<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>linux &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 29 Oct 2018 03:08:01 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>
	<item>
		<title>Centos升级gcc4.4.7升级gcc4.8手记</title>
		<link>https://www.mudbest.com/centos%e5%8d%87%e7%ba%a7gcc4-4-7%e5%8d%87%e7%ba%a7gcc4-8%e6%89%8b%e8%ae%b0/</link>
					<comments>https://www.mudbest.com/centos%e5%8d%87%e7%ba%a7gcc4-4-7%e5%8d%87%e7%ba%a7gcc4-8%e6%89%8b%e8%ae%b0/#comments</comments>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Sat, 23 Aug 2014 17:25:20 +0000</pubDate>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[gcc]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=2100</guid>

					<description><![CDATA[出于需求系统自带的是gcc4.4.7，版本太低无法编译，被逼无奈只能升级gcc了，碰到很多坑，下载这个玩意就用 ... <a title="Centos升级gcc4.4.7升级gcc4.8手记" class="read-more" href="https://www.mudbest.com/centos%e5%8d%87%e7%ba%a7gcc4-4-7%e5%8d%87%e7%ba%a7gcc4-8%e6%89%8b%e8%ae%b0/" aria-label="阅读 Centos升级gcc4.4.7升级gcc4.8手记">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>出于需求系统自带的是gcc4.4.7，版本太低无法编译，被逼无奈只能升级gcc了，碰到很多坑，下载这个玩意就用了不少时间。<span id="more-2100"></span></p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@VM_222_92_centos ~]# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) 
</pre>
<p>1.下载源码包</p>
<pre class="brush: bash; title: ; notranslate">
wget http: //ftp.gnu.org/gnu/gcc/gcc-4.8.0/gcc-4.8.0.tar.bz2
tar -jxvf  gcc-4.8.0.tar.bz2
</pre>
<p>2.下载编译所需依赖库</p>
<pre class="brush: bash; title: ; notranslate">
cd gcc-4.8.0
./contrib/download_prerequisites
cd ..
</pre>
<p>3.建立编译输出目录</p>
<pre class="brush: bash; title: ; notranslate">
mkdir gcc-build-4.8.0
</pre>
<p>4.进入此目录，执行以下命令，生成makefile文件</p>
<pre class="brush: bash; title: ; notranslate">
cd  gcc-build-4.8.0
../gcc-4.8.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
</pre>
<p>5.编译</p>
<pre class="brush: bash; title: ; notranslate">
# j 后面的是核心数，编译速度会比较快
make -j4
</pre>
<p>6.安装</p>
<pre class="brush: bash; title: ; notranslate">
sudo make install
</pre>
<p>7.切换GCC到新版<br />
确定新安装的GCC的路径,一般默认在/usr/local/bin下。可以先updatedb,然后locate gcc-4.8|tail找一下</p>
<pre class="brush: bash; title: ; notranslate">
ls /usr/local/bin | grep gcc
</pre>
<p>添加新GCC到可选项，倒数第三个是名字，倒数第二个参数为新GCC路径，最后一个参数40为优先级，设大一些之后就自动使用新版了 </p>
<pre class="brush: bash; title: ; notranslate">
update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/i686-pc-linux-gnu-gcc 40 
</pre>
<p>8.确认当前版本已经切换为新版(重新连接shell生效).</p>
<pre class="brush: bash; title: ; notranslate">
gcc -v
</pre>
<p><img fetchpriority="high" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/08/71-610x83.jpg" alt="7" width="610" height="83" class="alignnone size-medium wp-image-2107" srcset="https://www.mudbest.com/wp-content/uploads/2014/08/71-610x83.jpg 610w, https://www.mudbest.com/wp-content/uploads/2014/08/71.jpg 906w" sizes="(max-width: 610px) 100vw, 610px" /></p>
<p>近次make的时候提示下面的问题。</p>
<pre class="brush: bash; title: ; notranslate">
../driver: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by ../driver)
../driver: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ../driver)
</pre>
<p>这是因为虽然升级了GCC，生成的动态库没有替换老版本gcc的动态库。</p>
<p>解决方法：</p>
<pre class="brush: bash; title: ; notranslate">
cp /usr/local/lib64/libstdc++.so.6.0.18 /usr/lib64/
rm -f libstdc++.so.6
ln -s libstdc++.so.6.0.18 libstdc++.so.6
</pre>
<p>这里fluffos编译时的环境为libevent-2.1.so.6，为了能直接使用上，需要对应安装。</p>
<p>OK，检查一下</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@iZ237sml740Z ~]# strings /usr/lib64/libstdc++.so.6|grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
</pre>
<p>至此，已完成了GCC相关的安装&#038;设置，20170722补充。</p>
<p>现在来说下坑吧，以上的步骤完全不需要画蛇添足，几个步骤不多不少，我之前对第二步进行单独的make,make check，结果悲剧了，各种报错。碰到第二坑就是磁盘问题，上面说系统盘只有8G，编译过程中就报了磁盘不足，刚刚发现这个新服务器的数据盘没有挂载。</p>
<p><strong>挂在部分：</strong></p>
<p>1、查看数据盘<br />
在没有分区和格式化数据盘之前，使用 “df –h”命令，是无法看到数据盘的，可以使用“fdisk -l”命令查看。如下图：<br />
<img decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/08/1-610x268.png" alt="1" width="610" height="268" class="alignnone size-medium wp-image-2101" srcset="https://www.mudbest.com/wp-content/uploads/2014/08/1-610x268.png 610w, https://www.mudbest.com/wp-content/uploads/2014/08/1.png 627w" sizes="(max-width: 610px) 100vw, 610px" /><br />
友情提示：若您执行fdisk -l命令，发现没有 /dev/xvdb 标明您的云服务无数据盘，那么您无需进行挂载，此时该教程对您不适用</p>
<p>2、 对数据盘进行分区<br />
<img decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/08/2-580x430.png" alt="2" width="580" height="430" class="alignnone size-medium wp-image-2102" srcset="https://www.mudbest.com/wp-content/uploads/2014/08/2-580x430.png 580w, https://www.mudbest.com/wp-content/uploads/2014/08/2.png 672w" sizes="(max-width: 580px) 100vw, 580px" /><br />
执行“fdisk /dev/xvdb”命令，对数据盘进行分区；根据提示，依次输入“n”，“p”“1”，两次回车，“wq”，分区就开始了，很快就会完成。</p>
<p>3、 查看新的分区<br />
使用“fdisk -l”命令可以看到，新的分区xvdb1已经建立完成了。<br />
<img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/08/3-610x262.png" alt="3" width="610" height="262" class="alignnone size-medium wp-image-2103" srcset="https://www.mudbest.com/wp-content/uploads/2014/08/3-610x262.png 610w, https://www.mudbest.com/wp-content/uploads/2014/08/3.png 614w" sizes="auto, (max-width: 610px) 100vw, 610px" /></p>
<p>4、格式化新分区<br />
使用“mkfs.ext3 /dev/xvdb1”命令对新分区进行格式化，格式化的时间根据硬盘大小有所不同。<br />
<img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/08/4-610x350.png" alt="4" width="610" height="350" class="alignnone size-medium wp-image-2104" srcset="https://www.mudbest.com/wp-content/uploads/2014/08/4-610x350.png 610w, https://www.mudbest.com/wp-content/uploads/2014/08/4.png 643w" sizes="auto, (max-width: 610px) 100vw, 610px" /></p>
<p>5、添加分区信息</p>
<p>使用“echo &#8216;/dev/xvdb1 /mnt ext3 defaults 0 0&#8217; >> /etc/fstab”命令写入新分区信息。<br />
然后使用“cat /etc/fstab”命令查看，出现以下信息就表示写入成功。<br />
<img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/08/5-610x129.png" alt="5" width="610" height="129" class="alignnone size-medium wp-image-2105" srcset="https://www.mudbest.com/wp-content/uploads/2014/08/5-610x129.png 610w, https://www.mudbest.com/wp-content/uploads/2014/08/5.png 624w" sizes="auto, (max-width: 610px) 100vw, 610px" /></p>
<p>6、挂载新分区<br />
使用“mount -a”命令挂载新分区，然后用“df -h”命令查看，出现以下信息就说明挂载成功，可以开始使用新的分区了。<br />
<img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/08/6-610x113.png" alt="6" width="610" height="113" class="alignnone size-medium wp-image-2106" srcset="https://www.mudbest.com/wp-content/uploads/2014/08/6-610x113.png 610w, https://www.mudbest.com/wp-content/uploads/2014/08/6.png 624w" sizes="auto, (max-width: 610px) 100vw, 610px" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mudbest.com/centos%e5%8d%87%e7%ba%a7gcc4-4-7%e5%8d%87%e7%ba%a7gcc4-8%e6%89%8b%e8%ae%b0/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>VMware下Centos的lnmp编译安装</title>
		<link>https://www.mudbest.com/vmware%e4%b8%8bcentos%e7%9a%84lnmp%e7%bc%96%e8%be%91%e5%ae%89%e8%a3%85/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Tue, 29 Apr 2014 04:36:07 +0000</pubDate>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[lnmp]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=2043</guid>

					<description><![CDATA[VMware安装Centos就不说了，接下来是Centos的相关配置，如果Centos有防火墙的话，则需要配置 ... <a title="VMware下Centos的lnmp编译安装" class="read-more" href="https://www.mudbest.com/vmware%e4%b8%8bcentos%e7%9a%84lnmp%e7%bc%96%e8%be%91%e5%ae%89%e8%a3%85/" aria-label="阅读 VMware下Centos的lnmp编译安装">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>VMware安装Centos就不说了，接下来是Centos的相关配置，如果Centos有防火墙的话，则需要配置防火墙，非Vm通用。</p>
<p><strong>一、开启80端口、3306端口</strong><span id="more-2043"></span></p>
<pre class="brush: bash; title: ; notranslate">
vi /etc/sysconfig/iptables   #编辑防火墙配置文件 
</pre>
<p>-A INPUT -m state &#8211;state NEW -m tcp -p tcp &#8211;dport 80 -j ACCEPT（允许80端口通过防火墙）<br />
-A INPUT -m state &#8211;state NEW -m tcp -p tcp &#8211;dport 3306 -j ACCEPT（允许3306端口通过防火墙）   </p>
<pre class="brush: bash; title: ; notranslate"> 
#特别提示：很多网友把这两条规则添加到防火墙配置的最后一行，导致防火墙启动失败
#正确的应该是添加到默认的22端口这条规则的下面，添加好之后防火墙规则如下所示：
#########################################################    
# Firewall configuration written by system-config-firewall    
# Manual customization of this file is not recommended.    
*filter    
:INPUT ACCEPT &#x5B;0:0]    
:FORWARD ACCEPT &#x5B;0:0]    
:OUTPUT ACCEPT &#x5B;0:0]    
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT    
-A INPUT -p icmp -j ACCEPT    
-A INPUT -i lo -j ACCEPT    
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT    
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT    
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT    
-A INPUT -j REJECT --reject-with icmp-host-prohibited    
-A FORWARD -j REJECT --reject-with icmp-host-prohibited    
COMMIT    
#########################################################    
/etc/init.d/iptables restart  #最后重启防火墙使配置生效 
</pre>
<p><strong>二、关闭SELINUX</strong></p>
<pre class="brush: bash; title: ; notranslate">
vim /etc/selinux/config  #编辑
#SELINUX=enforcing       #注释掉 
#SELINUXTYPE=targeted    #注释掉 
SELINUX=disabled         #增加 
:wq #保存退出
shutdown -r now   #重启系统
</pre>
<p><strong>三、系统约定</strong><br />
软件源代码包存放位置：/usr/local/src<br />
源码包编译安装位置：/usr/local/软件包名字</p>
<p><strong>四、源码包下载</strong><br />
1、pcre下载(支持nginx伪静态)<br />
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz</p>
<p>2、mysql下载<br />
http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz</p>
<p>3、libmcrypt-2.5.7<br />
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz</p>
<p>3.2、libiconv-1.9.2<br />
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.9.2.tar.gz</p>
<p>3.3、zlib下载<br />
http://zlib.net/zlib-1.2.8.tar.gz</p>
<p>3.4、php下载<br />
http://ar2.php.net/distributions/php-5.5.11.tar.gz<br />
http://ar2.php.net/distributions/php-5.3.28.tar.gz</p>
<p>3.5、phpredis扩展下载<br />
https://github.com/nicolasff/phpredis/archive/master.zip</p>
<p>4、cmake下载(MySQL编译工具)<br />
http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz</p>
<p>5、nginx下载(稳定版本)<br />
http://nginx.org/download/nginx-1.4.7.tar.gz</p>
<p>安装编译工具及库文件（使用CentOS yum命令安装）</p>
<pre class="brush: bash; title: ; notranslate">
yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd  kernel keyutils  patch  perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch freetype-devel
</pre>
<p><strong>五、开始编译安装</strong><br />
1、编译准备工作</p>
<pre class="brush: bash; title: ; notranslate">
yum groupinstall &quot;Development tools&quot;
</pre>
<p>1.1、安装cmake</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/src 
tar zxvf cmake-2.8.8.tar.gz 
cd cmake-2.8.8 
./configure make  #编译 
make install   #安装
</pre>
<p>2、安装MySQL</p>
<pre class="brush: bash; title: ; notranslate">
groupadd mysql  #添加mysql组    
useradd -g mysql mysql -s /bin/false  #创建用户mysql并加入到mysql组，不允许mysql用户直接登录系统    
mkdir -p /data/mysql  #创建MySQL数据库存放目录    
chown -R mysql:mysql /data/mysql   #设置MySQL数据库目录权限    
mkdir -p /usr/local/mysql #创建MySQL安装目录    
cd /usr/local/src    
tar zxvf mysql-5.5.25.tar.gz  #解压    
cd mysql-5.5.25    
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFDIR=/etc/  #配置    
make #编译    
make install  #安装    
cd /usr/local/mysql    
cp ./support-files/my-huge.cnf  /etc/my.cnf   #拷贝配置文件（注意：如果/etc目录下面默认有一个my.cnf，直接覆盖即可）    
vim /etc/my.cnf   #编辑配置文件,在 &#x5B;mysqld] 部分增加下面一行    
datadir = /data/mysql  #添加MySQL数据库路径    
:wq!  #保存退出    
cd /usr/local/mysql/ #share 初始化的sql在这里面,下面一句命令默认读取share路径是./share/...
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/ &amp; #生成mysql系统数据库,并定义数据data存放位置
cp ./support-files/mysql.server  /etc/rc.d/init.d/mysqld  #把Mysql加入系统启动    
chmod 755 /etc/init.d/mysqld   #增加执行权限    
chkconfig mysqld on  #设置开机启动    
vim /etc/rc.d/init.d/mysqld  #编辑    
basedir = /usr/local/mysql   #MySQL程序安装路径    
datadir = /data/mysql  #MySQl数据库存放目录    
service mysqld start  #启动    
vim /etc/profile   #把mysql服务加入系统环境变量：在最后添加下面这一行    
export PATH=$PATH:/usr/local/mysql/bin    
:wq! #保存退出    
</pre>
<p>下面这两行把myslq的库文件链接到系统默认的位置，在编译类似PHP等软件时可以不用指定mysql的库文件地址。 </p>
<pre class="brush: bash; title: ; notranslate">
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock #创建快捷方式

ln -s /usr/local/mysql/lib /usr/lib/mysql    
ln -s /usr/local/mysql/include/mysql /usr/include/mysql    
shutdown -r now     #需要重启系统，等待系统重新启动之后继续在终端命令行下面操作    
mysql_secure_installation    #设置Mysql密码    

mysql --socket=/var/lib/mysql/mysql.sock #指定sock链接


</pre>
<p>根据提示按Y 回车（默认密码为空）<br />
然后输入2次密码<br />
继续按Y 回车，直到设置完成<br />
或者直接修改密码</p>
<pre class="brush: bash; title: ; notranslate">
/usr/local/mysql/bin/mysqladmin -u root -p password &quot;123456&quot; #修改密码    
service mysqld restart  #重启    
</pre>
<p>到此，mysql安装完成。</p>
<p>3、安装pcre</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/src    
mkdir /usr/local/pcre  #创建安装目录    
tar  zxvf pcre-8.30.tar.gz    
cd pcre-8.30    
./configure  --prefix=/usr/local/pcre  #配置    
make    
make install
</pre>
<p>4、安装nginx</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/src    
groupadd  www  #添加www组    
useradd -g  www www -s /bin/false  #创建nginx运行账户www并加入到www组，不允许www用户直接登录系统    
tar  zxvf nginx-1.2.0.tar.gz    
cd nginx-1.2.0    
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.30    
#注意:--with-pcre=/usr/local/src/pcre-8.30指向的是源码包解压的路径，而不是安装的路径，否则会报错    
make    
make install    
/usr/local/nginx/sbin/nginx   #启动nginx    
</pre>
<pre class="brush: bash; title: ; notranslate">
vim /etc/rc.d/init.d/nginx    #设置nginx开启启动，编辑启动文件添加下面内容 
</pre>
<pre class="brush: bash; title: ; notranslate">
#################################################################    
#!/bin/bash    
# nginx Startup script for the Nginx HTTP Server    
# it is v.0.0.2 version.    
# chkconfig: - 85 15    
# description: Nginx is a high-performance web and proxy server.    
#              It has a lot of features, but it's not for everyone.    
# processname: nginx    
# pidfile: /var/run/nginx.pid    
# config: /usr/local/nginx/conf/nginx.conf    
nginxd=/usr/local/nginx/sbin/nginx    
nginx_config=/usr/local/nginx/conf/nginx.conf    
nginx_pid=/usr/local/nginx/logs/nginx.pid    
RETVAL=0    
prog=&quot;nginx&quot;    
# Source function library.    
.  /etc/rc.d/init.d/functions    
# Source networking configuration.    
.  /etc/sysconfig/network    
# Check that networking is up.    
&#x5B; ${NETWORKING} = &quot;no&quot; ]  exit 0    
&#x5B; -x $nginxd ] || exit 0    
# Start nginx daemons functions.    
start() {    
if &#x5B; -e $nginx_pid ];then    
  echo &quot;nginx already running....&quot;    
  exit 1    
fi    
  echo -n $&quot;Starting $prog: &quot;    
  daemon $nginxd -c ${nginx_config}    
  RETVAL=$?    
  echo    
  &#x5B; $RETVAL = 0 ]  touch /var/lock/subsys/nginx    
  return $RETVAL    
}    
# Stop nginx daemons functions.    
stop() {    
       echo -n $&quot;Stopping $prog: &quot;    
       killproc $nginxd    
       RETVAL=$?    
       echo    
       &#x5B; $RETVAL = 0 ]  rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid    
}    
reload() {    
   echo -n $&quot;Reloading $prog: &quot;    
   #kill -HUP `cat ${nginx_pid}`    
   killproc $nginxd -HUP    
   RETVAL=$?    
   echo    
}    
# See how we were called.    
case &quot;$1&quot; in    
start)    
       start    
       ;;    
stop)    
       stop    
       ;;    
