Linux运维笔记https://www.diewufeiyang.com/书山有路勤为径,学海无涯苦作舟!- CentOS-Vault作为CentOS 5的yum源https://www.diewufeiyang.com/post/1264.html<p>1、修改yum源地址</p><p>将 /etc/yum.repos.d/CentOS-Base.repo 文件中所有的源主机地址修改为http://vault.centos.org</p><p>并且将$releasever替换为当前系统所使用的CentOS系统版本,可以使用5.x,具体根据你的系统版本选择,CentOS最后一个版本是5.11。</p><p>确认在 /etc/yum.repos.d/目录没有除了CentOS-Base.repo之外其他以repo结尾的文件,如果有的话需要删除,然后执行 yum clean all && yum makecache更新和启用新的yum源。</p><p>注意,需要将所有其他备用的源都删除,然后修改<span style="color: #333333; font-family: "Microsoft Yahei", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 15px; text-indent: 30px; background-color: #FFFFFF;">CentOS-Base.repo</span>内容如下:</p><pre class="prism-highlight prism-language-bash">[base]
name=CentOS-5.11 - Base
failovermethod=priority
baseurl=http://vault.centos.org/5.11/os/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-5.11 - Updates
failovermethod=priority
baseurl=http://vault.centos.org/5.11/updates/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-5.11 - Extras
failovermethod=priority
baseurl=http://vault.centos.org/5.11/extras/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5.11 - Plus
failovermethod=priority
baseurl=http://vault.centos.org/5.11/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#contrib - packages by Centos Users
[contrib]
name=CentOS-5.11 - Contrib
failovermethod=priority
baseurl=http://vault.centos.org/5.11/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5</pre><p>2.同步vault.centos.org源</p><p>因为http://vault.centos.org/的服务器在国外,在国内进行更新的时候速度比较慢,有可能经常会出现超时的错误,因此最好自己做个本地源,如何同步在http://vault.centos.org/readme.txt中有详细的说明,或者使用国内的源,目前腾讯,清华大学和阿里云都有CentOS的历史源</p><pre class="prism-highlight prism-language-bash">https://mirrors.cloud.tencent.com/centos-vault/
https://mirrors.tuna.tsinghua.edu.cn/centos-vault
https://mirrors.aliyun.com/centos-vault/</pre><p>创建本地源先创建一个需要同步的目录,然后执行下面的命令执行文件同步:</p><pre class="prism-highlight prism-language-bash">mkdir -p centos-vault/5.11
rsync -avz --exclude=debug --exclude=i386 rsync://archive.kernel.org/centos-vault/5.11/ ./centos-vault/5.11/</pre><p>去除了32位系统的文件,基本没有用过32位的操作系统,如果你需要32位的系统,把--exclude=i386去掉。</p>Tue, 01 Aug 2017 13:09:27 +0800
- CentOS6 libc.so.6 被误删、误改 急救https://www.diewufeiyang.com/post/1263.html<p>[root@mindoc lib64]# ldconfig</p><p>版本升级:</p><p>libc-2.12.so --->libc-2.14.so</p><p>首先下载 glibc-2.14.tar.gz</p><p>然后:</p><pre class="prism-highlight prism-language-bash">#tar -xzvf glibc-2.14.tar.gz
#cd glibc-2.14
#mkdir build // 在 glibc-2.14 目录下建立 build 文件夹
#cd build // 进入 build 目录
#../configure --prefix=/opt/glibc-2.14 // 配置 glibc 并设置当前 glibc-2.14 安装目录
#make && make install // 编译安装 glibc-2.14 库</pre><p>glibc 软链重新建立软连接:</p><pre class="prism-highlight prism-language-bash">#rm -rf /lib64/libc.so.6 // 先删除先前的 libc.so.6 软链
#ln -s /opt/glibc-2.14/lib/libc-2.14.so /lib64/libc.so.6</pre><p>注意!!!删除 libc.so.6 之后可能导致系统命令不可用的情况, 可使用如下方法解决:</p><pre class="prism-highlight prism-language-bash">#LD_PRELOAD=/opt/glibc-2.14/lib/libc-2.14.so ln -s /opt/glibc-2.14/lib/libc-2.14.so /lib64/libc.so.6</pre><p>如果上述更新失败可使用如下命令还原:</p><pre class="prism-highlight prism-language-bash">LD_PRELOAD=/lib64/libc-2.12.so ln -s /lib64/libc-2.12.so /lib64/libc.so.6</pre><p> libc-2.12.so 是系统升级前的</p><p>文章来源:https://ld246.com/article/1535349520368<br/></p>Sun, 30 Jul 2017 01:13:17 +0800
- linux编译安装时常见错误解决办法https://www.diewufeiyang.com/post/1262.html<p>原文链接:http://www.bkjia.com/PHPjc/1008013.html</p><p>configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libxslt-devel</pre><p>configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install net-snmp-devel</pre><p>configure: error: Please reinstall readline - I cannot find readline.h<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install readline-devel</pre><p>configure: error: Cannot find pspell<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install aspell-devel</pre><p>checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install unixODBC-devel</pre><p>configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libicu-devel</pre><p>configure: error: utf8mime2text() has new signature, but U8TCANONICAL is missing. This should not happen. Check config.log for additional information.<br/>复制代码 代码如下:</p><pre class="prism-highlight prism-language-bash">yum -y install libc-client-devel</pre><p>configure: error: freetype.h not found.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install freetype-devel</pre><p>configure: error: xpm.h not found.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libXpm-devel</pre><p>configure: error: png.h not found.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libpng-devel</pre><p>configure: error: vpx_codec.h not found.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libvpx-devel</pre><p>configure: error: Cannot find enchant<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install enchant-devel</pre><p>configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libcurl-devel</pre><p>LAOGAO added 20140907:<br/></p><p>configure: error: mcrypt.h not found. Please reinstall libmcrypt.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install</pre><p>added 20141003:<br/></p><p>Cannot find imap<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so</pre><p>configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing.<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libc-client-devel</pre><p>Cannot find ldap.h<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install openldap
yum -y install openldap-devel</pre><p>configure: error: Cannot find ldap libraries in /usr/lib<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">cp -frp /usr/lib64/libldap* /usr/lib/</pre><p>configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install postgresql-devel</pre><p>configure: error: Please reinstall the lib curl distribution<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install curl-devel</pre><p>configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.<br/>复制代码 代码如下:</p><pre class="prism-highlight prism-language-bash">yum -y install net-snmp-devel</pre><p>configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libxslt-devel</pre><p>checking for BZip2 support… yes checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution<br/></p><p>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install bzip2-devel</pre><p>checking for cURL support… yes checking if we should use cURL for url streams… no checking for cURL in default path… not found configure: error: Please reinstall the libcurl distribution – easy.h should be in/include/curl/<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install curl-devel</pre><p>checking for curl_multi_strerror in -lcurl… yes checking for QDBM support… no checking for GDBM support… no checking for NDBM support… no configure: error: DBA: Could not find necessary header file(s).<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install db4-devel</pre><p>checking for fabsf… yes checking for floorf… yes configure: error: jpeglib.h not found.<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libjpeg-devel</pre><p>checking for fabsf… yes checking for floorf… yes checking for jpeg_read_header in -ljpeg… yes configure: error: png.h not found.<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libpng-devel</pre><p>checking for png_write_image in -lpng… yes If configure fails try –with-xpm-dir=<br/></p><p>configure: error: freetype.h not found.<br/>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">Reconfigure your PHP with the following option. --with-xpm-dir=/usr</pre><p>checking for png_write_image in -lpng… yes configure: error: libXpm.(a|so) not found.<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libXpm-devel</pre><p>checking for bind_textdomain_codeset in -lc… yes checking for GNU MP support… yes configure: error: Unable to locate gmp.h<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install gmp-devel</pre><p>checking for utf8_mime2text signature… new checking for U8T_DECOMPOSE… configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libc-client-devel</pre><p>checking for LDAP support… yes, shared checking for LDAP Cyrus SASL support… yes configure: error: Cannot find ldap.h<br/></p><p>Fix:<br/>复制代码 代码如下:<br/>yum -y install openldap-devel<br/><br/>checking for mysql_set_character_set in -lmysqlclient… yes checking for mysql_stmt_next_result in -lmysqlclient… no checking for Oracle Database OCI8 support… no checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h' not found!</p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install unixODBC-devel</pre><p>checking for PostgreSQL support for PDO… yes, shared checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install postgresql-devel</pre><p>checking for sqlite 3 support for PDO… yes, shared checking for PDO includes… (cached) /usr/local/src/php-5.3.7/ext checking for sqlite3 files in default path… not found configure: error: Please reinstall the sqlite3 distribution<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install sqlite-devel</pre><p>checking for utsname.domainname… yes checking for PSPELL support… yes configure: error: Cannot find pspell<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install aspell-devel</pre><p>checking whether to enable UCD SNMP hack… yes checking for default_store.h… no<br/></p><p>checking for kstat_read in -lkstat… no checking for snmp_parse_oid in -lsnmp… no checking for init_snmp in -lsnmp… no configure: error: SNMP sanity check failed. Please check config.log for more information.</p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install net-snmp-devel</pre><p>checking whether to enable XMLWriter support… yes, shared checking for xml2-config path… (cached) /usr/bin/xml2-config checking whether libxml build works… (cached) yes checking for XSL support… yes, shared configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libxslt-devel</pre><p>configure: error: xml2-config not found. Please check your libxml2 installation.<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libxml2-devel</pre><p>checking for PCRE headers location… configure: error: Could not find pcre.h in /usr<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install pcre-devel</pre><p>configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install mysql-devel</pre><p>checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h' not found!<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install unixODBC-devel</pre><p>checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install postgresql-devel</pre><p>configure: error: Cannot find pspell<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install pspell-devel</pre><p>configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install net-snmp-devel</pre><p>configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution<br/></p><p>Fix:<br/>复制代码 代码如下:<br/></p><pre class="prism-highlight prism-language-bash">yum -y install libxslt-devel</pre>Thu, 27 Jul 2017 14:51:49 +0800
- aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversionhttps://www.diewufeiyang.com/post/1261.html<p class="subsection" style="font-family: "Microsoft YaHei"; font-size: medium; white-space: normal;">18.6.2 New Macros</p><p>While Autoconf was relatively dormant in the late 1990s, Automake provided Autoconf-like macros for a while. Starting with Autoconf 2.50 in 2001, Autoconf provided versions of these macros, integrated in the AC_ namespace, instead of AM_. But in order to ease the upgrading via autoupdate, bindings to such AM_ macros are provided.</p><p>Unfortunately older versions of Automake (e.g., Automake 1.4) did not quote the names of these macros. Therefore, when m4 finds something like ‘AC_DEFUN(AM_TYPE_PTRDIFF_T, ...)’ in aclocal.m4, AM_TYPE_PTRDIFF_T is expanded, replaced with its Autoconf definition.</p><p>Fortunately Autoconf catches pre-AC_INIT expansions, and complains, in its own words:</p><p> $cat configure.acAC_INIT([Example], [1.0], [bug-example@example.org])<br/> AM_TYPE_PTRDIFF_T<br/> $aclocal-1.4$autoconfaclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion<br/> aclocal.m4:17: the top level<br/> autom4te: m4 failed with exit status: 1<br/> $<br/></p><p>Modern versions of Automake no longer define most of these macros, and properly quote the names of the remaining macros. If you must use an old Automake, do not depend upon macros from Automake as it is simply not its job to provide macros (but the one it requires itself):</p><p> $cat configure.acAC_INIT([Example], [1.0], [bug-example@example.org])<br/> AM_TYPE_PTRDIFF_T<br/> $rm aclocal.m4$autoupdateautoupdate: `configure.ac' is updated<br/> $cat configure.acAC_INIT([Example], [1.0], [bug-example@example.org])<br/> AC_CHECK_TYPES([ptrdiff_t])<br/> $aclocal-1.4$autoconf$<br/></p><p>更新PHP版本之后,编译扩展,执行/usr/local/webserver/php/bin/phpize后报上述错误,更新autoconf和automake到最新版即可。</p><p>来源:https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/New-Macros.html</p>Mon, 24 Jul 2017 14:18:34 +0800
- 公共 NTP 服务器地址https://www.diewufeiyang.com/post/1260.html<p>
NTP 是 Network Time Protocol 的简称,也就是网络时间协议。而 NTP 服务器是可以通过网络来同步时间的服务器。
</p>
<p>
国内用阿里云、国外用谷歌或者苹果。也有朋友经过测试苹果在国内也是可以使用的,大家可以试试看。
</p>
<p>
国内知名公共 NTP 服务器地址:
</p>
<p>
国家授时中心 NTP 服务器(NTSC NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">ntp.ntsc.ac.cn</pre>
<p>
中国 NTP 快速授时服务(NTP ORG CN)
</p>
<pre class="prism-highlight prism-language-bash">cn.ntp.org.cn</pre>
<p>
教育网
</p>
<pre class="prism-highlight prism-language-bash">edu.ntp.org.cn</pre>
<p>
阿里云公共 NTP 服务器(Aliyun NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">time.pool.aliyun.com
time1.aliyun.com
time2.aliyun.com
time3.aliyun.com
time4.aliyun.com
time5.aliyun.com
time6.aliyun.com
time7.aliyun.com</pre>
<p>
腾讯云公共 NTP 服务器(Tencent Cloud NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">time1.cloud.tencent.com
time2.cloud.tencent.com
time3.cloud.tencent.com
time4.cloud.tencent.com
time5.cloud.tencent.com</pre>
<p>
教育网(高校自建)(EDU NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">ntp.sjtu.edu.cn
ntp.neu.edu.cn
ntp.bupt.edu.cn
ntp.shu.edu.cn</pre>
<p>
国际 NTP 服务器(Global Public NTP Server)
</p>
<p>
国际 NTP 快速授时服务(Pool NTP ORG)
</p>
<pre class="prism-highlight prism-language-bash">cn.pool.ntp.org
pool.ntp.org
0.pool.ntp.org
1.pool.ntp.org
2.pool.ntp.org
3.pool.ntp.org
asia.pool.ntp.org</pre>
<p>
谷歌公共 NTP 服务器(Google NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">time1.google.com
time2.google.com
time3.google.com
time4.google.com</pre>
<p>
苹果公司公共 NTP 服务器(Apple NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">time.apple.com
time1.apple.com
time2.apple.com
time3.apple.com
time4.apple.com
time5.apple.com
time6.apple.com
time7.apple.com</pre>
<p>
微软 Windows NTP 服务器(Microsoft Windows NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">time.windows.com</pre>
<p>
美国标准技术研究院 NTP 服务器(NIST NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">time.nist.gov
time-nw.nist.gov
time-a.nist.gov
time-b.nist.gov</pre>
<p>
香港天文台公共 NTP 服务器(Hong Kong Observator NTP Server)
</p>
<pre class="prism-highlight prism-language-bash">stdtime.gov.hk</pre>Thu, 20 Jul 2017 11:10:35 +0800
- telnet命令使用示例https://www.diewufeiyang.com/post/1259.html<p>telnet命令通常用来远程登录。telnet程序是基于TELNET协议的远程登录客户端程序。Telnet协议是TCP/IP协议族中的一员,是Internet远程登录服务的标准协议和主要方式。它为用户提供了在本地计算机上完成远程主机工作的能力。</p><p><strong>语法</strong></p><pre class="prism-highlight prism-language-bash">telnet [-8acdEfFKLrx][-b<主机别名>][-e<脱离字符>][-k<域名>][-l<用户名称>][-n<记录文件>][-S<服务类型>][-X<认证形态>][主机名称或IP地址<通信端口>]</pre><p><strong>参数</strong></p><pre class="prism-highlight prism-language-bash">-8 允许使用8位字符资料,包括输入与输出
-a 尝试自动登入远端系统
-b<主机别名> 使用别名指定远端主机名称
-c 不读取用户专属目录里的.telnetrc文件
-d 启动排错模式
-e<脱离字符> 设置脱离字符
-E 滤除脱离字符
-F 使用Kerberos V5认证时,加上此参数可把本地主机的认证数据上传到远端主机
-f 此参数的效果和”-F”参数相同
-k<域名> 使用Kerberos认证时,加上此参数让远端主机采用指定的领域名,而非该主机的域名
-K 不自动登入远端主机
-l<用户名称> 指定要登入远端主机的用户名称
-L 允许输出8位字符资料
-n<记录文件> 指定文件记录相关信息
-r 使用类似rlogin指令的用户界面
-S<服务类型> 设置telnet连线所需IP TOS信息
-x 假设主机有支持数据加密的功能,就使用它
-X<认证形态> 关闭指定的认证形态</pre><p><strong>使用示例</strong></p><p>示例1:远程服务器无法访问</p><pre class="prism-highlight prism-language-bash">[root@linuxprobe ~]# telnet 192.168.120.209
Trying 192.168.120.209...
telnet: connect to address 192.168.120.209: No route to host
telnet: Unable to connect to remote host: No route to host</pre><p>处理这种情况方法:</p><p>(1)确认IP地址是否正确</p><p>(2)确认IP地址对应的装机是否已经开机</p><p>(3)如果主机已经启动,确认路由设置是否设置正确(使用route命令查看)</p><p>(4)如果主机已经启动,确认主机上是否开启了telnet服务(使用netstat命令查看,TCP的23端口是否有LISTEN状态行)</p><p>(5)如果主机已经启动telnet服务,确认防火墙是否开放了23端口的访问(使用iptables-save查看)</p><p>示例2:域名无法解析</p><pre class="prism-highlight prism-language-bash">[root@linuxprobe ~]# telnet www.baidu.com
www.baidu.com/telnet: Temporary failure in name resolution</pre><p>处理这种情况方法:</p><p>(1)确认域名是否正确</p><p>(2)确认本机的域名解析有关的设置是否正确(/etc/resolv.conf中nameserver的配置是否正确,如果没有,可以使用nameserver 8.8.8.8)</p><p>(3)确认防火墙是否放开了UDP53端口的访问(DNS使用UDP协议,端口53,使用iptables-save查看)</p><p>示例3:拒绝访问</p><pre class="prism-highlight prism-language-bash">[root@linuxprobe ~]# telnet 192.168.120.206
Trying 192.168.120.206...
telnet: connect to address 192.168.120.206: Connection refused
telnet: Unable to connect to remote host: Connection refused</pre><p>处理这种情况方法:</p><p>(1)确认IP地址或者主机名是否正确</p><p>(2)确认端口是否正确,是否默认23端口</p><p>若要检查192.168.120.206的某端口是否能否能访问,如443端口,可使用如下命令</p><pre class="prism-highlight prism-language-bash">[root@linuxprobe ~]# telnet 192.168.120.206 443
Trying 192.168.120.206...
telnet: connect to address 192.168.120.206: Connection refused</pre><p>说明:这表示192.168.120.206的443端口不能访问</p><p>示例4:telnet root用户的登入</p><pre class="prism-highlight prism-language-bash">[root@linuxprobe ~]# telnet 192.168.120.204
Trying 192.168.120.204...
Connected to 192.168.120.204 (192.168.120.204).
Escape character is '^]'.
localhost (Linux release 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012) (1)
login: root
Password:
Login incorrect</pre><p>说明:一般情况下不允许root从远程登录,可以先用普通账号登录,然后再su -切到root用户。若要允许root用户登入,可用下列方法:</p><pre class="prism-highlight prism-language-bash">[root@linuxprobe ~]# vi /etc/pam.d/login
#auth required pam_securetty.so #将这一行加上注释!
或
[root@linuxprobe ~]# mv /etc/securetty /etc/securetty.bak</pre><p>示例5:启用telnet服务</p><pre class="prism-highlight prism-language-bash">[root@linuxprobe ~]# cd /etc/xinetd.d/
[root@linuxprobe xinetd.d]# ll
总计 124
-rw-r--r-- 1 root root 1157 2011-05-31 chargen-dgram
-rw-r--r-- 1 root root 1159 2011-05-31 chargen-stream
-rw-r--r-- 1 root root 523 2009-09-04 cvs
-rw-r--r-- 1 root root 1157 2011-05-31 daytime-dgram
-rw-r--r-- 1 root root 1159 2011-05-31 daytime-stream
-rw-r--r-- 1 root root 1157 2011-05-31 discard-dgram
-rw-r--r-- 1 root root 1159 2011-05-31 discard-stream
-rw-r--r-- 1 root root 1148 2011-05-31 echo-dgram
-rw-r--r-- 1 root root 1150 2011-05-31 echo-stream
-rw-r--r-- 1 root root 323 2004-09-09 eklogin
-rw-r--r-- 1 root root 347 2005-09-06 ekrb5-telnet
-rw-r--r-- 1 root root 326 2004-09-09 gssftp
-rw-r--r-- 1 root root 310 2004-09-09 klogin
-rw-r--r-- 1 root root 323 2004-09-09 krb5-telnet
-rw-r--r-- 1 root root 308 2004-09-09 kshell-rw-r--r-- 1 root root 317 2004-09-09 rsync
-rw-r--r-- 1 root root 1212 2011-05-31 tcpmux-server
-rw-r--r-- 1 root root 1149 2011-05-31 time-dgram
-rw-r--r-- 1 root root 1150 2011-05-31 time-stream
[root@linuxprobe xinetd.d]# cat krb5-telnet
# default: off
# description: The kerberized telnet server accepts normal telnet sessions, \
# but can also use Kerberos 5 authentication.
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/kerberos/sbin/telnetd
log_on_failure += USERID
disable = yes
}</pre><p>配置参数通常如下:</p><pre class="prism-highlight prism-language-bash">service telnet
{
disable = no #启用
flags = REUSE #socket可重用
socket_type = stream #连接方式为TCP
wait = no #为每个请求启动一个进程
user = root #启动服务的用户为root
server = /usr/sbin/in.telnetd #要激活的进程
log_on_failure += USERID #登录失败时记录登录用户名
}
如果要配置允许登录的客户端列表,加入
only_from = 192.168.0.2 #只允许192.168.0.2登录
如果要配置禁止登录的客户端列表,加入
no_access = 192.168.0.{2,3,4} #禁止192.168.0.2、192.168.0.3、192.168.0.4登录
如果要设置开放时段,加入
access_times = 9:00-12:00 13:00-17:00 # 每天只有这两个时段开放服务(我们的上班时间:P)
如果你有两个IP地址,一个是私网的IP地址如192.168.0.2,一个是公网的IP地址如218.75.74.83,如果你希望用户只能从私网来登录telnet服务,那么加入
bind = 192.168.0.2
各配置项具体的含义和语法可参考xined配置文件属性说明(man xinetd.conf)
配置端口,修改services文件:
# vi /etc/services
找到以下两句
telnet 23/tcp
telnet 23/udp
如 果前面有#字符,就去掉它。telnet的默认端口是23,这个端口也是黑客端口扫描的主要对象,因此最好将这个端口修改掉,修改的方法很简单,就是将 23这个数字修改掉,改成大一点的数字,比如61123。注意,1024以下的端口号是internet保留的端口号,因此最好不要用,还应该注意不要与 其它服务的端口冲突。
启动服务:service xinetd restart</pre><p>文章来源:<a href="https://www.linuxprobe.com/telnet-command-examples.html">https://www.linuxprobe.com/telnet-command-examples.html</a></p>Sun, 16 Jul 2017 17:05:06 +0800
- 解读vmstat中的ACTIVE/INACTIVE MEMORYhttps://www.diewufeiyang.com/post/1258.html<p>vmstat 命令能够报告关于内核线程、虚拟内存、磁盘、陷阱和 CPU 活动的统计信息,那么我们又该如何理解其工作原理呢?</p><p>vmstat -a 命令能看到active memory 和 inactive memory:</p><pre class="prism-highlight prism-language-bash">$ vmstat -a
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free inact active si so bi bo in cs us sy id wa st
1 0 138096 319560 1372408 1757848 0 0 2 3 2 3 1 0 99 0 0</pre><p>但它们的含义在manpage中只给了简单的说明,并未详细解释:</p><pre class="prism-highlight prism-language-bash">inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)</pre><p>在此我们试图准确理解它的含义。通过阅读vmstat的源代码(vmstat.c和proc/sysinfo.c)得知,vmstat命令是直接从/proc/meminfo中获取的数据:</p><pre class="prism-highlight prism-language-bash">$ grep -i act /proc/meminfo
Active: 1767928 kB
Inactive: 1373760 kB</pre><p>而/proc/meminfo的数据是在以下内核函数中生成的:</p><pre class="prism-highlight prism-language-bash">fs/proc/meminfo.c:
==================
0023 static int meminfo_proc_show(struct seq_file *m, void *v)
0024 {
...
0032 unsigned long pages[NR_LRU_LISTS];
...
0051 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
0052 pages[lru] = global_page_state(NR_LRU_BASE + lru);
...
0095 "Active: %8lu kB\n"
0096 "Inactive: %8lu kB\n"
0097 "Active(anon): %8lu kB\n"
0098 "Inactive(anon): %8lu kB\n"
0099 "Active(file): %8lu kB\n"
0100 "Inactive(file): %8lu kB\n"
...
0148 K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]),
0149 K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
0150 K(pages[LRU_ACTIVE_ANON]),
0151 K(pages[LRU_INACTIVE_ANON]),
0152 K(pages[LRU_ACTIVE_FILE]),
0153 K(pages[LRU_INACTIVE_FILE]),
...</pre><p>这段代码的意思是统计所有的LRU list,其中Active Memory等于ACTIVE_ANON与ACTIVE_FILE之和,Inactive Memory等于INACTIVE_ANON与INACTIVE_FILE之和。</p><p>LRU list是Linux kernel的内存页面回收算法(Page Frame Reclaiming Algorithm)所使用的数据结构,LRU是Least Recently Used的缩写词,这个算法的核心思想是:回收的页面应该是最近使用得最少的,为了实现这个目标,最理想的情况是每个页面都有一个年龄项,用于记录最近一次访问页面的时间,可惜x86 CPU硬件并不支持这个特性,x86 CPU只能做到在访问页面时设置一个标志位Access Bit,无法记录时间,所以Linux Kernel使用了一个折衷的方法——它采用了LRU list列表,把刚访问过的页面放在列首,越接近列尾的就是越长时间未访问过的页面,这样,虽然不能记录访问时间,但利用页面在LRU list中的相对位置也可以轻松找到年龄最长的页面。Linux kernel设计了两种LRU list: active list 和 inactive list, 刚访问过的页面放进active list,长时间未访问过的页面放进inactive list,这样从inactive list回收页面就变得简单了。内核线程kswapd会周期性地把active list中符合条件的页面移到inactive list中,这项转移工作是由refill_inactive_zone()完成的。</p><p><img src="/zb_users/upload/2017/07/LURlist.png"/></p><p>vmstat看到的active/inactive memory就分别是active list和inactive list中的内存大小,如果inactive list很大,表明在必要时可以回收的页面很多;而如果inactive list很小,说明可以回收的页面不多,Active/inactive memory是针对用户进程所占用的内存而言的,内核占用的内存(包括slab)不在其中。</p><p>至于在源代码中看到的ACTIVE_ANON和ACTIVE_FILE,分别表示anonymous pages和mapped pages。用户进程的内存页分为两种:与文件关联的内存(比如程序文件、数据文件所对应的内存页)和与文件无关的内存(比如进程的堆栈,用malloc申请的内存),前者称为file pages或mapped pages,后者称为anonymous pages,File pages在发生换页(page-in或page-out)时,是从它对应的文件读入或写出;anonymous pages在发生换页时,是对交换区进行读/写操作。</p><p>文章来源:<a href="https://www.linuxprobe.com/vmstat-active-inactive-memory.html" _src="https://www.linuxprobe.com/vmstat-active-inactive-memory.html">https://www.linuxprobe.com/vmstat-active-inactive-memory.html</a></p>Wed, 12 Jul 2017 16:56:17 +0800
- Linux系统下查看硬件信息命令大全https://www.diewufeiyang.com/post/1257.html<p>
有许多命令可以用来查看 Linux 系统上的硬件信息。有些命令只能够打印出像 CPU 和内存这一特定的硬件组件信息,另外一些命令可以查看多种硬件组件的信息。
</p>
<p>
这个教程可以带大家快速了解一下查看各种硬件设备的信息和配置详情的最常用的命令。
</p>
<p>
<strong>lscpu</strong>
</p>
<p>
lscpu命令能够查看 CPU 和处理单元的信息。该命令没有任何其他选项或者别的功能。
</p>
<pre class="prism-highlight prism-language-bash">lscpu</pre>
<p>
运行该命令会看到下面输出:
</p>
<p>
<img src="/zb_users/upload/2017/07/lscpu.png" />
</p>
<p>
<strong>lspci</strong>
</p>
<p>
lspci是另一个命令行工具,可以用来列出所有的 PCI 总线,还有与 PCI 总线相连的设备的详细信息,比如 VGA 适配器、显卡、网络适配器、usb 端口、SATA 控制器等。
</p>
<pre class="prism-highlight prism-language-bash">lspci</pre>
<p>
你可以看到类似下图的输出信息:
</p>
<p>
<img src="/zb_users/upload/2017/07/lspci.png" />
</p>
<p>
可以通过运行下面的命令来过滤出特定设备的信息:
</p>
<pre class="prism-highlight prism-language-bash">lspci -v | grep "VGA" -A 12</pre>
<p>
运行上面的命令可以看到类似下图的关于显卡的信息:
</p>
<p>
<img src="/zb_users/upload/2017/07/lspcivga.png" />
</p>
<p>
<strong>lshw</strong>
</p>
<p>
lshw是一个通用的工具,可以列出多种硬件单元的详细或者概要的信息,比如 CPU、内存、usb 控制器、硬盘等。lshw能够从各个“/proc”文件中提取出相关的信息。
</p>
<pre class="prism-highlight prism-language-bash">lshw -short</pre>
<p>
通过运行上面的命令可以看到下面的信息:
</p>
<p>
<img src="/zb_users/upload/2017/07/lshw.png" />
</p>
<p>
<strong>lsscsi</strong>
</p>
<p>
通过运行下面的命令可以列出像硬盘和光驱等 scsi/sata 设备的信息:
</p>
<pre class="prism-highlight prism-language-bash">lsscsi</pre>
<p>
会得到类似下面的输出:
</p>
<p>
<img src="/zb_users/upload/2017/07/lsscsi.png" />
</p>
<p>
<strong>lsusb</strong>
</p>
<p>
lsusb命令能够列出 USB 控制器和与 USB 控制器相连的设备的详细信息。默认情况下,lsusb命令只打印出概要信息。可以通过使用-v参数打印每一个usb端口的详细信息。
</p>
<pre class="prism-highlight prism-language-bash">lsusb</pre>
<p>
可以看到下面输出
</p>
<p>
<img src="/zb_users/upload/2017/07/lsusb.png" />
</p>
<p>
<strong>df</strong>
</p>
<p>
df命令能够列出不同分区的概要信息、挂载点、已用的和可用的空间。
</p>
<p>
可以在使用df命令的时候加上-H参数。
</p>
<pre class="prism-highlight prism-language-bash">df -H</pre>
<p>
<img src="/zb_users/upload/2017/07/df.png" />
</p>
<p>
<strong>Free</strong>
</p>
<p>
通过使用free命令可以查看系统中使用的、闲置的和 RAM 的总体数量。
</p>
<pre class="prism-highlight prism-language-bash">free -m</pre>
<p>
会看到下面输出。
</p>
<p>
<img src="/zb_users/upload/2017/07/free.png" />
</p>
<p>
<strong>Hdparm</strong>
</p>
<p>
hdparm命令可以用来显示像硬盘这样的 sata 设备的信息。
</p>
<pre class="prism-highlight prism-language-bash">sudo hdparm</pre>
<p>
可以看到下面的输出:
</p>
<p>
<img src="/zb_users/upload/2017/07/hdparm.png" />
</p>
<p>
<strong>总结</strong>
</p>
<p>
每个命令都有不同的方式来获取硬件的信息。在查看特定的硬件信息的时候,可以尝试使用不同的方式。上面所有的命令行工具在大部分的 Linux 发行版本中都是可以使用的,可以很容易的从仓库中获取安装。
</p>
<p>
文章来源:<a href="https://www.linuxprobe.com/linux-list-hardware-information-command.html" _src="https://www.linuxprobe.com/linux-list-hardware-information-command.html">https://www.linuxprobe.com/linux-list-hardware-information-command.html</a>
</p>Sat, 08 Jul 2017 16:44:08 +0800
- 程序员必读:Linux内存管理剖析https://www.diewufeiyang.com/post/1256.html<p>
现在的服务器大部分都是运行在Linux上面的,所以作为一个程序员有必要简单地了解一下系统是如何运行的。
</p>
<p>
对于内存部分需要知道:
</p>
<p>
1.地址映射
</p>
<p>
2.内存管理的方式
</p>
<p>
3.缺页异常
</p>
<p>
先来看一些基本的知识,在进程看来,内存分为内核态和用户态两部分,经典比例如下:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_1.jpg" />
</p>
<p>
从用户态到内核态一般通过系统调用、中断来实现。用户态的内存被划分为不同的区域用于不同的目的:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_2.jpg" />
</p>
<p>
当然内核态也不会无差别地使用,所以,其划分如下:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_3.jpg" />
</p>
<p>
下面来仔细看这些内存是如何管理的。
</p>
<p>
<strong>地址</strong>
</p>
<p>
在Linux内部的地址的映射过程为逻辑地址–>线性地址–>物理地址,物理地址最简单:地址总线中传输的数字信号,而线性地址和逻辑地址所表示的则是一种转换规则,线性地址规则如下:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_4.jpg" />
</p>
<p>
这部分由MMU完成,其中涉及到主要的寄存器有CR0、CR3。机器指令中出现的是逻辑地址,逻辑地址规则如下:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_5.jpg" />
</p>
<p>
在Linux中的逻辑地址等于线性地址,也就是说Inter为了兼容把事情搞得很复杂,Linux简化顺便偷个懒。
</p>
<p>
<strong>内存管理的方式</strong>
</p>
<p>
在系统boot的时候会去探测内存的大小和情况,在建立复杂的结构之前,需要用一个简单的方式来管理这些内存,这就是bootmem,简单来说就是位图,不过其中也有一些优化的思路。
</p>
<p>
bootmem再怎么优化,效率都不高,在要分配内存的时候毕竟是要去遍历,buddy系统刚好能解决这个问题:在内部保存一些2的幂次大小的空闲内存片段,如果要分配3page,去4page的列表里面取一个,分配3个之后将剩下的1个放回去,内存释放的过程刚好是一个逆过程。用一个图来表示:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_6.jpg" />
</p>
<p>
可以看到0、4、5、6、7都是正在使用的,那么,1、2被释放的时候,他们会合并吗?
</p>
<pre class="prism-highlight prism-language-bash">static inline unsigned long
__find_buddy_index(unsigned long page_idx, unsigned int order)
{
return page_idx ^ (1 << order);// 更新最高位,0~1互换
}</pre>
<p>
从上面这段代码中可以看到,0、1是buddy,2、3是buddy,虽然1、2相邻,但他们不是。内存碎片是系统运行的大敌,伙伴系统机制可以在一定程度上防止碎片~~另外,我们可以通过cat /proc/buddyinfo获取到各order中的空闲的页面数。
</p>
<p>
伙伴系统每次分配内存都是以页(4KB)为单位的,但系统运行的时候使用的绝大部分的数据结构都是很小的,为一个小对象分配4KB显然是不划算了。Linux中使用slab来解决小对象的分配:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_7.jpg" />
</p>
<p>
在运行时,slab向buddy“批发”一些内存,加工切块以后“散卖”出去。随着大规模多处理器系统和NUMA系统的广泛应用,slab终于暴露出不足:
</p>
<p>
1.复杂的队列管理
</p>
<p>
2.管理数据和队列存储开销较大
</p>
<p>
3.长时间运行partial队列可能会非常长
</p>
<p>
4.对NUMA支持非常复杂
</p>
<p>
为了解决这些高手们开发了slub:改造page结构来削减slab管理结构的开销、每个CPU都有一个本地活动的slab(kmem_cache_cpu)等。对于小型的嵌入式系统存在一个slab模拟层slob,在这种系统中它更有优势。
</p>
<p>
小内存的问题算是解决了,但还有一个大内存的问题:用伙伴系统分配10 x 4KB的数据时,会去16 x 4KB的空闲列表里面去找(这样得到的物理内存是连续的),但很有可能系统里面有内存,但是伙伴系统分配不出来,因为他们被分割成小的片段。那么,vmalloc就是要用这些碎片来拼凑出一个大内存,相当于收集一些“边角料”,组装成一个成品后“出售”:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_8.jpg" />
</p>
<p>
之前的内存都是直接映射的,第一次感觉到页式管理的存在:D 另外对于高端内存,提供了kmap方法为page分配一个线性地址。
</p>
<p>
进程由不同长度的段组成:代码段、动态库的代码、全局变量和动态产生数据的堆、栈等,在Linux中为每个进程管理了一套虚拟地址空间:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_9.jpg" />
</p>
<p>
在我们写代码malloc完以后,并没有马上占用那么大的物理内存,而仅仅是维护上面的虚拟地址空间而已,只有在真正需要的时候才分配物理内存,这就是COW(COPY-ON-WRITE:写时复制)技术,而物理分配的过程就是最复杂的缺页异常处理环节了,下面来看!
</p>
<p>
<strong>缺页异常</strong>
</p>
<p>
在实际需要某个虚拟内存区域的数据之前,和物理内存之间的映射关系不会建立。如果进程访问的虚拟地址空间部分尚未与页帧关联,处理器自动引发一个缺页异常。在内核处理缺页异常时可以拿到的信息如下:
</p>
<p>
1.cr2:访问到线性地址
</p>
<p>
2.err_code:异常发生时由控制单元压入栈中,表示发生异常的原因
</p>
<p>
3.regs:发生异常时寄存器的值
</p>
<p>
处理的流程如下:
</p>
<p>
<img src="/zb_users/upload/2017/07/Linux_Memory_10.jpg" />
</p>
<p>
发生缺页异常的时候,可能因为不常使用而被swap到磁盘上了,swap相关的命令如下:
</p>
<pre class="prism-highlight prism-language-bash">swapon 开启swap
swapoff 关闭swap
/proc/sys/vm/swapiness 分值越大越积极使用swap,可以修改/etc/sysctl.conf中添加vm.swappiness=xx[1-100]来修改</pre>
<p>
如果内存是mmap映射到内存中的,那么在读、写对应内存的时候也会产生缺页异常。
</p>
<p>
文章来源:<a href="https://www.linuxprobe.com/programmer-must-read%ef%bc%9a-linux-memory-management.html" _src="https://www.linuxprobe.com/programmer-must-read%ef%bc%9a-linux-memory-management.html">https://www.linuxprobe.com/programmer-must-read%ef%bc%9a-linux-memory-management.html</a>
</p>Tue, 04 Jul 2017 16:25:16 +0800
- Munin监控的安装与配置https://www.diewufeiyang.com/post/1255.html<p>Munin 是一款类似 RRD tool 的优秀系统监控工具,它能提供给你多方面的系统性能信息,例如 磁盘、网络、进程、系统和用户。</p><p><img src="/zb_users/upload/2017/07/Munin.gif"/></p><p><strong>Munin 的工作原理</strong></p><p>Munin 以客户端-服务器模式运行,主服务器上运行的 Munin 服务器进程会从本地运行的客户端守护进程(Munin 可以监控它自己的资源)或者远程客户端(Munin 可以监控上百台机器)收集数据,然后在它的 web 界面上以图形的方式显示出来。</p><p>在服务器中配置 Munin</p><p><strong>安装</strong></p><p>要配置服务器端和客户端,我们需要完成以下两步。</p><p>安装 Munin 服务器软件包并配置,使得它能从客户端收集数据。</p><p>安装 Munin 客户端,使得服务器能连接到客户端守护进程进行数据收集。</p><p>1、在 Linux 上安装 munin 服务器端</p><p>在基于Ubuntu/Debian的机器上安装 Munin 服务器:</p><pre class="prism-highlight prism-language-bash">apt-get install munin apache2</pre><p>在基于 Redhat/CentOS 的机器上安装 Munin 服务器:</p><p>在基于 Redhat 的机器上安装 Munin 之前,你需要确保 启用 EPEL 软件仓库,因为基于 Redhat 的机器的软件仓库默认没有 Munin,下载EPEL 的rpm 安装包(下载对应版本):</p><pre class="prism-highlight prism-language-bash">wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm</pre><p>下载完成后,通过以下命令安装EPEL 软件包</p><pre class="prism-highlight prism-language-bash">rpm -ivh epel-release-6-8.noarch.rpm或rpm -ivh epel-release*</pre><p>安装好EPEL 源后,用yum 命令来检查是否添加到源列表:</p><pre class="prism-highlight prism-language-bash"># yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.vonline.vn
* epel: buaya.klas.or.id
* extras: centos-hn.viettelidc.com.vn
* updates: mirrors.fibo.vn
repo id repo name status
base CentOS-6 - Base 6,381
epel Extra Packages for Enterprise Linux 6 - x86_64 10,023
extras CentOS-6 - Extras 13
nginx nginx repo 47
updates CentOS-6 - Updates 1,555
repolist: 18,019</pre><p>EPEL已经在repo 后列出,并且显示提供了上万个软件包,所以EPEL 已经安装到你的CentOS了,EPEL源的配置安装到了/etc/yum.repos.d/epel.repo 文件。</p><p>然后就可以直接安装munin了,执行命令:</p><pre class="prism-highlight prism-language-bash">yum install munin httpd</pre><p>2、在 Linux 上配置 Munin 服务器端:</p><p>下面是我们要在服务器上启动 Munini 所进行的步骤:</p><p>步骤 1:在 /etc/munin/munin.conf 中添加需要监控的主机详情。</p><p>在 /etc/munin/munin.conf 文件中添加主机条目,调到文件末尾添加要监控的客户端。在这个例子中,我添加了要监控的数据库服务器和它的 IP 地址。</p><pre class="prism-highlight prism-language-bash">[db.linuxprobe.com]
address 192.168.1.25
use_node_name yes</pre><p>保存文件并退出。</p><p>步骤 2:配置 apache web 服务器使其包括 munin 配置。</p><p>在 /etc/apache2/conf.d 目录中编辑或创建文件 munin.conf 用于包括 Munin 和 Apache 相关的配置,另外注意一点,默认其它和 web 相关的 Munin 配置保存在 /var/www/munin 目录。</p><pre class="prism-highlight prism-language-bash">vi /etc/apache2/conf.d/munin.conf
内容:
Alias /munin /var/www/munin
<Directory /var/www/munin>
Order allow,deny
Allow from localhost 127.0.0.0/8 ::1
AllowOverride None
Options ExecCGI FollowSymlinks
AddHandler cgi-script .cgi
DirectoryIndex index.cgi
AuthUserFile /etc/munin/munin.passwd
AuthType basic
AuthName "Munin stats"
require valid-user
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault M310
</IfModule>
</Directory></pre><p>保存文件并退出。</p><p>步骤 3:为 web 界面创建用户名和密码。</p><p>现在为查看 munin 的图示而创建用户名和密码:</p><pre class="prism-highlight prism-language-bash">htpasswd -c /etc/munin/munin-htpasswd munin</pre><p>注意:对于 Redhat/Centos 机器,要访问你的配置文件,需要在每个路径中用 “httpd” 替换 “apache2”。</p><p>步骤 4:重启 apache 服务器。</p><p>重启 Apache 服务器,使得 Munin 配置生效。</p><p>基于 Ubuntu/Debian :</p><pre class="prism-highlight prism-language-bash">service apache2 restart</pre><p>基于 Centos/Redhat :</p><pre class="prism-highlight prism-language-bash">service httpd restart</pre><p>3、在 Linux 上安装和配置 Munin 客户端:</p><p>步骤 1:在 Linux 上安装 Munin 客户端。</p><pre class="prism-highlight prism-language-bash">apt-get install munin-node</pre><p>注意:如果你想监控你的 Munin 服务器端,你也需要在服务器端安装 munin-node。</p><p>步骤 2:编辑 munin-node.conf 文件配置客户端。</p><pre class="prism-highlight prism-language-bash">vi /etc/munin/munin-node.conf
示例:
allow ^127\.0\.0\.1$
allow ^10\.10\.20\.20$
# 监听到哪个地址上
host *
# 以及哪个端口
port 4949</pre><p>注意: 10.10.20.20 是我的 Munin 服务器,它连接到客户端的 4949 端口获取数据。</p><p>步骤 3:在客户端机器中重启 munin-node:</p><pre class="prism-highlight prism-language-bash">service munin-node restart</pre><p><strong>测试连接</strong></p><p>检查你是否能从服务器的连接到客户端的 4949 端口,如果不行,你需要在客户端机器中的防火墙打开该端口。</p><p>访问 Munin web 页面http://munin.linuxprobe.com/munin/index.html即可。</p><p>注意,测试之前已经将域名定义到了指定的服务端的80端口。</p><p>文章来源:<a href="https://www.linuxprobe.com/munin-monitor-installation-and-configuration.html" _src="https://www.linuxprobe.com/munin-monitor-installation-and-configuration.html">https://www.linuxprobe.com/munin-monitor-installation-and-configuration.html</a></p>Sat, 01 Jul 2017 17:27:45 +0800