reload)    
       reload    
       ;;    
restart)    
       stop    
       start    
       ;;    
               
status)    
       status $prog    
       RETVAL=$?    
       ;;    
*)    
       echo $&quot;Usage: $prog {start|stop|restart|reload|status|help}&quot;    
       exit 1    
esac    
exit $RETVAL    
#################################################################  
:wq!  #保存退出 
</pre>
<pre class="brush: bash; title: ; notranslate">   
chmod 775  /etc/rc.d/init.d/nginx  #赋予文件执行权限    
chkconfig nginx on    #设置开机启动    
/etc/rc.d/init.d/nginx restart  #重启    
</pre>
<p>5.1、安装libmcrypt</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/src    
tar zxvf  libmcrypt-2.5.7.tar.gz   #解压    
cd  libmcrypt-2.5.7 #进入目录    
./configure    #配置    
make             #编译    
make install   #安装  
</pre>
<p>5.2、安装libiconv</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/src    
tar -zxvf libiconv-1.9.2.tar.gz   #解压    
cd  libiconv-1.9.2 #进入目录    
./configure --prefix=/usr/local/iconv    #配置    
make             #编译    
make install   #安装  

#重新编译php 增加编译参数--with-iconv=/usr/local/iconv 
</pre>
<p>5.3、安装zlib</p>
<pre class="brush: bash; title: ; notranslate">
yum info zlib
cd /usr/local/src    
tar -zxvf zlib-1.2.8.tar.gz   #解压    
cd  zlib-1.2.8 #进入目录    
./configure --prefix=/usr/local/zlib    #配置    
make             #编译    
make install   #安装  

#重新编译php 增加编译参数--with-iconv=/usr/local/iconv 
</pre>
<p>5.4、php5需要的devel 包：</p>
<pre class="brush: bash; title: ; notranslate">
yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel
</pre>
<p>6、安装php</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/src    
tar -zvxf php-5.3.13.tar.gz    
cd  php-5.3.13    
mkdir -p /usr/local/php5  #建立php安装目录    
#5.3配置    
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv=/usr/local/iconv --with-zlib  --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex  --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir    
#5.5配置    
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv=/usr/local/iconv  --with-zlib --with-zlib-dir=/usr/local/zlib  --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir 

make   #编译    
make install    #安装    

ln -s -f /usr/local/php5/bin/phar.phar /usr/local/php5/bin/phar
</pre>
<pre class="brush: bash; title: ; notranslate">
cp  php.ini-production   /usr/local/php5/etc/php.ini  #复制php配置文件到安装目录 
</pre>
<pre class="brush: bash; title: ; notranslate">
rm -rf /etc/php.ini   #删除系统自带配置文件    
ln -s /usr/local/php5/etc/php.ini  /etc/php.ini    #添加软链接    
cp  /usr/local/php5/etc/php-fpm.conf.default   /usr/local/php5/etc/php-fpm.conf      #拷贝模板文件为php-fpm配置文件    
vim  /usr/local/php5/etc/php-fpm.conf  #编辑    
user = www    #设置php-fpm运行账号为www    
group = www   #设置php-fpm运行组为www    
pid = run/php-fpm.pid    #取消前面的分号    
cp /usr/local/src/php-5.3.13/sapi/fpm/init.d.php-fpm   /etc/rc.d/init.d/php-fpm  #设置 php-fpm开机启动，拷贝php-fpm到启动目录    
chmod +x /etc/rc.d/init.d/php-fpm  #添加执行权限    
chkconfig php-fpm on    #设置开机启动    
</pre>
<pre class="brush: bash; title: ; notranslate">
vim /usr/local/php5/etc/php.ini    #编辑配置文件  
</pre>
<p>找到：&#8221;disable_functions =&#8221;，修改为：</p>
<pre class="brush: bash; title: ; notranslate">
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname     
</pre>
<p>#列出PHP可以禁用的函数，如果某些程序需要用到这个函数，可以删除，取消禁用。</p>
<p>找到：&#8221;;date.timezone =&#8221;，修改为：</p>
<pre class="brush: bash; title: ; notranslate">
date.timezone = PRC   #设置时区   
</pre>
<p>找到：&#8221;expose_php = On&#8221;，修改为：</p>
<pre class="brush: bash; title: ; notranslate">
修改为：expose_php = OFF  #禁止显示php版本的信息    
</pre>
<p>注意：在编译PHP的过程中可能会报UNDEFINED REFERENCE TO `LIBICONV_OPEN 无法编译PHP LIBICONV错误</p>
<p>php5.4 php-fpm重启方法</p>
<p>master进程可以理解以下信号<br />
INT, TERM 立刻终止<br />
QUIT 平滑终止<br />
USR1 重新打开日志文件<br />
USR2 平滑重载所有worker进程并重新载入配置和二进制模块</p>
<p>示例：<br />
php-fpm 启动：</p>
<pre class="brush: bash; title: ; notranslate">
/usr/local/php5/sbin/php-fpm
</pre>
<p>php-fpm 关闭：</p>
<pre class="brush: bash; title: ; notranslate">
kill -INT `cat /usr/local/php5/var/run/php-fpm.pid`
</pre>
<p>php-fpm 重启：</p>
<pre class="brush: bash; title: ; notranslate">
kill -USR2 `cat /usr/local/php5/var/run/php-fpm.pid`
</pre>
<p>查看php-fpm进程数：</p>
<pre class="brush: bash; title: ; notranslate">
ps aux | grep -c php-fpm
</pre>
<p>6.1、phpredis扩展安装</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/src/phpredis-master
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config
make
make install
</pre>
<p>增加phpredis扩展</p>
<pre class="brush: bash; title: ; notranslate">
vim /usr/local/php5/etc/php.ini
</pre>
<p>在后面增加</p>
<pre class="brush: bash; title: ; notranslate">
extension=redis.so
</pre>
<p>测试</p>
<pre class="brush: php; title: ; notranslate">
$objRedis = new Redis();
$objRedis&gt;connect('127.0.0.1',6379)
$objRedis-&gt;set('test','ok');
echo $objRedis-&gt;get('test');
</pre>
<p>7、配置nginx支持php</p>
<pre class="brush: bash; title: ; notranslate">
vim /usr/local/nginx/conf/nginx.conf      #编辑配置文件     
</pre>
<pre class="brush: bash; title: ; notranslate">
user   www  www;          #首行user去掉注释,修改Nginx运行组为www www；必须与/usr/local/php5/etc/php-fpm.conf中的user,group配置相同，否则php运行出错    
index  index.php  index.html index.htm;    #添加index.php    
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    
#    
location ~ \.php$ {    
   root           html;#此处和server下面root保持一致,默认为html    
   fastcgi_pass   127.0.0.1:9000;    
   fastcgi_index  index.php;    
   fastcgi_param  SCRIPT_FILENAME   /usr/local/nginx/html/$fastcgi_script_name;    
   include        fastcgi_params;          
</pre>
<p>注意：取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为/data/webroot/(此为网站根目录绝对路径)$fastcgi_script_name</p>
<pre class="brush: bash; title: ; notranslate">
/etc/init.d/nginx restart  #重启nginx  
</pre>
<p><a href="http://www.mudbest.com/vmware%e4%b8%8bcentos%e7%9a%84lnmp%e7%bc%96%e8%be%91%e5%ae%89%e8%a3%85/cmake-2-8-8-tar/" rel="attachment wp-att-2053">cmake-2.8.8.tar</a></p>
<p><a href="http://www.mudbest.com/vmware%e4%b8%8bcentos%e7%9a%84lnmp%e7%bc%96%e8%be%91%e5%ae%89%e8%a3%85/nginx-1-4-7-tar/" rel="attachment wp-att-2054">nginx-1.4.7.tar</a><br />
<a href="http://www.mudbest.com/vmware%e4%b8%8bcentos%e7%9a%84lnmp%e7%bc%96%e8%be%91%e5%ae%89%e8%a3%85/phpredis-master/" rel="attachment wp-att-2077">phpredis-master扩展</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>rsync安装与使用细节</title>
		<link>https://www.mudbest.com/rsync%e5%ae%89%e8%a3%85%e4%b8%8e%e4%bd%bf%e7%94%a8%e7%bb%86%e8%8a%82/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Fri, 28 Mar 2014 09:30:12 +0000</pubDate>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[同步]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=2028</guid>

					<description><![CDATA[老套的搬用一下rsync的介绍，rsync是Linux系统下的数据镜像备份工具，从软件的命名上就可以看出来了— ... <a title="rsync安装与使用细节" class="read-more" href="https://www.mudbest.com/rsync%e5%ae%89%e8%a3%85%e4%b8%8e%e4%bd%bf%e7%94%a8%e7%bb%86%e8%8a%82/" aria-label="阅读 rsync安装与使用细节">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>老套的搬用一下rsync的介绍，rsync是Linux系统下的数据镜像备份工具，从软件的命名上就可以看出来了——remote sync。rsync支持大多数的类Unix系统，无论是Linux、Solaris还是BSD上都经过了良好的测试。它的特性如下： </p>
<p>1、可以镜像保存整个目录树和文件系统。<br />
2、可以很容易做到保持原来文件的权限、时间、软硬链接等等。 <span id="more-2028"></span><br />
3、无须特殊权限即可安装。<br />
4、优化的流程，文件传输效率高。<br />
5、可以使用rcp、ssh等方式来传输文件，当然也可以通过直接的socket连接。</p>
<p><strong>一、安装Rsync。</strong><br />
如果支持yum安装，直接使用：</p>
<pre class="brush: bash; title: ; notranslate">
yum install xinetd
</pre>
<p>如果是源码安装则到官方http://rsync.samba.org/下载source包即可，安装过程大致如下：</p>
<pre class="brush: bash; title: ; notranslate">
tar zxvf *
cd *
./configure
make
make install
#如果是已安装了RPM版的Rsync，并且要安装新版的Rsync，需要先删除Rsync 
#rpm -e rsync
</pre>
<p>Redhat会有一个包依赖rsync，可以使用rpm -e rsync &#8211;nodeps卸载。另外，RPM版的rsync带了一个服务端的启动脚本，/etc/xinetd.d/rsync可以保留，但是需要注意的是必须在主服务器和同步服务器上都安装rsync，其中主服务器上是以服务器模式运行rsync，而同步上则以客户端方式运行rsync。这样在主服务器上运行rsyn守护进程，在同步上用crond定时运行客户程序来同步主服务器上需要同步的内容。</p>
<p><strong>二、配置rsync服务器端</strong></p>
<p>rsync服务器的配置文件为/etc/rsyncd.conf，其控制认证、访问、日志记录等等。该文件是由一个或多个模块结构组成。一个模块定义以方括弧中的模块名开始，直到下一个模块定义开始或者文件结束，模块中包含格式为name=value的参数定义。每个模块其实就对应需要备份的一个目录树，比方说在我们的实例环境中，有三个目录树需要备份：/www/和/mirror/file0/和/mirror/file1/目录，那么就需要在配置文件中定义三个模块，分别对应三个目录树。配置文件是行为单位的，也就是每个新行都表示一个新的注释、模块定义或者参数赋值。</p>
<pre class="brush: bash; title: ; notranslate">
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#       allows crc checksumming etc.
service rsync
{
        disable = no
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}
</pre>
<p>将disable 改为no，另外将配置成随系统启动：</p>
<pre class="brush: bash; title: ; notranslate">
chkconfig rsync on
</pre>
<p>重新启动：</p>
<pre class="brush: bash; title: ; notranslate">
service xinetd restart  
#重新加载配置
/etc/rc.d/init.d/xinetd reload  
</pre>
<p>查看进程是否在监听：</p>
<pre class="brush: bash; title: ; notranslate">
netstat -a | grep rsync
#或者
lsof -i :873
</pre>
<p>配置rsync账户相关：</p>
<pre class="brush: bash; title: ; notranslate">
#配置rsync密码文件，(名字随便写，只要和配置文件里的一致即可)，格式(一行一个用户) ：
vim /home/rsync.ps
hkshadow:hkshadow
#配置rsync密码文件权限 
chown root.root rsync.ps
#注意：该文件只能是root用户可读写的，注意，出于安全目的，这个文件的属性必需是只有属主可读，否则rsync将拒绝运行。 
chmod 600 rsync.ps
</pre>
<p>创建配置文件：</p>
<pre class="brush: bash; title: ; notranslate">
uid = nobody # 备份以什么身份进行，用户
ID gid = nobody # 备份以什么身份进行，组ID ，注意这个用户ID和组ID，如果要方便的话，可以设置成root，这样rsync几乎就可以读取任何文件和目录了，但是也带来安全隐患。建议设置成只能读取你要备份的目录和文件即可。 
use chroot = no  max connections = 0  #最大连接数，0代表没有限制  
#port = 873          #默认端口873  
pid file = /var/log/rsync/rsyncd.pid   #运行进程的ID写到哪里 
#lock file = /var/log/rsync/rsync.lock

log file = /var/log/rsync/rsyncd.log  #日志记录文件 
motd file = /var/log/rsync/rsyncd.motd  #欢迎消息 
strict modes =yes         #是否检查口令文件的权限 

&#x5B;txt]           # 指定认证的备份模块名  
path = /www/htdocs/pub/test/   # 需要备份的目录 
comment = BACKUP attachment           # 注释  
ignore errors              # 忽略一些无关的IO错误  
read only = false          # 设置为非只读，即可以传至服务器的相应目录。 
list = false                # 不允许列文件  
exclude = test/ test.php      #设置不同步的目录或文件用空格隔开 
hosts allow = 210.51.0.80     #允许连接服务器的主机IP地址，如果多个ip则用空格隔开 
hosts deny = 0.0.0.0/0.0.0.0         #禁止连接服务器的主机IP地址，也可为*，表示所有。 
auth users = msyn                     # 认证的用户名，如果没有这行，则表明是匿名 
secrets file = /home/rsync.ps      # 认证文件名，用来存放密码
</pre>
<p><strong>三、配置客户端(省略)</strong><br />
配置密码文件 (注：为了安全，设定密码档案的属性为：600。rsync.scrt的密码一定要和Rsync Server 密码设定案里的密码一样)</p>
<p>下一步是一个运行rsync的例子：</p>
<pre class="brush: bash; title: ; notranslate">
rsync -vzrltogp --progress --delete user@x.x.x.168::attachment  /usr/local/apache/htdocs/pub/html/ --password-file=/home/rsync.ps
</pre>
<p>上面这个命令行中-vzrtopg代表的意思是：<br />
-v表示verbose(详细)<br />
-z表示zip（压缩）<br />
-r表示recursive（递归目录）<br />
-topg是保持文件原有属性如o=owner(属主)、t=times(时间)、p=perms(权限)、g=group(组)的参数 -H表示保持硬连接<br />
-l：保留软链结  -u：表示只更新源文件比目标时间新的文件<br />
&#8211;progress是指显示出详细的进度情况<br />
&#8211;delete是指如果服务器端删除了这一文件，那么客户端也相应把文件删除，保持真正的一致。 user@x.x.x.168::attachment 是表示对服务器x.x.x.168中的attachment模块进行备份，登录帐号是user<br />
&#8211;password-file = /etc/rsync.scrt来指定密码文件，这里需要注意的是这份密码文件权限属性要设得只 有属主可读(权限为600)，属主为正在运行此命令的用户。<br />
-a:(-a, &#8211;archive equivalent to -rlptgoD)以archive模式操作，复制目录、符号连接在这里面</p>
<p>==========================================================================<br />
另外，可以创建一个脚本运行这个命令，并记录日志：</p>
<pre class="brush: bash; title: ; notranslate">
# cat /usr/local/bin/rsync.sh  
#!/bin/bash    
DATE=`date +%w`  
rsync -avzH --progress --delete inburst@192.168.168.52::inburst /home/quack/backup/$DATE --password-file=/etc/rsync.pass &gt; /var/log/rsync.$DATE   
</pre>
<p>修改/etc/crontab做好定时更新(配置文件 /etc/crontab)  </p>
<pre class="brush: bash; title: ; notranslate">
crontab -e  15 4 * * 6 root rsync.sh  
crontab -l    
//查看所有自定义任务 
/etc/init.d/crond restart    //重启动任务计划 

#crontab Crontab文件的格式： 
#第1列分钟1～59  
#第2列小时1～23（0表示子夜） 
#第3列日1～31  
#第4列月1～12  
#第5列星期0～6（0表示星期天）
</pre>
<p>扩展阅读：<br />
<strong>关于 rsync 中: 和 :: 及 rysnc 和 ssh 认证协议的区别</strong></p>
<p>（1）双冒号 “::”的用法：<br />
rsync 传输文件前需要登录认证，那么这个过程用到的协议有两种：ssh 和 rsync<br />
何时用ssh 协议呢？<br />
我们平时用的  rsync -av /SRC root@192.168.99.36:/DEST 就是默认用的 ssh 协议<br />
这种方式默认是省略了 -e ssh 的，与下面等价：</p>
<pre class="brush: bash; title: ; notranslate">
rsync -av /SRC -e ssh root@192.168.99.36:/DEST
</pre>
<p>当遇到要修改端口的时候，我们可以：</p>
<pre class="brush: bash; title: ; notranslate">
rsync -av /SRC -e &quot;ssh -p36000&quot; root@192.168.99.36:/DEST
</pre>
<p>何时用rysnc协议呢？</p>
<pre class="brush: bash; title: ; notranslate">
rsync -av /SRC rsync://root@192.168.99.36:36000/modual/DestPath
</pre>
<p>注意：这条语句显示的指明了使用rsync认证协议，port后的modual是rsync服务端配置文件rsyncd.conf<br />
里面配置的模块名，模块里面会包含一些用户名、密码、路径等认证信息。<br />
使用rsync认证，还有一种写法：</p>
<p>1<br />
rsync -av /SRC &#8211;port=36000 root@172.17.256.211::modual/DestPath<br />
注意：这种写法不需显示指定 rsync 协议，而是根据 :: 来识别的，端口自己用 &#8211;port 指定。<br />
而且这里 modual 前面没有 / 的。</p>
<p>总结： 双冒号:: 是用在 rsync 协议里面的，: 一般用在ssh协议里面，这两种用法各有千秋：<br />
rsync协议你需要在rsync服务端配置模块，这增加了运维工作量，但是安全，因为不需要对客户公开帐号密码。<br />
ssh协议方便，不需配置，拿到帐号密码即可开工，但是对客户是暴露的，有安全风险。<br />
还需要注意的是用rsync协议认证的时候，后面跟的是模块名，而不是路径，这点要注意。</p>
<p>（2）关于 rsync &#8211;port 的man文档如下：<br />
rsync 客户端 &#8211;port<br />
 &#8211;port=PORT<br />
              This  specifies  an alternate TCP port number to use rather than<br />
              the default of 873.  This is only needed if you  are  using  the<br />
              double-colon  (::) syntax to connect with an rsync daemon (since<br />
              the URL syntax has a way to specify the port as a  part  of  the<br />
              URL).<br />
rsync 服务端 &#8211;port<br />
 &#8211;port=PORT<br />
              This  specifies  an  alternate TCP port number for the daemon to<br />
              listen on rather than the default of 873.  See also  the  &#8220;port&#8221;<br />
              global option in the rsyncd.conf manpage.</p>
<p>（3）附一些参考文档：<br />
rsync实例用法及参数详解<br />
http://hi.baidu.com/leejun_2005/item/672c31d4c12a8b1b20e25041</p>
<p>rsync命令用法入门<br />
http://hi.baidu.com/leejun_2005/item/a04d17c4cf24547088ad9e7c</p>
<p>rsync 的核心算法<br />
http://hi.baidu.com/leejun_2005/item/11651fc379229f52bdef69b7</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>由于binlog未及时清理导致硬盘爆满无法启动mysql</title>
		<link>https://www.mudbest.com/%e7%94%b1%e4%ba%8ebinlog%e6%9c%aa%e5%8f%8a%e6%97%b6%e6%b8%85%e7%90%86%e5%af%bc%e8%87%b4%e7%a1%ac%e7%9b%98%e7%88%86%e6%bb%a1%e6%97%a0%e6%b3%95%e5%90%af%e5%8a%a8mysql/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Sat, 08 Feb 2014 05:04:38 +0000</pubDate>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[binlog]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=2017</guid>

					<description><![CDATA[这几天由于太忙了，7天没有观察服务器了，今天用手机打开网站发现报mysql.sock丢失的错误，刚开始以为是m ... <a title="由于binlog未及时清理导致硬盘爆满无法启动mysql" class="read-more" href="https://www.mudbest.com/%e7%94%b1%e4%ba%8ebinlog%e6%9c%aa%e5%8f%8a%e6%97%b6%e6%b8%85%e7%90%86%e5%af%bc%e8%87%b4%e7%a1%ac%e7%9b%98%e7%88%86%e6%bb%a1%e6%97%a0%e6%b3%95%e5%90%af%e5%8a%a8mysql/" aria-label="阅读 由于binlog未及时清理导致硬盘爆满无法启动mysql">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>这几天由于太忙了，7天没有观察服务器了，今天用手机打开网站发现报mysql.sock丢失的错误，刚开始以为是my.ini修改的原因，用df一看，/dev/xvda1的占用已经100%了，这样的情况还能启动mysql就真的逆天了。这时候想到了用sql删除binlog，但是根本进不去控制台，连安全模式都启动不了，以下是具体操作。<span id="more-2017"></span></p>
<p>分配了20G的硬盘，活生生的被binlog吃完了。</p>
<pre class="brush: sql; title: ; notranslate">
tail -f /opt/server/mysql/var/slyar.err
</pre>
<p>看了一下Mysql的错误日志，意外状况出现……</p>
<pre class="brush: sql; title: ; notranslate">
Disk is full writing './mysql-bin.~rec~' (Errcode: 28). Waiting for someone to free space... (Expect up to 60 secs delay for server to continue after freeing disk space)
</pre>
<p>神奇的情况，居然是因为磁盘满了无法写入日志导致Mysql起不来。</p>
<pre class="brush: sql; title: ; notranslate">
root@hkshadow# df 
Filesystem 1K-blocks Used Available Use% Mounted on 
/dev/xvda1 20641404 20641404 0 100% / 
</pre>
<p>基本上就是被这些玩意占满了，查了一下Mysql手册发现这些东西也没啥用，直接删除(此操作最好在Mysql服务停止时进行，因为当前日志使用的话无法删除，而且有可能导致一些其它问题，不过用mysql>reset master命令可以直接清空日志)。</p>
<pre class="brush: sql; title: ; notranslate">/opt/server/mysql/var/
root@hkshadow# cd 
root@hkshadow# rm -f mysql-bin.*
</pre>
<p>如果一定要使用binlog又担心时间久了没及时清理的话，可以在my.ini里设置binlog过期时间。</p>
<pre class="brush: sql; title: ; notranslate">
expire_logs_days = 7
</pre>
<p>如果不需要binlog的话可以关闭掉，避免未来得及监控导致的系列问题。</p>
<pre class="brush: sql; title: ; notranslate">
vim /etc/my.cnf
</pre>
<p>注释掉下面2行</p>
<pre class="brush: sql; title: ; notranslate">
log-bin=mysql-bin
binlog_format=mixed
</pre>
<p>然后重启即可</p>
<pre class="brush: sql; title: ; notranslate">
/etc/init.d/mysqld restart
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>linux终止超时的进程</title>
		<link>https://www.mudbest.com/linux%e7%bb%88%e6%ad%a2%e8%b6%85%e6%97%b6%e7%9a%84%e8%bf%9b%e7%a8%8b/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Thu, 30 Jan 2014 09:29:43 +0000</pubDate>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[kill]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[超时进程]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=2009</guid>

					<description><![CDATA[目前服务器数据接口调用的地方较多，虽然将超时控制的很好了，但依然还是有超时的脚本占了进程，由于作了-eq这样的 ... <a title="linux终止超时的进程" class="read-more" href="https://www.mudbest.com/linux%e7%bb%88%e6%ad%a2%e8%b6%85%e6%97%b6%e7%9a%84%e8%bf%9b%e7%a8%8b/" aria-label="阅读 linux终止超时的进程">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>目前服务器数据接口调用的地方较多，虽然将超时控制的很好了，但依然还是有超时的脚本占了进程，由于作了-eq这样的判断进程数的方法，超时进程的导致无法开启新进程，根据进程的执行时间可以判断是否为超时进程，并kill掉即可解决问题。</p>
<p>shell：<br />
<span id="more-2009"></span></p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash
function show_elapsed_time()
{
    user_hz=$(getconf CLK_TCK) #mostly it's 100 on x86/x86_64
    pid=$1
    jiffies=$(cat /proc/$pid/stat | cut -d&quot; &quot; -f22)
    sys_uptime=$(cat /proc/uptime | cut -d&quot; &quot; -f1)
    last_time=$(( ${sys_uptime%.*} - $jiffies/$user_hz ))
    #echo &quot;the process $pid lasts for $last_time seconds.&quot;
    time_out=1800 #限制为 30 分钟
    if &#x5B; &quot;$last_time&quot; -ge &quot;$time_out&quot; ]
    then
        echo &quot;the process $pid lasts for $last_time seconds.&quot;
        kill -9 $pid
    fi
}
#pgrep php 用于返回进程名包含 php 字符的进程ID列表
for pid in `pgrep php`
do
    #echo 'It is '$pid  
    show_elapsed_time $pid

done
</pre>
<p>//匹配筛选</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash
function show_elapsed_time()
{
    user_hz=$(getconf CLK_TCK) #mostly it's 100 on x86/x86_64
    pid=$1
    jiffies=$(cat /proc/$pid/stat | cut -d&quot; &quot; -f22)
    sys_uptime=$(cat /proc/uptime | cut -d&quot; &quot; -f1)
    last_time=$(( ${sys_uptime%.*} - $jiffies/$user_hz ))
    #echo &quot;the process $pid lasts for $last_time seconds.&quot;
    time_out=180
    if &#x5B; &quot;$last_time&quot; -ge &quot;$time_out&quot; ]
    then
        echo &quot;the process $pid lasts for $last_time seconds.&quot;
        kill -9 $pid
    fi
}

#for pid in `pgrep php`
for pid in `ps -ef| grep a.php | awk '{print $2}'`
do
    echo 'It is '$pid  
    show_elapsed_time $pid

done
</pre>
<p>扩展阅读：<br />
<strong>Linux bash shell 逐行读取文本文件的三种方法</strong></p>
<p>方法一，指定换行符读取：</p>
<pre class="brush: bash; title: ; notranslate">
#! /bin/bash  
   
IFS=&quot;  
&quot;  
   
for LINE in `cat /etc/passwd`  
do  
        echo $LINE 
done
</pre>
<p>方法二，文件重定向给read处理：</p>
<pre class="brush: bash; title: ; notranslate">
#! /bin/bash  
   
cat /etc/passwd | while read LINE  
do
        echo $LINE 
done
</pre>
<p>方法三，用read读取文件重定向：</p>
<pre class="brush: bash; title: ; notranslate">
#! /bin/bash  
   
while read LINE
do
        echo $LINE 
done &lt; /etc/passwd
</pre>
<p><strong>Linux获取进程已经运行的时间</strong><br />
本来，ps本身也提供了选项来查询的，但是比较直观和形象（如 10:32这样的），不是用seconds为单位，并不方便在脚本中直接使用。ps中的关于进程时间的命令如下：</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# ps -p 4260 -o pid,start_time,etime,comm
  PID START     ELAPSED COMMAND
 4260 Apr18 16-08:57:25 gnome-session
</pre>
<p>其中第三列的16-08:57:25就是进程运行的时间，为：16天8小时57分25秒。<br />
根据一些/proc文件系统中的信息，查询进程运行时间脚本分享如下：</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash
function show_elapsed_time()
{
	user_hz=$(getconf CLK_TCK) #mostly it's 100 on x86/x86_64
	pid=$1
	jiffies=$(cat /proc/$pid/stat | cut -d&quot; &quot; -f22)
	sys_uptime=$(cat /proc/uptime | cut -d&quot; &quot; -f1)
	last_time=$(( ${sys_uptime%.*} - $jiffies/$user_hz ))
	echo &quot;the process $pid lasts for $last_time seconds.&quot;
}
 
if &#x5B; $# -ge 1 ];then
	for pid in $@
	do
		show_elapsed_time $pid
	done
fi
 
while read pid
do
	show_elapsed_time $pid
done
</pre>
<p>执行过程和结果如下：</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# ./get_process_time.sh 4260
the process #4260 lasts for 1415417 seconds.
</pre>
<p><strong>linux根据进程名查询PID值</strong></p>
<p>很多时候，我们都需要根据进程名查询进程PID值，笔者总结了多种方法解决：<br />
1、pidof命令<br />
用pidof指令很轻易的找到您所想要的程序内容<br />
范例二：仅列出关于 root 的所有程序开启的 socket 档案</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# lsof -u root -a -U
COMMAND     PID USER   FD   TYPE     DEVICE SIZE   NODE NAME
kmodule     793 root    4u  unix 0xd744b700        3549 socket
udevd       801 root    5u  unix 0xd744bb40        3561 socket
syslogd    1539 root    0u  unix 0xd75946e0        4870 /dev/log
</pre>
<p># 注意到那个 -a 吧！如果你分别输入 lsof -u root 及 lsof -U ，会有啥信息？<br />
# 使用 lsof -u root -U 及 lsof -u root -a -U ，呵呵！都不同啦！<br />
# -a 的用途就是在解决同时需要两个项目都成立时啊！ ^_^</p>
<p>范例三：请列出目前系统上面所有的被启动的周边设备</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# lsof +d /dev
COMMAND     PID    USER   FD   TYPE     DEVICE SIZE NODE NAME
init          1    root   10u  FIFO       0,13      1834 /dev/initctl
kmodule     793    root    2u   CHR        1,3      2135 /dev/null
kmodule     793    root    3u   CHR        5,1      2134 /dev/console
udevd       801    root    2u   CHR        1,3      2135 /dev/null
syslogd    1539    root    0u  unix 0xd75946e0      4870 /dev/log xinetd     1589    root    1r   CHR        1,3      2135 /dev/null
</pre>
<p>#看吧！因为设备都在 /dev 里面嘛！所以啰，使用搜寻目录即可啊！<br />
范例四：秀出属于 root 的 bash 这支程序所开启的档案</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# lsof -u root | grep bash
bash   26199 root  cwd   DIR   3,2   4096   159875 /root
bash   26199 root  rtd   DIR   3,1   4096        2 /
bash   26199 root  txt   REG   3,1 686520   294425 /bin/bash
bash   26199 root  mem   REG   3,1  83160    32932 /usr/lib/gconv/BIG5.so
bash   26199 root  mem   REG   3,1  46552   915764 /lib/libnss_files-2.3.5.so
#.....底下的数据就省略不写了.....
</pre>
<p>这个指令可以找出您想要知道的某个程序是否有启用哪些信息？ 例如上头提到的范例四的执行结果呢！</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pidof &#x5B;-sx] program_name
</pre>
<p>参数：<br />
-s  ：仅列出一个 PID 而不列出所有的 PID<br />
-x  ：同时列出该 program name 可能的 PPID 那个程序的 PID<br />
范例：<br />
范例一：列出目前系统上面 init 以及 syslogd 这两个程序的 PID</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pidof init syslogd
</pre>
<p>1 2546<br />
# 理论上，应该会有两个 PID 才对。上面的显示也是出现了两个 PID 喔。<br />
# 分别是 init 及 syslogd 这两支程序的 PID 啦。</p>
<p>范例二：找出 bash 即以 bash 为 PPID 的几个主要的 PID</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pidof -x bash
2961 2959 338
</pre>
<p># 因为我的系统被我登入之后，我就会主动取得一个 bash 的程序，所以啰，<br />
# 很自然就会拥有一个 PID 啊。只要我再以底下的方式，就可以取得我所想要的 PID 内容。</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# ps aux | egrep '(2961|2959|338)'
dmtsai   338  0.0  0.1  6024 1536 pts/0    Ss   16:43   0:00 -bash
kiki    2961  0.0  0.1  6025 1526 pts/0    Ss   17:43   0:00 -bash
#.....以下省略......
</pre>
<p>很简单的用法吧，讲解的这个pidof 指令，并且配合 ps aux 与正规表示法， 就可以很轻易的找到您所想要的程序内容了呢。 </p>
<p>2、pgrep命令<br />
语 法</p>
<pre class="brush: bash; title: ; notranslate">
pgrep &#x5B;必要参数] &#x5B;选择参数]  &#x5B;程序]      功 能   pgrep 命令：可以依照进程ID来浏览程序
类似命令: ps  kill  grep  killall  less  top   
  
参数必要参数
-f 显示完整程序
-l 显示源代码
-n 显示新程序
-o 显示旧程序
-v 与条件不符合的程序
-x 与条件符合的程序

选择参数
-p&lt;进程号&gt; 列出父进程为用户指定进程的进程信息
-t&lt;终端&gt; 指定终端下的所有程序
-u&lt;用户&gt; 指定用户的程序
</pre>
<p>范例</p>
<p>范例1：显示指定终端相联系的程序</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pgrep -t tty2
862
8236
8672
&#x5B;root@AY140122175316610bdcZ shell]#
</pre>
<p>范例2：显示与某字符串相关的命令</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pgrep at //列出at字符串相关的程序
3
5
19
20
42
&#x5B;root@AY140122175316610bdcZ shell]#
</pre>
<p>范例3：列出父进程为init进程的所有进程</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pgrep -P 1 //列出父进程为1的所有进程
314
317
672
&#x5B;root@AY140122175316610bdcZ shell]#
</pre>
<p>范例4： 反向选择</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pgrep -v -P 1 //列出父进程不为1的进程
1
2
3
&#x5B;root@AY140122175316610bdcZ shell]#
</pre>
<p>范例5：显示指定用户进程</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;root@AY140122175316610bdcZ shell]# pgrep -u root
1
2
3
#显示结果省略
</pre>
<p>3、ps命令<br />
查找进程httpd的PID：</p>
<pre class="brush: bash; title: ; notranslate">
ps -ef | grep &quot;httpd&quot; | grep -v &quot;grep&quot; | awk '{print $2}' 
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
