<?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>Haihan&#039;Blog</title>
	<atom:link href="http://www.phpwebgo.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpwebgo.com</link>
	<description>Linux、Apache/Nginx、MySQL、PHP爱好者</description>
	<lastBuildDate>Mon, 14 May 2012 10:48:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>linux常见命令的列表</title>
		<link>http://www.phpwebgo.com/2012/05/14/329.html</link>
		<comments>http://www.phpwebgo.com/2012/05/14/329.html#comments</comments>
		<pubDate>Mon, 14 May 2012 10:16:10 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=329</guid>
		<description><![CDATA[系统 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本或者用cat /etc/issue # cat /proc/cpuinfo # 查看CPU信息 # cat /proc/meminfo # 查看内存信息 # cat /proc/version # 查看内核版本 # lsb_release -a # 列出操作系统所有版本信息 # getconf LONG_BIT # 查看操作系统位数(是32位还是64位) # hostname # 查看计算机名 # lspci -tv # 列出所有PCI设备 # lsusb -tv # 列出所有USB设备 # lsmod [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: bash; gutter: true">系统

# uname -a               # 查看内核/操作系统/CPU信息
# head -n 1 /etc/issue   # 查看操作系统版本或者用cat /etc/issue
# cat /proc/cpuinfo      # 查看CPU信息
# cat /proc/meminfo      # 查看内存信息
# cat /proc/version      # 查看内核版本
# lsb_release -a         # 列出操作系统所有版本信息
# getconf LONG_BIT       # 查看操作系统位数(是32位还是64位)
# hostname               # 查看计算机名
# lspci -tv              # 列出所有PCI设备
# lsusb -tv              # 列出所有USB设备
# lsmod                  # 列出加载的内核模块
# env                    # 查看环境变量

资源

# free -m                # 查看内存使用量和交换区使用量
# df -h                  # 查看各分区使用情况
# du -sh &lt;目录名&gt;        # 查看指定目录的大小
# grep MemTotal /proc/meminfo   # 查看内存总量
# grep MemFree /proc/meminfo    # 查看空闲内存量
# uptime                 # 查看系统运行时间、用户数、负载
# cat /proc/loadavg      # 查看系统负载

磁盘和分区

# mount | column -t      # 查看挂接的分区状态
# df -h                  # 显示空余磁盘空间
# fdisk -l               # 查看所有分区
# swapon -s              # 查看所有交换分区
# hdparm -i /dev/hda     # 查看磁盘参数(仅适用于IDE设备)
# dmesg | grep IDE       # 查看启动时IDE设备检测状况

网络

# ifconfig               # 查看所有网络接口的属性
# iptables -L            # 查看防火墙设置
# route -n               # 查看路由表
# netstat -lntp          # 查看所有监听端口
# netstat -antp          # 查看所有已经建立的连接
# netstat -s             # 查看网络统计信息

进程

# ps -ef                 # 查看所有进程
# top                    # 实时显示进程状态

用户

# w                      # 查看活动用户
# id &lt;用户名&gt;            # 查看指定用户信息
# last                   # 查看用户登录日志
# cut -d: -f1 /etc/passwd   # 查看系统所有用户
# cut -d: -f1 /etc/group    # 查看系统所有组
# crontab -l             # 查看当前用户的计划任务

服务

# chkconfig --list       # 列出所有系统服务
# chkconfig --list | grep on    # 列出所有启动的系统服务

程序

# rpm -qa                # 查看所有安装的软件包</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table>
<tbody>
<tr id="misc">
<td colspan="2">命令</td>
<td>描述</td>
</tr>
<tr>
<td>•</td>
<td>apropos whatis</td>
<td>显示和word相关的命令。 参见<a href="http://www.pixelbeat.org/scripts/threadsafe">线程安全</a></td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/lkdb/less.html">man</a> -t man | ps2pdf &#8211; &gt; man.pdf</td>
<td>生成一个PDF格式的帮助文件</td>
</tr>
<tr>
<td></td>
<td>which command</td>
<td>显示命令的完整路径名</td>
</tr>
<tr>
<td></td>
<td>time command</td>
<td>计算命令运行的时间</td>
</tr>
<tr>
<td>•</td>
<td>time cat</td>
<td>开始计时. Ctrl-d停止。参见<a href="http://www.pixelbeat.org/scripts/sw">sw</a></td>
</tr>
<tr>
<td>•</td>
<td>nice <a href="http://www.pixelbeat.org/lkdb/info.html">info</a></td>
<td>运行一个低优先级命令（这里是info）</td>
</tr>
<tr>
<td>•</td>
<td>renice 19 -p $$</td>
<td>使脚本运行于低优先级。用于非交互任务。</td>
</tr>
<tr id="dirs">
<td colspan="3">目录操作</td>
</tr>
<tr>
<td>•</td>
<td>cd -</td>
<td>回到前一目录</td>
</tr>
<tr>
<td>•</td>
<td>cd</td>
<td>回到用户目录</td>
</tr>
<tr>
<td></td>
<td>(cd dir &amp;&amp; command)</td>
<td>进入目录dir，执行命令command然后回到当前目录</td>
</tr>
<tr>
<td>•</td>
<td>pushd <strong>.</strong></td>
<td>将当前目录压入栈，以后你可以使用popd回到此目录</td>
</tr>
<tr id="file_search">
<td colspan="3">文件搜索</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/settings/.bashrc">alias</a> l=&#8217;ls -l &#8211;color=auto&#8217;</td>
<td>单字符文件列表命令</td>
</tr>
<tr>
<td>•</td>
<td>ls -lrt</td>
<td>按日期显示文件. 参见<a href="http://www.pixelbeat.org/scripts/newest">newest</a></td>
</tr>
<tr>
<td>•</td>
<td>ls /usr/bin | pr -T9 -W$COLUMNS</td>
<td>在当前终端宽度上打印9列输出</td>
</tr>
<tr>
<td></td>
<td>find -name &#8216;*.[ch]&#8216; | xargs grep -E &#8216;expr&#8217;</td>
<td>在当前目录及其子目录下所有.c和.h文件中寻找&#8217;expr&#8217;. 参见<a href="http://www.pixelbeat.org/scripts/findrepo">findrepo</a></td>
</tr>
<tr>
<td></td>
<td>find -type f -print0 | xargs -r0 grep -F &#8216;example&#8217;</td>
<td>在当前目录及其子目录中的常规文件中查找字符串&#8217;example&#8217;</td>
</tr>
<tr>
<td></td>
<td>find -maxdepth 1 -type f | xargs grep -F &#8216;example&#8217;</td>
<td>在当前目录下查找字符串&#8217;example&#8217;</td>
</tr>
<tr>
<td></td>
<td>find -maxdepth 1 -type d | while <a href="http://www.pixelbeat.org/programming/readline/">read</a> dir; do echo $dir; echo cmd2; done</td>
<td>对每一个找到的文件执行多个命令(使用while循环)</td>
</tr>
<tr>
<td>•</td>
<td>find -type f ! -perm -444</td>
<td>寻找所有不可读的文件(对网站有用)</td>
</tr>
<tr>
<td>•</td>
<td>find -type d ! -perm -111</td>
<td>寻找不可访问的目录(对网站有用)</td>
</tr>
<tr>
<td>•</td>
<td>locate -r &#8216;file[^/]*\.txt&#8217;</td>
<td>使用locate 查找所有符合*file*.txt的文件</td>
</tr>
<tr>
<td>•</td>
<td>look reference</td>
<td>在（有序）字典中快速查找</td>
</tr>
<tr>
<td>•</td>
<td>grep <a href="http://www.pixelbeat.org/settings/.bashrc">&#8211;color</a> reference /usr/share/dict/words</td>
<td>使字典中匹配的正则表达式高亮</td>
</tr>
<tr id="archives">
<td colspan="3">归档 and compression</td>
</tr>
<tr>
<td></td>
<td>gpg -c file</td>
<td>文件加密</td>
</tr>
<tr>
<td></td>
<td>gpg file.gpg</td>
<td>文件解密</td>
</tr>
<tr>
<td></td>
<td>tar -c dir/ | bzip2 &gt; dir.tar.bz2</td>
<td>将目录dir/压缩打包</td>
</tr>
<tr>
<td></td>
<td>bzip2 -dc dir.tar.bz2 | tar -x</td>
<td>展开压缩包 (对tar.gz文件使用gzip而不是bzip2)</td>
</tr>
<tr>
<td></td>
<td>tar -c dir/ | gzip | gpg -c | ssh user@remote &#8216;dd of=dir.tar.gz.gpg&#8217;</td>
<td>目录dir/压缩打包并放到远程机器上</td>
</tr>
<tr>
<td></td>
<td>find dir/ -name &#8216;*.txt&#8217; | tar -c &#8211;files-from=- | bzip2 &gt; dir_txt.tar.bz2</td>
<td>将目录dir/及其子目录下所有.txt文件打包</td>
</tr>
<tr>
<td></td>
<td>find dir/ -name &#8216;*.txt&#8217; | xargs cp -a &#8211;target-directory=dir_txt/ &#8211;parents</td>
<td>将目录dir/及其子目录下所有.txt按照目录结构拷贝到dir_txt/</td>
</tr>
<tr>
<td></td>
<td>( tar -c /dir/to/copy ) | ( cd /where/to/ &amp;&amp; tar -x -p )</td>
<td>拷贝目录copy/到目录/where/to/并保持文件属性</td>
</tr>
<tr>
<td></td>
<td>( cd /dir/to/copy &amp;&amp; tar -c <strong>.</strong> ) | ( cd /where/to/ &amp;&amp; tar -x -p )</td>
<td>拷贝目录copy/下的所有文件到目录/where/to/并保持文件属性</td>
</tr>
<tr>
<td></td>
<td>( tar -c /dir/to/copy ) | ssh -C user@remote &#8216;cd /where/to/ &amp;&amp; tar -x -p&#8217;</td>
<td>拷贝目录copy/到远程目录/where/to/并保持文件属性</td>
</tr>
<tr>
<td></td>
<td>dd bs=1M if=/dev/sda | gzip | ssh user@remote &#8216;dd of=sda.gz&#8217;</td>
<td>将整个硬盘备份到远程机器上</td>
</tr>
<tr id="rsync">
<td colspan="3">rsync (使用 &#8211;dry-run选项进行测试)</td>
</tr>
<tr>
<td></td>
<td>rsync -P rsync://rsync.server.com/path/to/file file</td>
<td>只获取diffs.当下载有问题时可以作多次</td>
</tr>
<tr>
<td></td>
<td>rsync &#8211;bwlimit=1000 fromfile tofile</td>
<td>有速度限制的本地拷贝，对I/O有利</td>
</tr>
<tr>
<td></td>
<td>rsync -az -e ssh &#8211;delete ~/public_html/ remote.com:&#8217;~/public_html&#8217;</td>
<td>镜像网站(使用压缩和加密)</td>
</tr>
<tr>
<td></td>
<td>rsync -auz -e ssh remote:/dir/ <strong>.</strong> &amp;&amp; rsync -auz -e ssh <strong>.</strong> remote:/dir/</td>
<td>同步当前目录和远程目录</td>
</tr>
<tr id="ssh">
<td colspan="3"><strong>ssh</strong> (安全 Shell)</td>
</tr>
<tr>
<td></td>
<td>ssh $USER@$HOST command</td>
<td>在$Host主机上以$User用户运行命令(默认命令为Shell)</td>
</tr>
<tr>
<td>•</td>
<td>ssh -f -Y $USER@$HOSTNAME xeyes</td>
<td>在名为$HOSTNAME的主机上以$USER用户运行GUI命令</td>
</tr>
<tr>
<td></td>
<td>scp -p -r $USER@$HOST: file dir/</td>
<td>拷贝到$HOST主机$USER&#8217;用户的目录下</td>
</tr>
<tr>
<td></td>
<td>ssh -g -L 8080:localhost:80 root@$HOST</td>
<td>由本地主机的8080端口转发到$HOST主机的80端口</td>
</tr>
<tr>
<td></td>
<td>ssh -R 1434:imap:143 root@$HOST</td>
<td>由主机的1434端口转发到imap的143端口</td>
</tr>
<tr id="wget">
<td colspan="3">wget (多用途下载工具)</td>
</tr>
<tr>
<td>•</td>
<td>(cd cmdline &amp;&amp; wget -nd -pHEKk http://www.pixelbeat.org/cmdline.html)</td>
<td>在当前目录中下载指定网页及其相关的文件使其可完全浏览</td>
</tr>
<tr>
<td></td>
<td>wget -c http://www.example.com/large.file</td>
<td>继续上次未完的下载</td>
</tr>
<tr>
<td></td>
<td>wget -r -nd -np -l1 -A &#8216;*.jpg&#8217; http://www.example.com/</td>
<td>批量下载文件到当前目录中</td>
</tr>
<tr>
<td></td>
<td>wget ftp://remote/file[1-9].iso/</td>
<td>下载FTP站上的整个目录</td>
</tr>
<tr>
<td>•</td>
<td>wget -q -O- http://www.pixelbeat.org/timeline.html | grep &#8216;a href&#8217; | head</td>
<td>直接处理输出</td>
</tr>
<tr>
<td></td>
<td>echo &#8216;wget url&#8217; | at 01:00</td>
<td>在下午一点钟下载指定文件到当前目录</td>
</tr>
<tr>
<td></td>
<td>wget &#8211;limit-rate=20k url</td>
<td>限制下载速度(这里限制到20<a href="http://www.pixelbeat.org/speeds.html">KB/s</a>)</td>
</tr>
<tr>
<td></td>
<td>wget -nv &#8211;spider &#8211;force-html -i bookmarks.html</td>
<td>检查文件中的链接是否存在</td>
</tr>
<tr>
<td></td>
<td>wget &#8211;mirror http://www.example.com/</td>
<td>更新网站的本地拷贝(可以方便地用于cron)</td>
</tr>
<tr id="net">
<td colspan="3">网络(ifconfig, route, mii-tool, nslookup 命令皆已过时)</td>
</tr>
<tr>
<td></td>
<td><acronym title="usually in /sbin/">ethtool</acronym> eth0</td>
<td>显示网卡eth0的状态</td>
</tr>
<tr>
<td></td>
<td>ethtool &#8211;change eth0 autoneg off speed 100 duplex full</td>
<td>手动设制网卡速度</td>
</tr>
<tr>
<td></td>
<td><acronym title="usually in /sbin/">iwconfig</acronym> eth1</td>
<td>显示无线网卡eth1的状态</td>
</tr>
<tr>
<td></td>
<td>iwconfig eth1 rate 1Mb/s fixed</td>
<td>手动设制无线网卡速度</td>
</tr>
<tr>
<td>•</td>
<td><acronym title="usually in /sbin/">iwlist</acronym> scan</td>
<td>显示无线网络列表</td>
</tr>
<tr>
<td>•</td>
<td><acronym title="通常在目录/sbin/中">ip</acronym> link show</td>
<td>显示interface列表</td>
</tr>
<tr>
<td></td>
<td>ip link set dev eth0 name wan</td>
<td>重命名eth0为wan</td>
</tr>
<tr>
<td></td>
<td>ip link set dev eth0 up</td>
<td>启动interface eth0(或关闭)</td>
</tr>
<tr>
<td>•</td>
<td>ip addr show</td>
<td>显示网卡的IP地址</td>
</tr>
<tr>
<td></td>
<td>ip addr add 1.2.3.4/24 brd + dev eth0</td>
<td>添加ip和掩码(255.255.255.0)</td>
</tr>
<tr>
<td>•</td>
<td>ip route show</td>
<td>显示路由列表</td>
</tr>
<tr>
<td></td>
<td>ip route add default via 1.2.3.254</td>
<td>设置默认网关1.2.3.254</td>
</tr>
<tr>
<td>•</td>
<td><acronym title="通常在目录/sbin/下">tc</acronym> qdisc add dev lo root handle 1:0 netem delay 20msec</td>
<td>增加20ms传输时间到loopback设备(调试用)</td>
</tr>
<tr>
<td>•</td>
<td>tc qdisc del dev lo root</td>
<td>移除上面添加的传输时间</td>
</tr>
<tr>
<td>•</td>
<td>host pixelbeat.org</td>
<td>查寻主机的DNS IP地址</td>
</tr>
<tr>
<td>•</td>
<td>hostname -i</td>
<td>查寻本地主机的IP地址(同等于host `hostname`)</td>
</tr>
<tr>
<td>•</td>
<td>whois pixelbeat.org</td>
<td>查寻某主机或莫IP地址的whois信息</td>
</tr>
<tr>
<td>•</td>
<td>netstat -tupl</td>
<td>列出系统中的internet服务</td>
</tr>
<tr>
<td>•</td>
<td>netstat -tup</td>
<td>列出活跃的连接</td>
</tr>
<tr id="windows">
<td colspan="3">windows networking (samba提供所有windows相关的网络支持)</td>
</tr>
<tr>
<td>•</td>
<td>smbtree</td>
<td>寻找一个windows主机. 参见findsmb</td>
</tr>
<tr>
<td></td>
<td>nmblookup -A 1.2.3.4</td>
<td>寻找一个指定ip的windows (netbios)名</td>
</tr>
<tr>
<td></td>
<td>smbclient -L windows_box</td>
<td>显示在windows主机或samba服务器上的所有共享</td>
</tr>
<tr>
<td></td>
<td>mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/share</td>
<td>挂载一个windows共享</td>
</tr>
<tr>
<td></td>
<td>echo &#8216;message&#8217; | smbclient -M windows_box</td>
<td>发送一个弹出信息到windows主机(XP sp2默认关闭此功能)</td>
</tr>
<tr id="text">
<td colspan="3">文本操作 (sed使用标准输入和标准输出，如果想要编辑文件，则需添加<em>&lt;oldfile &gt;newfile</em>)</td>
</tr>
<tr>
<td></td>
<td>sed &#8216;s/string1/string2/g&#8217;</td>
<td>使用string2替换string1</td>
</tr>
<tr>
<td></td>
<td>sed &#8216;s/\(.*\)1/\12/g&#8217;</td>
<td>将任何以1结尾的字符串替换为以2结尾的字符串</td>
</tr>
<tr>
<td></td>
<td>sed &#8216;/ *#/d; /^ *$/d&#8217;</td>
<td>删除注释和空白行</td>
</tr>
<tr>
<td></td>
<td>sed &#8216;:a; /\\$/N; s/\\\n//; ta&#8217;</td>
<td>连接结尾有\的行和其下一行</td>
</tr>
<tr>
<td></td>
<td>sed &#8216;s/[ \t]*$//&#8217;</td>
<td>删除每行后的空白</td>
</tr>
<tr>
<td></td>
<td>sed &#8216;s/\([\\`\\"$\\\\]\)/\\\1/g&#8217;</td>
<td>将所有转义字符之前加上\</td>
</tr>
<tr>
<td>•</td>
<td>seq 10 | sed “s/^/      /; s/ *\(.\{7,\}\)/\1/”</td>
<td>向右排N(任意数)列</td>
</tr>
<tr>
<td></td>
<td>sed -n &#8217;1000p;<acronym title="quit ASAP">1000q</acronym>&#8216;</td>
<td>输出第一千行</td>
</tr>
<tr>
<td></td>
<td>sed -n &#8217;10,20p;<acronym title="quit ASAP">20q</acronym>&#8216;</td>
<td>输出第10-20行</td>
</tr>
<tr>
<td></td>
<td>sed -n &#8216;s/.*&lt;title&gt;\(.*\)&lt;\/title&gt;.*/\1/ip;<acronym title="quit after match">T;q</acronym>&#8216;</td>
<td>输出HTML文件的&lt;title&gt;&lt;/title&gt;字段中的 内容</td>
</tr>
<tr>
<td></td>
<td>sort -t. -k1,1n -k2,2n -k3,3n -k4,4n</td>
<td>排序IPV4地址</td>
</tr>
<tr>
<td>•</td>
<td>echo &#8216;Test&#8217; | tr &#8216;[:lower:]&#8216; &#8216;[:upper:]&#8216;</td>
<td>转换成大写</td>
</tr>
<tr>
<td>•</td>
<td>tr -dc &#8216;[:print:]&#8216; &lt; /dev/urandom</td>
<td>过滤掉不能打印的字符</td>
</tr>
<tr>
<td>•</td>
<td>history | wc -l</td>
<td>计算指定单词出现的次数</td>
</tr>
<tr id="sets">
<td colspan="3">集合操作 (如果是英文文本的话<a href="http://www.pixelbeat.org/docs/env.html">export LANG=C</a>可以提高速度)</td>
</tr>
<tr>
<td></td>
<td>sort file1 file2 | uniq</td>
<td>两个未排序文件的<acronym title="在file1或file2中">并集</acronym></td>
</tr>
<tr>
<td></td>
<td>sort file1 file2 | uniq -d</td>
<td>两个未排序文件的<acronym title="在file1和file2中">交集</acronym></td>
</tr>
<tr>
<td></td>
<td>sort file1 file1 file2 | uniq -u</td>
<td>两个未排序文件的<acronym title="在file2中但不在file1中">差 集</acronym></td>
</tr>
<tr>
<td></td>
<td>sort file1 file2 | uniq -u</td>
<td>两个未排序文件的<acronym title="只在一个文件中">对称差集</acronym></td>
</tr>
<tr>
<td></td>
<td>join <acronym title="process whole line (assuming no NUL characters present)">-t&#8217;\0&#8242;</acronym> -a1 -a2 file1 file2</td>
<td>两个有序文件的并集</td>
</tr>
<tr>
<td></td>
<td>join -t&#8217;\0&#8242; file1 file2</td>
<td>两个有序文件的交集</td>
</tr>
<tr>
<td></td>
<td>join -t&#8217;\0&#8242; -v2 file1 file2</td>
<td>两个有序文件的差集</td>
</tr>
<tr>
<td></td>
<td>join -t&#8217;\0&#8242; -v1 -v2 file1 file2</td>
<td>两个有序文件的对称差集</td>
</tr>
<tr id="math">
<td colspan="3">数学</td>
</tr>
<tr>
<td>•</td>
<td>echo &#8216;(1 + sqrt(5))/2&#8242; | bc -l</td>
<td>方便的计算器(计算 φ)</td>
</tr>
<tr>
<td>•</td>
<td>echo &#8216;pad=20; min=64; (100*10^6)/((pad+min)*8)&#8217; | bc</td>
<td>更复杂地计算，这里计算了最大的FastE包率</td>
</tr>
<tr>
<td>•</td>
<td>echo &#8216;pad=20; min=64; print (100E6)/((pad+min)*8)&#8217; | python</td>
<td>Python处理数值的科学表示法</td>
</tr>
<tr>
<td>•</td>
<td>echo &#8216;pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)&#8217; | gnuplot -persist</td>
<td>显示FastE包率相对于包大小的图形</td>
</tr>
<tr>
<td>•</td>
<td>echo &#8216;obase=16; ibase=10; 64206&#8242; | bc</td>
<td>进制转换(十进制到十六进制)</td>
</tr>
<tr>
<td>•</td>
<td>echo $((0x2dec))</td>
<td>进制转换(十六进制到十进制)((shell数学扩展))</td>
</tr>
<tr>
<td>•</td>
<td>units -t &#8217;100m/<a href="http://www.pixelbeat.org/misc/usain_bolt.html">9.58s</a>&#8216; &#8216;miles/hour&#8217;</td>
<td>单位转换(公尺到英尺)</td>
</tr>
<tr>
<td>•</td>
<td>units -t &#8217;500GB&#8217; &#8216;GiB&#8217;</td>
<td>单位转换(<acronym title="powers of 10">SI</acronym> 到<acronym title="powers of 2">IEC</acronym> 前缀)</td>
</tr>
<tr>
<td>•</td>
<td>units -t &#8217;1 googol&#8217;</td>
<td>定义查找</td>
</tr>
<tr>
<td>•</td>
<td>seq 100 | (tr &#8216;\n&#8217; +; echo 0) | bc</td>
<td>加N(任意数)列. 参见 <a href="http://www.pixelbeat.org/scripts/add">add</a> and <a href="http://www.pixelbeat.org/scripts/funcpy">funcpy</a></td>
</tr>
<tr id="dates">
<td colspan="3">日历</td>
</tr>
<tr>
<td>•</td>
<td>cal -3</td>
<td>显示一日历</td>
</tr>
<tr>
<td>•</td>
<td>cal 9 1752</td>
<td>显示指定月，年的日历</td>
</tr>
<tr>
<td>•</td>
<td>date -d fri</td>
<td>这个星期五是几号. 参见<a href="http://www.pixelbeat.org/scripts/day">day</a></td>
</tr>
<tr>
<td>•</td>
<td>date &#8211;date=&#8217;25 Dec&#8217; +%A</td>
<td>今年的圣诞节是星期几</td>
</tr>
<tr>
<td>•</td>
<td>date &#8211;date &#8217;1970-01-01 UTC 2147483647 seconds&#8217;</td>
<td>将一相对于1970-01-01 00：00的秒数转换成时间</td>
</tr>
<tr>
<td>•</td>
<td>TZ=&#8217;:America/Los_Angeles&#8217; date</td>
<td>显示当前的美国西岸时间(使用tzselect寻找时区)</td>
</tr>
<tr>
<td></td>
<td>echo “mail -s &#8216;get the train&#8217; P@draigBrady.com &lt; /dev/null” | at 17:45</td>
<td>在指定的时间发送邮件</td>
</tr>
<tr>
<td>•</td>
<td>echo “DISPLAY=$DISPLAY xmessage cooker” | at “NOW + 30 minutes”</td>
<td>在给定的时间弹出对话框</td>
</tr>
<tr id="locale">
<td colspan="3">locales</td>
</tr>
<tr>
<td>•</td>
<td>printf “%&#8217;d\n” 1234</td>
<td>根据locale输出正确的数字分隔</td>
</tr>
<tr>
<td>•</td>
<td>BLOCK_SIZE=\&#8217;1 ls -l</td>
<td>用ls命令作类适于locale()文件分组</td>
</tr>
<tr>
<td>•</td>
<td>echo “I live in `locale territory`”</td>
<td>从locale数据库中展开信息</td>
</tr>
<tr>
<td>•</td>
<td>LANG=en_IE.utf8 locale int_prefix</td>
<td>查找指定地区的locale信息。参见<a href="http://www.pixelbeat.org/scripts/ccodes">ccodes</a></td>
</tr>
<tr>
<td>•</td>
<td>locale | cut -d= -f1 | xargs locale -kc | less</td>
<td>显示在locale数据库中的所有字段</td>
</tr>
<tr id="recode">
<td colspan="3">recode (iconv, dos2unix, unix2dos 已经过时了)</td>
</tr>
<tr>
<td>•</td>
<td>recode -l | less</td>
<td>显示所有有效的字符集及其别名</td>
</tr>
<tr>
<td></td>
<td>recode windows-1252.. file_to_change.txt</td>
<td>转换Windows下的ansi文件到当前的字符集(自动进行回车换行符的转换)</td>
</tr>
<tr>
<td></td>
<td>recode utf-8/CRLF.. file_to_change.txt</td>
<td>转换Windows下的ansi文件到当前的字符集</td>
</tr>
<tr>
<td></td>
<td>recode iso-8859-15..utf8 file_to_change.txt</td>
<td>转换Latin9（西欧）字符集文件到utf8</td>
</tr>
<tr>
<td></td>
<td>recode ../b64 &lt; file.txt &gt; file.b64</td>
<td>Base64编码</td>
</tr>
<tr>
<td></td>
<td>recode /qp.. &lt; file.txt &gt; file.qp</td>
<td>Quoted-printable格式解码</td>
</tr>
<tr>
<td></td>
<td>recode ..HTML &lt; file.txt &gt; file.html</td>
<td>将文本文件转换成HTML</td>
</tr>
<tr>
<td>•</td>
<td>recode -lf windows-1252 | grep euro</td>
<td>在<a href="http://www.pixelbeat.org/docs/utf8.html">字符表</a>中查找欧元符号</td>
</tr>
<tr>
<td>•</td>
<td>echo -n 0&#215;80 | recode latin-9/x1..dump</td>
<td>显示字符在latin-9中的字符映射</td>
</tr>
<tr>
<td>•</td>
<td>echo -n 0x20AC | recode ucs-2/x2..latin-9/x</td>
<td>显示latin-9编码</td>
</tr>
<tr>
<td>•</td>
<td>echo -n 0x20AC | recode ucs-2/x2..utf-8/x</td>
<td>显示utf-8编码</td>
</tr>
<tr id="CDs">
<td colspan="3">光盘</td>
</tr>
<tr>
<td></td>
<td>gzip &lt; /dev/cdrom &gt; cdrom.iso.gz</td>
<td>保存光盘拷贝</td>
</tr>
<tr>
<td></td>
<td>mkisofs -V LABEL -r dir | gzip &gt; cdrom.iso.gz</td>
<td>建立目录dir的光盘镜像</td>
</tr>
<tr>
<td></td>
<td>mount -o loop cdrom.iso /mnt/dir</td>
<td>将光盘镜像挂载到 /mnt/dir (只读)</td>
</tr>
<tr>
<td></td>
<td>cdrecord -v dev=/dev/cdrom blank=fast</td>
<td>清空一张CDRW</td>
</tr>
<tr>
<td></td>
<td>gzip -dc cdrom.iso.gz | cdrecord -v dev=/dev/cdrom -</td>
<td>烧录光盘镜像 (使用 dev=ATAPI -scanbus 来确认该使用的 dev)</td>
</tr>
<tr>
<td></td>
<td>cdparanoia -B</td>
<td>在当前目录下将光盘音轨转录成wav文件</td>
</tr>
<tr>
<td></td>
<td>cdrecord -v dev=/dev/cdrom -audio *.wav</td>
<td>将当前目录下的wav文件烧成音乐光盘 (参见cdrdao)</td>
</tr>
<tr>
<td></td>
<td>oggenc &#8211;tracknum=&#8217;track&#8217; track.cdda.wav -o &#8216;track.ogg&#8217;</td>
<td>将wav文件转换成ogg格式</td>
</tr>
<tr id="disk_space">
<td colspan="3">磁盘空间 (参见<a href="http://www.pixelbeat.org/fslint/">FSlint</a>)</td>
</tr>
<tr>
<td>•</td>
<td>ls -lSr</td>
<td>按文件大小降序显示文件</td>
</tr>
<tr>
<td>•</td>
<td>du -s * | sort -k1,1rn | head</td>
<td>显示当前目录下占用空间最大的一批文件. 参见<a href="http://www.pixelbeat.org/scripts/dutop">dutop</a></td>
</tr>
<tr>
<td>•</td>
<td>df -h</td>
<td>显示空余的磁盘空间</td>
</tr>
<tr>
<td>•</td>
<td>df -i</td>
<td>显示空余的inode</td>
</tr>
<tr>
<td>•</td>
<td><acronym title="通常在目录/sbin/中">fdisk</acronym> -l</td>
<td>显示磁盘分区大小和类型（在root下执行）</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/docs/packaging.html">rpm</a> -q -a &#8211;qf &#8216;%10{SIZE}\t%{NAME}\n&#8217; | sort -k1,1n</td>
<td>显示所有在rpm发布版上安装的<a href="http://www.pixelbeat.org/docs/packaging.html">包</a>，并以包字节大小为序</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/docs/packaging.html">dpkg</a>-query -W -f=&#8217;${Installed-Size;10}\t${Package}\n&#8217; | sort -k1,1n</td>
<td>显示所有在deb发布版上安装的<a href="http://www.pixelbeat.org/docs/packaging.html">包</a>，并以KB包大小为序</td>
</tr>
<tr>
<td>•</td>
<td>dd bs=1 seek=2TB if=/dev/null of=ext3.test</td>
<td>建立一个大的测试文件（不占用空间）. 参见<a href="http://www.pixelbeat.org/scripts/truncate">truncate</a></td>
</tr>
<tr id="monitor">
<td colspan="3">监视/调试</td>
</tr>
<tr>
<td>•</td>
<td>tail -f /var/log/messages</td>
<td><a href="http://www.pixelbeat.org/docs/web/access_log/monitoring.html">监视Messages</a>日志文件</td>
</tr>
<tr>
<td>•</td>
<td>strace -c ls &gt;/dev/null</td>
<td>总结/剖析命令进行的系统调用</td>
</tr>
<tr>
<td>•</td>
<td>strace -f -e open ls &gt;/dev/null</td>
<td>显示命令进行的系统调用</td>
</tr>
<tr>
<td>•</td>
<td>ltrace -f -e getenv ls &gt;/dev/null</td>
<td>显示命令调用的库函数</td>
</tr>
<tr>
<td>•</td>
<td><acronym title="通常在目录/usr/sbin/中">lsof</acronym> -p <acronym title="process id of current shell">$$</acronym></td>
<td>显示当前进程打开的文件</td>
</tr>
<tr>
<td>•</td>
<td>lsof ~</td>
<td>显示打开用户目录的进程</td>
</tr>
<tr>
<td>•</td>
<td>tcpdump not port 22</td>
<td>显示除了ssh外的网络交通. 参见<a href="http://www.pixelbeat.org/scripts/tcpdump_not_me">tcpdump_not_me</a></td>
</tr>
<tr>
<td>•</td>
<td>ps -e -o pid,args &#8211;forest</td>
<td>以树状结构显示进程</td>
</tr>
<tr>
<td>•</td>
<td>ps -e -o pcpu,cpu,nice,state,cputime,args &#8211;sort pcpu | sed &#8216;/^ 0.0 /d&#8217;</td>
<td>以CPU占用率为序显示进程</td>
</tr>
<tr>
<td>•</td>
<td>ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS</td>
<td>以内存使用量为序显示进程. 参见<a href="http://www.pixelbeat.org/scripts/ps_mem.py">ps_mem.py</a></td>
</tr>
<tr>
<td>•</td>
<td>ps -C firefox-bin -L -o pid,tid,pcpu,state</td>
<td>显示指定进程的所有线程信息</td>
</tr>
<tr>
<td>•</td>
<td>ps -p 1,2</td>
<td>显示指定进程ID的进程信息</td>
</tr>
<tr>
<td>•</td>
<td>last reboot</td>
<td>显示系统重启记录</td>
</tr>
<tr>
<td>•</td>
<td>free -m</td>
<td>显示(剩余的)内存总量(-m以MB为单位显示)</td>
</tr>
<tr>
<td>•</td>
<td>watch -n.1 &#8216;cat /proc/interrupts&#8217;</td>
<td>监测文件/proc/interrupts的变化</td>
</tr>
<tr id="sysinfo">
<td colspan="3">系统信息 (参见<a href="http://www.pixelbeat.org/scripts/sysinfo">sysinfo</a>)</td>
</tr>
<tr>
<td>•</td>
<td>uname -a</td>
<td>查看内核/操作系统/CPU信息</td>
</tr>
<tr>
<td>•</td>
<td>head -n1 /etc/issue</td>
<td>查看操作系统版本</td>
</tr>
<tr>
<td>•</td>
<td>cat /proc/partitions</td>
<td>显示所有在系统中注册的分区</td>
</tr>
<tr>
<td>•</td>
<td>grep MemTotal /proc/meminfo</td>
<td>显示系统可见的内存总量</td>
</tr>
<tr>
<td>•</td>
<td>grep “model name” /proc/cpuinfo</td>
<td>显示CPU信息</td>
</tr>
<tr>
<td>•</td>
<td><acronym title="通常在目录/sbin/中">lspci</acronym> -tv</td>
<td>显示PCI信息</td>
</tr>
<tr>
<td>•</td>
<td><acronym title="通常在目录/sbin/中">lsusb</acronym> -tv</td>
<td>显示USB信息</td>
</tr>
<tr>
<td>•</td>
<td>mount | column -t</td>
<td>显示所有挂载的文件系统并对齐输出</td>
</tr>
<tr>
<td>#</td>
<td>dmidecode -q | less</td>
<td>显示SMBIOS/DMI 信息</td>
</tr>
<tr>
<td>#</td>
<td>smartctl -A /dev/sda | grep Power_On_Hours</td>
<td>系统开机的总体时间</td>
</tr>
<tr>
<td>#</td>
<td>hdparm -i /dev/sda</td>
<td>显示关于磁盘sda的信息</td>
</tr>
<tr>
<td>#</td>
<td>hdparm -tT /dev/sda</td>
<td>检测磁盘sda的读取速度</td>
</tr>
<tr>
<td>#</td>
<td>badblocks -s /dev/sda</td>
<td>检测磁盘sda上所有的坏扇区</td>
</tr>
<tr id="interactive">
<td colspan="3">交互 (参见<a href="http://www.pixelbeat.org/lkdb/">linux keyboard shortcut database</a>)</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/lkdb/readline.html">readline</a></td>
<td>Line editor used by bash, python, bc, gnuplot, &#8230;</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/lkdb/screen.html">screen</a></td>
<td>多窗口的虚拟终端, &#8230;</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/lkdb/mc.html">mc</a></td>
<td>强大的文件管理器，可以浏览rpm, tar, ftp, ssh, &#8230;</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/docs/web/access_log/analyzing.html">gnuplot</a></td>
<td>交互式并可进行脚本编程的画图工具</td>
</tr>
<tr>
<td>•</td>
<td>links</td>
<td>网页浏览器</td>
</tr>
<tr id="misc">
<td colspan="3">miscellaneous</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/settings/.bashrc">alias</a> hd=&#8217;od -Ax -tx1z -v&#8217;</td>
<td>方便的十六进制输出。 (用法举例: • hd /proc/self/cmdline | less)</td>
</tr>
<tr>
<td>•</td>
<td><a href="http://www.pixelbeat.org/settings/.bashrc">alias</a> realpath=&#8217;readlink -f&#8217;</td>
<td>显示符号链接指向的真实路径((用法举例: • realpath ~/../$USER)</td>
</tr>
<tr>
<td>•</td>
<td>set | grep $USER</td>
<td>在当前<a href="http://www.pixelbeat.org/docs/env.html">环境</a>中查找</td>
</tr>
<tr>
<td></td>
<td>touch -c -t 0304050607 file</td>
<td>改变文件的时间标签 (YYMMDDhhmm)</td>
</tr>
<tr>
<td>•</td>
<td>python -m SimpleHTTPServer</td>
<td>Serve current directory tree at http://$HOSTNAME:8000/</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/05/14/329.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux(centos)下如何安装Splunk日志分析系统</title>
		<link>http://www.phpwebgo.com/2012/05/14/318.html</link>
		<comments>http://www.phpwebgo.com/2012/05/14/318.html#comments</comments>
		<pubDate>Mon, 14 May 2012 10:00:16 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>
		<category><![CDATA[PHP编程]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=318</guid>
		<description><![CDATA[一、splunk简介： Splunk 是一个可运行于各种平台的 IT 数据、日志分析软件，支持的作业平台包含Windows, Linux, Solaris, FreeBSD, AIX, MacOS, HP-UX。与 Google Analytics 这一类的 Web 日志分析软件的不同之处在于，Splunk 可以支持任何 IT 设备(服务器、网络设备、应用程序、数据库等)所产生的日志，其对日志进行处理的方式是进行高效索引之后让管理员可以对日志中出现的各种情况进行搜索，并且通过非常好的图形化的方式展现出来。 free版的有功能限制，每天不能超过500MB的数据 二、splunk如何安装： 到官方http://www.splunk.com/download注册一个账号选择对应的操作系统版本（可以通过#getconf LONG_BIT命令查看是32位还是64位） tar zxvf splunk-4.3.2-123586-Linux-i686.tgz mkdir /usr/local/splunk cp splunk/* /usr/local/splunk cd /usr/local/splunk/bin ./splunk start 然后会看到一些输出信息，接着按enter键，会出现以下信息 Do you agree with this license? [y/n]: 直接同意按y即可 netstat -ant Proto Recv-Q Send-Q Local Address               Foreign Address             State tcp        [...]]]></description>
			<content:encoded><![CDATA[<p>一、splunk简介：</p>
<p>Splunk 是一个可运行于各种平台的 IT 数据、日志分析软件，支持的作业平台包含Windows, Linux, Solaris, FreeBSD, AIX, MacOS, HP-UX。与 Google Analytics 这一类的 Web 日志分析软件的不同之处在于，Splunk 可以支持任何 IT 设备(服务器、网络设备、应用程序、数据库等)所产生的日志，其对日志进行处理的方式是进行高效索引之后让管理员可以对日志中出现的各种情况进行搜索，并且通过非常好的图形化的方式展现出来。</p>
<p>free版的有功能限制，每天不能超过500MB的数据</p>
<p>二、splunk如何安装：</p>
<p>到官方http://www.splunk.com/download注册一个账号选择对应的操作系统版本（可以通过#getconf LONG_BIT命令查看是32位还是64位）</p>
<pre class="brush: bash; gutter: true">tar zxvf splunk-4.3.2-123586-Linux-i686.tgz
mkdir /usr/local/splunk
cp splunk/* /usr/local/splunk
cd /usr/local/splunk/bin
./splunk start</pre>
<p>然后会看到一些输出信息，接着按enter键，会出现以下信息<br />
Do you agree with this license? [y/n]:<br />
直接同意按y即可</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_0.jpg"><img class="alignnone size-large wp-image-325" title="20120514174715_0" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_0-1024x996.jpg" alt="" width="1024" height="996" /></a></p>
<p>netstat -ant<br />
Proto Recv-Q Send-Q Local Address               Foreign Address             State<br />
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN<br />
tcp        0      0 0.0.0.0:8089                0.0.0.0:*                   LISTEN<br />
看到以上信息即可通过http://localhost:8000访问</p>
<p>设置开机自动启动<br />
ln -s /usr/local/splunk/bin/splunk /etc/rc2.d/S80splunk<br />
放到服务里面<br />
ln -s /usr/local/splunk/bin/splunk /etc/init.d/splunk</p>
<p>三、设置日志分析目录</p>
<p>进入http://localhost:8000，第一次需要重设密码</p>
<p>然后点击添加数据</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_1.jpg"><img class="alignnone size-full wp-image-319" title="20120514174715_1" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_1.jpg" alt="" width="923" height="396" /></a></p>
<p>选择数据源&#8212;&gt;从文件和目录</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_2.jpg"><img class="alignnone size-full wp-image-320" title="20120514174715_2" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_2.jpg" alt="" width="927" height="548" /></a></p>
<p>选择/var/log即可</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_3.jpg"><img class="alignnone size-full wp-image-321" title="20120514174715_3" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_3.jpg" alt="" width="923" height="467" /></a></p>
<p>点击头部应用菜单下面的search即可看到生成的日志报告(比如cron日志，yum日志，mail日志，boot日志；当然我们也可以把我们所需要记录的比如php错误日志等都输出到/var/log目录下即可对其进行分析)</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_4.jpg"><img class="alignnone size-full wp-image-322" title="20120514174715_4" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/20120514174715_4.jpg" alt="" width="902" height="589" /></a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/05/14/318.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux（centos）更改系统时间为中国上海时间</title>
		<link>http://www.phpwebgo.com/2012/05/14/316.html</link>
		<comments>http://www.phpwebgo.com/2012/05/14/316.html#comments</comments>
		<pubDate>Mon, 14 May 2012 09:22:44 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[PHP编程]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=316</guid>
		<description><![CDATA[#date #date -R 运行以上命令查看当前系统时间以及时区 如何设置： 一、将我们的时区文件复制到系统位置，把当前时区调整为上海 就是东八区(+8区) cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 二、利用ntpdate同步标准时间(如果 ntpdate 无法运行，那么需要 yum install -y ntpdate 安装一下服务) ntpdate us.pool.ntp.org 三、定时同步 vim /etc/crontab */10 * * * * root /usr/sbin/ntpdate us.pool.ntp.org &#124; logger -t NTP /etc/rc.d/init.d/crond restart]]></description>
			<content:encoded><![CDATA[<p>#date<br />
#date -R</p>
<p>运行以上命令查看当前系统时间以及时区</p>
<p>如何设置：<br />
一、将我们的时区文件复制到系统位置，把当前时区调整为上海 就是东八区(+8区)<br />
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime<br />
二、利用ntpdate同步标准时间(如果 ntpdate 无法运行，那么需要 yum install -y ntpdate 安装一下服务)<br />
ntpdate us.pool.ntp.org<br />
三、定时同步</p>
<pre class="brush: bash; gutter: true">vim /etc/crontab
*/10 * * * * root /usr/sbin/ntpdate us.pool.ntp.org | logger -t NTP
/etc/rc.d/init.d/crond restart</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/05/14/316.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux(centos)安装FastDFS分布式文件系统以及PHP对应FastDFS的client扩展</title>
		<link>http://www.phpwebgo.com/2012/05/14/298.html</link>
		<comments>http://www.phpwebgo.com/2012/05/14/298.html#comments</comments>
		<pubDate>Mon, 14 May 2012 04:29:07 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>
		<category><![CDATA[PHP编程]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=298</guid>
		<description><![CDATA[一、FastDFS简介： FastDFS是一款类Google FS的开源分布式文件系统，它用纯C语言实现，支持Linux、FreeBSD、AIX等UNIX系统。它只能通过 专有API对文件进行存取访问，不支持POSIX接口方式，不能mount使用。准确地讲，Google FS以及FastDFS、mogileFS、 HDFS、TFS等类Google FS都不是系统级的分布式文件系统，而是应用级的分布式文件存储服务。 FastDFS是一个开源的轻量级分布式文件系统，它对文件进行管理，功能包括：文件存储、文件同步、文件访问（文件上传、文件下载）等，解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务，如相册网站、视频网站等等。 二、FastDFS安装 wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz tar -zxvf FastDFS_v3.03.tar.gz cd FastDFS vim make.sh 将#WITH_HTTPD=1 修改成WITH_HTTPD=1 以支持 http ./make.sh &#38;&#38; ./make.sh install 三、FastDFS配置 1、配置及启动Tracker Server mkdir /home/fastdfs vi /etc/fdfs/tracker.conf base_path=/home/yuqing/fastdfs  修改为：base_path=/home/fastdfs ##include http.conf  修改为：#include http.conf /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf 检查tracker是否启动成功，可以查看如下文件/home/fastdfs/logs/trackerd.log &#160; 2、配置及启动Storage Server mkdir /home/fastdfs/fdfs_storage cd /etc/fdfs vim storage.conf 或者 vim /etc/fdfs/storage.conf base_path=/home/yuqing/fastdfs 修改为： /home/fastdfs/fdfs_storage store_path0=/home/yuqing/fastdfs 修改为： store_path0=/home/fastdfs/fdfs_storage tracker_server=192.168.209.121:22122 修改为 tracker_server=10.201.20.237:22122 ##include http.conf  修改为：#include http.conf &#160; /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf 接下来会出现很多mkdir data path，这是系统在创建数据目录。 3.配置PHP扩展 cd php_client phpize ./configure--with-php-config=/usr/local/php/bin/php-config make &#38;&#38; make install cat fastdfs_client.ini [...]]]></description>
			<content:encoded><![CDATA[<p>一、FastDFS简介：</p>
<p>FastDFS是一款类Google FS的开源分布式文件系统，它用纯C语言实现，支持Linux、FreeBSD、AIX等UNIX系统。它只能通过 专有API对文件进行存取访问，不支持POSIX接口方式，不能mount使用。准确地讲，Google FS以及FastDFS、mogileFS、 HDFS、TFS等类Google FS都不是系统级的分布式文件系统，而是应用级的分布式文件存储服务。</p>
<p>FastDFS是一个开源的轻量级分布式文件系统，它对文件进行管理，功能包括：文件存储、文件同步、文件访问（文件上传、文件下载）等，解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务，如相册网站、视频网站等等。</p>
<p>二、FastDFS安装</p>
<pre class="brush: bash; gutter: true">wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz

tar -zxvf FastDFS_v3.03.tar.gz
cd FastDFS
vim make.sh 将#WITH_HTTPD=1 修改成WITH_HTTPD=1 以支持 http
./make.sh &amp;&amp; ./make.sh install</pre>
<p>三、FastDFS配置</p>
<p>1、配置及启动<span style="font-family: Times New Roman;">Tracker Server</span></p>
<p>mkdir /home/fastdfs<br />
vi /etc/fdfs/tracker.conf<br />
base_path=/home/yuqing/fastdfs  修改为：base_path=/home/fastdfs<br />
##include http.conf  修改为：#include http.conf<br />
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf<br />
检查<span style="font-family: Times New Roman;">tracker</span><span style="font-family: 宋体;">是否启动成功，可以查看如下文件</span><span style="font-family: Times New Roman;">/home/fastdfs/logs/trackerd.log</span></p>
<p>&nbsp;</p>
<p>2、配置及启动<span style="font-family: Times New Roman;">Storage Server</span></p>
<p>mkdir /home/fastdfs/fdfs_storage<br />
cd /etc/fdfs<br />
vim storage.conf<br />
或者 <span style="font-family: Times New Roman;">vim /etc/fdfs/storage.conf</span></p>
<p>base_path=/home/yuqing/fastdfs 修改为： /home/fastdfs/fdfs_storage<br />
store_path0=/home/yuqing/fastdfs 修改为： store_path0=/home/fastdfs/fdfs_storage<br />
tracker_server=192.168.209.121:22122 修改为 tracker_server=10.201.20.237:22122<br />
##include http.conf  修改为：#include http.conf</p>
<p>&nbsp;</p>
<p>/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf</p>
<p>接下来会出现很多<span style="font-family: Times New Roman;">mkdir data path</span><span style="font-family: 宋体;">，这是系统在创建数据目录。</span></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/fastdfsimg.png"><img class="alignnone size-full wp-image-306" title="fastdfsimg" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/fastdfsimg.png" alt="" width="352" height="476" /></a></p>
<p>3.配置PHP扩展</p>
<pre class="brush: bash; gutter: true">cd php_client

phpize

./configure--with-php-config=/usr/local/php/bin/php-config

make &amp;&amp; make install

cat fastdfs_client.ini &gt;&gt; /usr/local/php/etc/php.ini

/usr/local/apache2/bin/apachectl restart

cp fastdfs_test.php /home/wwwroot/</pre>
<p>http://10.201.20.237/fastdfs_test.php</p>
<p>&nbsp;</p>
<p>vim /usr/local/php/etc/php.ini <span style="font-family: 宋体;">可以看到</span>fastdfs_clicet.so<span style="font-family: 宋体;">已经加载到</span><span style="font-family: Times New Roman;">php.ini</span><span style="font-family: 宋体;">中</span></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/fstdfsphpini2.jpg"><img title="fstdfsphpini2" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/fstdfsphpini2.jpg" alt="" width="554" height="399" /></a></p>
<p>查看phpinfo()</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/fastdfsphpini1.jpg"><img class="alignnone size-full wp-image-305" title="fastdfsphpini1" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/fastdfsphpini1.jpg" alt="" width="554" height="94" /></a></p>
<p>&nbsp;</p>
<p>四、测试以及使用FastDFS</p>
<p>1<span style="font-family: 宋体;">、</span><span style="font-family: Times New Roman;">FastDFS</span><span style="font-family: 宋体;">之配置</span><span style="font-family: Times New Roman;">client</span><br />
vim /etc/fdfs/client.conf<br />
base_path=/home/yuqing/fastdfs 修改为： base_path=/home/fastdfs<br />
tracker_server=192.168.209.121:22122 修改为： tracker_server=10.201.20.237:22122<br />
##include http.conf  修改为： #include http.conf</p>
<p>&nbsp;</p>
<p>2、测试上传文件</p>
<p>用法：Usage: fdfs_test &lt;config_file&gt; upload &lt;local_filename&gt; [FILE | BUFF | CALLBACK]</p>
<p>测试：</p>
<p>cd /home/wwwroot/<br />
fdfs_test /etc/fdfs/client.conf  upload  FlexPaper.zip</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/QQ20120514104544.jpg"><img class="alignnone  wp-image-299" title="QQ20120514104544" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/QQ20120514104544-1024x452.jpg" alt="" width="819" height="362" /></a></p>
<p>http://10.201.20.237:8080/group1/M00/00/00/CskU7U-c9hio4fAeACCD1c0mEbg924_big.zip</p>
<p>启动tracker<span style="font-family: 宋体;">服务</span>：</p>
<p>/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf<br />
启动<span style="font-family: Times New Roman;">storager</span><span style="font-family: 宋体;">服务</span>：</p>
<p>/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf</p>
<p>监控：</p>
<p>/usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf</p>
<p>&nbsp;</p>
<p>FastDFS架构介绍：</p>
<p>FastDFS是一款为互联网应用量身定做的类Google FS的开源应用级的分布式文件系统，它用纯C语言实现，支持Linux、FreeBSD、AIX等UNIX系统，其架构和设计理念有其独到之处，主要体现在轻量级、分组方式和对等结构三个方面：<br />
<strong>轻量级：</strong></p>
<ol>
<li>FastDFS只有两个角色：Tracker server和Storage server。Tracker server作为中心结点，其主要作用是负载均衡和调度。Tracker server在内存中记录分组和Storage server的状态等信息，不记录文件索引信息，占用的内存量很少。另外，客户端（应用）和Storage server访问Tracker server时，Tracker server扫描内存中的分组和Storage server信息，然后给出应答。由此可以看出Tracker server非常轻量化，不会成为系统瓶颈。</li>
<li>FastDFS不对文件进行分块存储，客户端上传文件时，文件ID不是由客户端指定，而是由Storage server生成后返回给客户端的。文件ID中包含了组名、文件相对路径和文件名，Storage server可以根据文件ID直接定位到文件。因此FastDFS集群中根本不需要存储文件索引信息，这是FastDFS比较轻量级的一个例证。</li>
<li>FastDFS轻量级的另外一个体现是代码量较小。最新的V2.0包括了C客户端API、FastDHT客户端API和PHP extension等，代码行数不到5.2万行。</li>
</ol>
<p><strong>分组方式：</strong></p>
<ol>
<ol>FastDFS采用了分组存储方式。集群由一个或多个组构成，集群存储总容量为集群中所有组的存储容量之和。一个组由一台或多台存储服务器组成，同组内的 多台Storage server之间是互备关系，同组存储服务器上的文件是完全一致的。文件上传、下载、删除等操作可以在组内任意一台Storage server上进行。类似木桶短板效应，一个组的存储容量为该组内存储服务器容量最小的那个，由此可见组内存储服务器的软硬件配置最好是一致的。</ol>
</ol>
<p>&nbsp;</p>
<ol>采用分组存储方式的好处是灵活、可控性较强。比如上传文件时，可以由客户端直接指定上传到的组。一个分组的存储服务器访问压力较大时，可以在该组增加存储 服务器来扩充服务能力（纵向扩容）。当系统容量不足时，可以增加组来扩充存储容量（横向扩容）。采用这样的分组存储方式，可以使用FastDFS对文件进 行管理，使用主流的Web server如Apache、nginx等进行文件下载。</ol>
<p><strong>对等结构</strong></p>
<ul>
<li>FastDFS集群中的Tracker server也可以有多台，Tracker server和Storage server均不存在单点问题。Tracker server之间是对等关系，组内的Storage server之间也是对等关系。FastDFS的架构:<a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/分布式文件系统FastDFS架构剖-285x300.gif"><img class="alignnone size-full wp-image-309" title="分布式文件系统FastDFS架构剖-285x300" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/分布式文件系统FastDFS架构剖-285x300.gif" alt="" width="285" height="300" /></a></li>
<li>从图可以看出，Tracker server之间相互独立，不存在直接联系。</li>
</ul>
<p>客户端和Storage server主动连接Tracker server。Storage server主动向Tracker server报 告其状态信息，包括磁盘剩余空间、文件同步状况、文件上传下载次数等统计信息。Storage server会连接集群中所有的 Tracker server，向他们报告自己的状态。Storage server启动一个单独的线程来完成对一台Tracker server的连接 和定时报告。需要说明的是，一个组包含的Storage server不是通过配置文件设定的，而是通过Tracker server获取到的。</p>
<p>不同组的Storage server之间不会相互通信，同组内的Storage server之间会相互连接进行文件同步。</p>
<p>Storage server采用binlog文件记录文件上传、删除等更新操作。binlog中只记录文件名，不记录文件内容。</p>
<p>文件同步只在同组内的Storage server之间进行，采用push方式，即源头服务器同步给目标服务器。只有源头数据才需要同步，备份数据 并不需要再次同步，否则就构成环路了。有个例外，就是新增加一台Storage server时，由已有的一台Storage server将已有的所有 数据（包括源头数据和备份数据）同步给该新增服务器。</p>
<p>Storage server中由专门的线程根据binlog进行文件同步。为了最大程度地避免相互影响以及出于系统简洁性考虑，Storage server对组内除自己以外的每台服务器都会启动一个线程来进行文件同步。</p>
<p>文件同步采用增量同步方式，系统记录已同步的位置（binlog文件偏移量）到标识文件中。标识文件名格式：{dest storage IP}_{port}.mark，例如：192.168.1.14_23000.mark。</p>
<p><strong>文件上传和下载的交互过程</strong></p>
<p>接下来我们一起看一下文件上传和下载的交互过程。文件上传和下载流程分别如图2、图3所示。文件上传流程的步骤如下：</p>
<div id="attachment_4382">
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/分布式文件2-300x192.gif"><img class="alignnone size-full wp-image-312" title="分布式文件2-300x192" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/分布式文件2-300x192.gif" alt="" width="300" height="192" /></a></p>
<p>图2 文件上传流程</p>
</div>
<div id="attachment_4383">
<p>图3 文件下载流程</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/分布式文件3-300x180.gif"><img class="alignnone size-full wp-image-313" title="分布式文件3-300x180" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/分布式文件3-300x180.gif" alt="" width="300" height="180" /></a></p>
</div>
<p>1. Client询问Tracker server上传到的Storage server；</p>
<p>2. Tracker server返回一台可用的Storage server，返回的数据为该Storage server的IP地址和端口；</p>
<p>3. Client直接和该Storage server建立连接，进行文件上传，Storage server返回新生成的文件ID，文件上传结束。</p>
<p>文件下载流程的步骤如下：</p>
<p>1. Client询问Tracker server可以下载指定文件的Storage server，参数为文件ID（包含组名和文件名）；</p>
<p>2. Tracker server返回一台可用的Storage server；</p>
<p>3. Client直接和该Storage server建立连接，完成文件下载。</p>
<p><strong>文件同步延迟问题的提出</strong></p>
<p>客户端将一个文件上传到一台Storage server后，文件上传工作就结束了。由该Storage server根据binlog中的上传记 录将这个文件同步到同组的其他Storage server。这样的文件同步方式是异步方式，异步方式带来了文件同步延迟的问题。新上传文件后，在尚未被 同步过去的Storage server上访问该文件，会出现找不到文件的现象。FastDFS是如何解决文件同步延迟这个问题的呢？</p>
<p>文件的访问分为两种情况：文件更新和文件下载。文件更新包括设置文件附加属性和删除文件。文件的附加属性包括文件大小、图片宽度、图片高度等。 FastDFS中，文件更新操作都会优先选择源Storage server，也就是该文件被上传到的那台Storage server。这样的做法不仅 避免了文件同步延迟的问题，而且有效地避免了在多台Storage server上更新同一文件可能引起的时序错乱的问题。</p>
<p>那么文件下载是如何解决文件同步延迟这个问题的呢？</p>
<p>要回答这个问题，需要先了解文件名中包含了什么样的信息。Storage server生成的文件名中，包含了源Storage server的 IP地址和文件创建时间等字段。文件创建时间为UNIX时间戳，后面称为文件时间戳。从文件名或文件ID中，可以反解出这两个字段。</p>
<p>然后我们再来看一下，Tracker server是如何准确地知道一个文件已被同步到一台Storage server上的。前面已经讲过，文件 同步采用主动推送的方式。另外，每台storage server都会定时向tracker server报告它向同组的其他 storage server同步到的文件时间戳。当tracker server收到一台storage server的文件同步报告后，它会依次找出 该组内各个storage server（后称作为S）被同步到的文件时间戳最小值，作为S的一个属性记录到内存中。</p>
<p><strong>FastDFS对文件同步延迟问题的解决方案</strong></p>
<p>下面我们来看一下FastDFS采取的解决方法。</p>
<p>一个最简单的解决办法，和文件更新一样，优先选择源Storage server下载文件即可。这可以在Tracker server的配置文件中设置，对应的参数名为download_server。</p>
<p>另外一种选择Storage server的方法是轮流选择（round-robin）。当Client询问Tracker server有哪些 Storage server可以下载指定文件时，Tracker server返回满足如下四个条件之一的Storage server：</p>
<ul>
<li>该文件上传到的源Storage server，文件直接上传到该服务器上的；</li>
<li>文件创建时间戳 &lt; Storage server被同步到的文件时间戳，这意味着当前文件已经被同步过来了；</li>
<li>文件创建时间戳=Storage server被同步到的文件时间戳，且（当前时间—文件创建时间戳） &gt; 一个文件同步完成需要的最大时间（如5分钟）；</li>
<li>（当前时间—文件创建时间戳） &gt; 文件同步延迟阈值，比如我们把阈值设置为1天，表示文件同步在一天内肯定可以完成。</li>
</ul>
<p>FastDFS作者余庆，现在淘宝网Java中间件团队从事Java基础平台研发工作，有10年互联网开发和架构经历，曾担任新浪网开发工程师、雅虎中国架构师。开源分布式文件系统FastDFS和分布式哈希系统FastDHT的作者，对分布式数据存储架构有比较深入的研究。</p>
<p>百度百科：http://baike.baidu.com/view/2466025.htm</p>
<p>架构参考：http://www.programmer.com.cn/4380/</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/05/14/298.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>利用Shell脚本实现自动备份VPS网站程序以及数据库数据到Dropbox</title>
		<link>http://www.phpwebgo.com/2012/05/10/274.html</link>
		<comments>http://www.phpwebgo.com/2012/05/10/274.html#comments</comments>
		<pubDate>Thu, 10 May 2012 04:23:21 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=274</guid>
		<description><![CDATA[&#160; 1.注册DropBox，https://www.dropbox.com/，DropBox百度百科：http://baike.baidu.com/view/2998059.htm 2.shell脚本: vim DropboxBackup.sh #!/bin/bash DROPBOX_USER=&#34;xxx@gmail.com&#34; #Dropbox的账号 DROPBOX_PASS=&#34;xxxxxx&#34; #Dropbox的密码 DROPBOX_DIR=&#34;/backups&#34; #Dropbox中的文件夹名称 BACKUP_SRC=&#34;/home/wwwroot/www.phpwebgo.com /home/wwwroot/blog.phpwebgo.com&#34; #需要备份的文件夹路径，可以同时指定多个 BACKUP_DST=&#34;/home/backup&#34; #用来存放备份的文件夹路径 MYSQL_SERVER=&#34;localhost&#34; #连接本地MySQL MYSQL_USER=&#34;root&#34; #本地MySQL的用户 MYSQL_PASS=&#34;xxxxxx&#34; #本地MySQL的密码 # # Stop editing here. NOW=$(date +&#34;%Y.%m.%d&#34;) DESTFILE=&#34;$BACKUP_DST/$NOW.tgz&#34; # # Upload a file to Dropbox. # = Source file # = Destination file. function dropboxUpload { # # Code based on DropBox [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>1.注册DropBox，https://www.dropbox.com/，DropBox百度百科：http://baike.baidu.com/view/2998059.htm</p>
<p>2.shell脚本:</p>
<p>vim DropboxBackup.sh</p>
<pre class="brush: bash; gutter: true">#!/bin/bash
DROPBOX_USER=&quot;xxx@gmail.com&quot; #Dropbox的账号
DROPBOX_PASS=&quot;xxxxxx&quot; #Dropbox的密码
DROPBOX_DIR=&quot;/backups&quot; #Dropbox中的文件夹名称
BACKUP_SRC=&quot;/home/wwwroot/www.phpwebgo.com /home/wwwroot/blog.phpwebgo.com&quot; #需要备份的文件夹路径，可以同时指定多个
BACKUP_DST=&quot;/home/backup&quot; #用来存放备份的文件夹路径
MYSQL_SERVER=&quot;localhost&quot; #连接本地MySQL
MYSQL_USER=&quot;root&quot; #本地MySQL的用户
MYSQL_PASS=&quot;xxxxxx&quot; #本地MySQL的密码

#
# Stop editing here.
NOW=$(date +&quot;%Y.%m.%d&quot;)
DESTFILE=&quot;$BACKUP_DST/$NOW.tgz&quot;

#
# Upload a file to Dropbox.
#  = Source file
#  = Destination file.
function dropboxUpload
{
#
# Code based on DropBox Uploader 0.6 from http://www.andreafabrizi.it/?dropbox_uploader
	LOGIN_URL=&quot;https://www.dropbox.com/login&quot;
		HOME_URL=&quot;https://www.dropbox.com/home&quot;
		UPLOAD_URL=&quot;https://dl-web.dropbox.com/upload&quot;
		COOKIE_FILE=&quot;/tmp/du_cookie_$RANDOM&quot;
		RESPONSE_FILE=&quot;/tmp/du_resp_$RANDOM&quot;

		UPLOAD_FILE=
		DEST_FOLDER=

# Login
		echo -ne &quot; &gt; Logging in...&quot;
		curl -s -i -c $COOKIE_FILE -o $RESPONSE_FILE --data &quot;login_email=$DROPBOX_USER&amp;login_password=$DROPBOX_PASS&amp;t=$TOKEN&quot; &quot;$LOGIN_URL&quot;
		grep &quot;location: /home&quot; $RESPONSE_FILE &gt; /dev/null

		if [ $? -ne 0 ]; then
			echo -e &quot; Failed!&quot;
				rm -f &quot;$COOKIE_FILE&quot; &quot;$RESPONSE_FILE&quot;
				exit 1
		else
			echo -e &quot; OK&quot;
				fi

# Load home page
				echo -ne &quot; &gt; Loading Home...&quot;
				curl -s -i -b &quot;$COOKIE_FILE&quot; -o &quot;$RESPONSE_FILE&quot; &quot;$HOME_URL&quot;

				if [ $? -ne 0 ]; then
					echo -e &quot; Failed!&quot;
						rm -f &quot;$COOKIE_FILE&quot; &quot;$RESPONSE_FILE&quot;
						exit 1
				else
					echo -e &quot; OK&quot;
						fi

# Get token
						TOKEN=$(cat &quot;$RESPONSE_FILE&quot; | tr -d &#039;\n&#039; | sed &#039;s/.*&lt;form action=&quot;https:\/\/dl-web.dropbox.com\/upload&quot;[^&gt;]*&gt;\s*&lt;input type=&quot;hidden&quot; name=&quot;t&quot; value=&quot;\([a-z 0-9]*\)&quot;.*/\1/&#039;)

# Upload file
						echo -ne &quot; &gt; Uploading &#039;$UPLOAD_FILE&#039; to &#039;DROPBOX$DEST_FOLDER/&#039;...&quot;
						curl -s -i -b $COOKIE_FILE -o $RESPONSE_FILE -F &quot;plain=yes&quot; -F &quot;dest=$DEST_FOLDER&quot; -F &quot;t=$TOKEN&quot; -F &quot;file=@$UPLOAD_FILE&quot;  &quot;$UPLOAD_URL&quot;
						grep &quot;HTTP/1.1 302 FOUND&quot; &quot;$RESPONSE_FILE&quot; &gt; /dev/null

						if [ $? -ne 0 ]; then
							echo -e &quot; Failed!&quot;
								rm -f &quot;$COOKIE_FILE&quot; &quot;$RESPONSE_FILE&quot;
								exit 1
						else
							echo -e &quot; OK&quot;
								rm -f &quot;$COOKIE_FILE&quot; &quot;$RESPONSE_FILE&quot;
								fi
}

# Backup files.
echo &quot;Dumping databases...&quot;
mysqldump -u $MYSQL_USER -h $MYSQL_SERVER -p$MYSQL_PASS --databases db_blog db_php &gt; &quot;$NOW-Databases.sql&quot;
echo &quot;Packing files...&quot;
tar czf &quot;$DESTFILE&quot; $BACKUP_SRC &quot;$NOW-Databases.sql&quot;

dropboxUpload &quot;$DESTFILE&quot; &quot;$DROPBOX_DIR&quot;

echo &quot;Cleaning the backups...&quot;
rm -f &quot;$NOW-Databases.sql&quot;
find $BACKUP_DST -mtime +31 -delete #这里的时间可以根据需要进行修改</pre>
<p>执行：/bin/bash /home/shell/DropboxBackup.sh</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/05/201205101220161.jpg"><img class="alignnone size-full wp-image-276" title="20120510122016" src="http://www.phpwebgo.com/wp-content/uploads/2012/05/201205101220161.jpg" alt="" width="632" height="180" /></a></p>
<p>3.每天定时备份：</p>
<p>①修改文件属性，使其可执行</p>
<p>chmod +x DropboxBackup.sh</p>
<p>②添加每天凌晨三点备份</p>
<p>vim /etc/crontab</p>
<p>01 3 * * * root /bin/bash /home/shell/DropboxBackup.sh</p>
<p>③重启crond</p>
<p>/etc/rc.d/init.d/crond restart</p>
<p>这样每天凌晨三点就会在/home/backup目录下面看到备份的文件，例如：</p>
<p>2012.05.10.tgz</p>
<p>crontab详见：<a title="crontab详细" href="http://www.phpwebgo.com/2011/12/01/269.html" target="_blank">http://www.phpwebgo.com/2011/12/01/269.html</a></p>
<p>参考:</p>
<p>http://heylinux.com/archives/1452.html</p>
<p>http://davehope.co.uk/Blog/backup-your-linux-vps-to-dropbox/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/05/10/274.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux(centos)下编译安装php性能测试工具xhprof笔记</title>
		<link>http://www.phpwebgo.com/2012/04/29/243.html</link>
		<comments>http://www.phpwebgo.com/2012/04/29/243.html#comments</comments>
		<pubDate>Sun, 29 Apr 2012 05:03:30 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>
		<category><![CDATA[PHP编程]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=243</guid>
		<description><![CDATA[一、安装xhprof： wget http://pecl.php.net/get/xhprof-0.9.2.tgz tar zxvf xhprof-0.9.2.tgz cd xhprof-0.9.2 mkdir /home/wwwroot/xhprof cp -r xhprof_html xhprof_lib /home/wwwroot/xhprof/ cd extension/ /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make &#38;&#38; make install vim /usr/local/php/etc/php.ini extension = &#34;xhprof.so&#34; xhprof.output_dir=/home/wwwlogs/xhprof mkdir /home/wwwlogs/xhprof chmod 777 -R /home/wwwlogs/xhprof/ /etc/init.d/php-fpm restart /etc/init.d/nginx restart &#160; phpinfo信息：xhprof  0.9.2 CPU num  2 &#160; 二、安装画图工具graphviz wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz tar zxvf graphviz-2.24.0.tar.gz cd graphviz-2.24.0 ./configure make &#38;&#38; [...]]]></description>
			<content:encoded><![CDATA[<p>一、安装<span style="font-family: Times New Roman;">xhprof</span>：</p>
<pre class="brush: bash; gutter: true">wget http://pecl.php.net/get/xhprof-0.9.2.tgz

tar zxvf xhprof-0.9.2.tgz

cd xhprof-0.9.2

mkdir /home/wwwroot/xhprof

cp -r xhprof_html xhprof_lib /home/wwwroot/xhprof/

cd extension/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make &amp;&amp; make install

vim /usr/local/php/etc/php.ini

extension = &quot;xhprof.so&quot;

xhprof.output_dir=/home/wwwlogs/xhprof

 mkdir /home/wwwlogs/xhprof

 chmod 777 -R /home/wwwlogs/xhprof/

/etc/init.d/php-fpm restart

/etc/init.d/nginx restart</pre>
<p>&nbsp;</p>
<p><span>phpinfo</span>信息：<br style="font-family: 宋体;" />xhprof  0.9.2<br />
CPU num  2</p>
<p>&nbsp;</p>
<p>二、安装<span style="font-family: Times New Roman;">画图工具graphviz</span></p>
<pre class="brush: bash; gutter: true">wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz

 tar zxvf graphviz-2.24.0.tar.gz

cd graphviz-2.24.0

./configure
make &amp;&amp; make install</pre>
<p>&nbsp;</p>
<p>三、如何使用</p>
<p>xhprof_enable(); // 统计的代码部分之前加，如果要显示CPU占用 可以加入XHPROF_FLAGS_CPU参数，内存是XHPROF_FLAGS_MEMORY，如果两个一起：XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY，如：xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);</p>
<p>xhprof_disable();//统计的代码部分之后加</p>
<p>这样xhprof就可以统计当前页面的函数性能情况了。xhprof会把每次访问加入统计代码的页面的性能统计结果在指定目录下生成一个文件，文件名命名方式为：本次访问的系统ID.命名空间，每次刷新页面都会重新生成一个文件，每个的系统ID都不同。</p>
<p>例子：</p>
<p>测试用php扩展<span style="color: #ff0000;"><strong><a title="getlocationip扩展" href="http://www.phpwebgo.com/2012/04/18/230.html" target="_blank">getlocationip</a></strong></span>和原生的php读取qqwry.dat，哪个更好一些：</p>
<p>vim /home/wwwroot/t.php</p>
<pre class="brush: php; gutter: true">&lt;?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
$xhprof_on = true;
$obj = new getlocationip(&#039;./qqwry.dat&#039;);
for($i=0;$i&lt;1000;$i++)
{
	echo $ip = rand(10,255).&#039;.&#039;.rand(1,255).&#039;.&#039;.rand(1,255).&#039;.&#039;.rand(1,255);
	$address = $obj-&gt;find($ip);
	$str = $address [&#039;0&#039;].$address [&#039;1&#039;];
	echo $str.&#039;&lt;hr&gt;&#039;;
}
if($xhprof_on){
	$xhprof_data = xhprof_disable();
	$xhprof_root = dirname(__FILE__).&#039;/xhprof/&#039;;
	include_once $xhprof_root.&quot;xhprof_lib/utils/xhprof_lib.php&quot;;
	include_once $xhprof_root.&quot;xhprof_lib/utils/xhprof_runs.php&quot;;
	$xhprof_runs = new XHProfRuns_Default();
	$run_id = $xhprof_runs-&gt;save_run($xhprof_data, &quot;hx&quot;);
	echo &#039;&lt;a href=&quot;http://xxx.xxx.xxx.xxx/xhprof/xhprof_html/index.php?run=&#039;.$run_id.&#039;&amp;source=hx&quot; target=&quot;_blank&quot;&gt;统计&lt;/a&gt;&#039;;
 }</pre>
<p>vim /home/wwwroot/t2.php</p>
<pre class="brush: php; gutter: true">&lt;?php
class IpLocation {

	/**
	 * QQWry.Dat文件指针
	 *
	 * @var resource
	 */
	var $fp;

	/**
	 * 第一条IP记录的偏移地址
	 *
	 * @var int
	 */
	var $firstip;

	/**
	 * 最后一条IP记录的偏移地址
	 *
	 * @var int
	 */
	var $lastip;

	/**
	 * IP记录的总条数（不包含版本信息记录）
	 *
	 * @var int
	 */
	var $totalip;

	/**
	 * 构造函数，打开 QQWry.Dat 文件并初始化类中的信息
	 *
	 * @param string $filename
	 * @return IpLocation
	 */
	function __construct($filename = &quot;QQWry.Dat&quot;) {
		$this-&gt;fp = 0;
		if (($this-&gt;fp = fopen ( $filename, &#039;rb&#039; )) !== false) {
			$this-&gt;firstip = $this-&gt;getlong ();
			$this-&gt;lastip = $this-&gt;getlong ();
			$this-&gt;totalip = ($this-&gt;lastip - $this-&gt;firstip) / 7;
			//注册析构函数，使其在程序执行结束时执行
			register_shutdown_function ( array (&amp;$this, &#039;_IpLocation&#039; ) );
		}
	}
	/**
	 * 返回读取的长整型数
	 *
	 * @access private
	 * @return int
	 */
	function getlong() {
		//将读取的little-endian编码的4个字节转化为长整型数
		$result = unpack ( &#039;Vlong&#039;, fread ( $this-&gt;fp, 4 ) );
		return $result [&#039;long&#039;];
	}

	/**
	 * 返回读取的3个字节的长整型数
	 *
	 * @access private
	 * @return int
	 */
	function getlong3() {
		//将读取的little-endian编码的3个字节转化为长整型数
		$result = unpack ( &#039;Vlong&#039;, fread ( $this-&gt;fp, 3 ) . chr ( 0 ) );
		return $result [&#039;long&#039;];
	}

	/**
	 * 返回压缩后可进行比较的IP地址
	 *
	 * @access private
	 * @param string $ip
	 * @return string
	 */
	function packip($ip) {
		// 将IP地址转化为长整型数，如果在PHP5中，IP地址错误，则返回False，
		// 这时intval将Flase转化为整数-1，之后压缩成big-endian编码的字符串
		return pack ( &#039;N&#039;, intval ( ip2long ( $ip ) ) );
	}

	/**
	 * 返回读取的字符串
	 *
	 * @access private
	 * @param string $data
	 * @return string
	 */
	function getstring($data = &quot;&quot;) {
		$char = fread ( $this-&gt;fp, 1 );
		while ( ord ( $char ) &gt; 0 ) { // 字符串按照C格式保存，以\0结束
			$data .= $char; // 将读取的字符连接到给定字符串之后
			$char = fread ( $this-&gt;fp, 1 );
		}
		return $data;
	}

	/**
	 * 返回地区信息
	 *
	 * @access private
	 * @return string
	 */
	function getarea() {
		$byte = fread ( $this-&gt;fp, 1 ); // 标志字节
		switch (ord ( $byte )) {
			case 0 : // 没有区域信息
				$area = &quot;&quot;;
				break;
			case 1 :
			case 2 : // 标志字节为1或2，表示区域信息被重定向
				fseek ( $this-&gt;fp, $this-&gt;getlong3 () );
				$area = $this-&gt;getstring ();
				break;
			default : // 否则，表示区域信息没有被重定向
				$area = $this-&gt;getstring ( $byte );
				break;
		}
		return $area;
	}

	/**
	 * 根据所给 IP 地址或域名返回所在地区信息
	 *
	 * @access public
	 * @param string $ip
	 * @return array
	 */
	function getlocation($ip) {
		if (! $this-&gt;fp)
			return null; // 如果数据文件没有被正确打开，则直接返回空
		$location [&#039;ip&#039;] = gethostbyname ( $ip ); // 将输入的域名转化为IP地址
		$ip = $this-&gt;packip ( $location [&#039;ip&#039;] ); // 将输入的IP地址转化为可比较的IP地址
		// 不合法的IP地址会被转化为255.255.255.255
		// 对分搜索
		$l = 0; // 搜索的下边界
		$u = $this-&gt;totalip; // 搜索的上边界
		$findip = $this-&gt;lastip; // 如果没有找到就返回最后一条IP记录（QQWry.Dat的版本信息）
		while ( $l &lt;= $u ) { // 当上边界小于下边界时，查找失败
			$i = floor ( ($l + $u) / 2 ); // 计算近似中间记录
			fseek ( $this-&gt;fp, $this-&gt;firstip + $i * 7 );
			$beginip = strrev ( fread ( $this-&gt;fp, 4 ) ); // 获取中间记录的开始IP地址
			// strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式
			// 以便用于比较，后面相同。
			if ($ip &lt; $beginip) { // 用户的IP小于中间记录的开始IP地址时
				$u = $i - 1; // 将搜索的上边界修改为中间记录减一
			} else {
				fseek ( $this-&gt;fp, $this-&gt;getlong3 () );
				$endip = strrev ( fread ( $this-&gt;fp, 4 ) ); // 获取中间记录的结束IP地址
				if ($ip &gt; $endip) { // 用户的IP大于中间记录的结束IP地址时
					$l = $i + 1; // 将搜索的下边界修改为中间记录加一
				} else { // 用户的IP在中间记录的IP范围内时
					$findip = $this-&gt;firstip + $i * 7;
					break; // 则表示找到结果，退出循环
				}
			}
		}

		//获取查找到的IP地理位置信息
		fseek ( $this-&gt;fp, $findip );
		$location [&#039;beginip&#039;] = long2ip ( $this-&gt;getlong () ); // 用户IP所在范围的开始地址
		$offset = $this-&gt;getlong3 ();
		fseek ( $this-&gt;fp, $offset );
		$location [&#039;endip&#039;] = long2ip ( $this-&gt;getlong () ); // 用户IP所在范围的结束地址
		$byte = fread ( $this-&gt;fp, 1 ); // 标志字节
		switch (ord ( $byte )) {
			case 1 : // 标志字节为1，表示国家和区域信息都被同时重定向
				$countryOffset = $this-&gt;getlong3 (); // 重定向地址
				fseek ( $this-&gt;fp, $countryOffset );
				$byte = fread ( $this-&gt;fp, 1 ); // 标志字节
				switch (ord ( $byte )) {
					case 2 : // 标志字节为2，表示国家信息又被重定向
						fseek ( $this-&gt;fp, $this-&gt;getlong3 () );
						$location [&#039;country&#039;] = $this-&gt;getstring ();
						fseek ( $this-&gt;fp, $countryOffset + 4 );
						$location [&#039;area&#039;] = $this-&gt;getarea ();
						break;
					default : // 否则，表示国家信息没有被重定向
						$location [&#039;country&#039;] = $this-&gt;getstring ( $byte );
						$location [&#039;area&#039;] = $this-&gt;getarea ();
						break;
				}
				break;
			case 2 : // 标志字节为2，表示国家信息被重定向
				fseek ( $this-&gt;fp, $this-&gt;getlong3 () );
				$location [&#039;country&#039;] = $this-&gt;getstring ();
				fseek ( $this-&gt;fp, $offset + 8 );
				$location [&#039;area&#039;] = $this-&gt;getarea ();
				break;
			default : // 否则，表示国家信息没有被重定向
				$location [&#039;country&#039;] = $this-&gt;getstring ( $byte );
				$location [&#039;area&#039;] = $this-&gt;getarea ();
				break;
		}
		if ($location [&#039;country&#039;] == &quot; CZ88.NET&quot;) { // CZ88.NET表示没有有效信息
			$location [&#039;country&#039;] = &quot;未知&quot;;
		}
		if ($location [&#039;area&#039;] == &quot; CZ88.NET&quot;) {
			$location [&#039;area&#039;] = &quot;&quot;;
		}
		return $location;
	}

	/**
	 * 析构函数，用于在页面执行结束后自动关闭打开的文件。
	 *
	 */
	function _IpLocation() {
		if ($this-&gt;fp) {
			fclose ( $this-&gt;fp );
		}
		$this-&gt;fp = 0;
	}
}
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
$xhprof_on = true;
$dir= &quot;./qqwry.dat&quot;;
$myobj = new IpLocation ($dir);
for($i=0;$i&lt;1000;$i++)
{
	echo $ip = rand(10,255).&#039;.&#039;.rand(1,255).&#039;.&#039;.rand(1,255).&#039;.&#039;.rand(1,255);
	$address = $myobj-&gt;getlocation ($ip );
	$str = $address [&#039;country&#039;].$address [&#039;area&#039;];
	echo $str.&#039;&lt;hr&gt;&#039;;
}
if($xhprof_on){
	$xhprof_data = xhprof_disable();
	$xhprof_root = dirname(__FILE__).&#039;/xhprof/&#039;;
	include_once $xhprof_root.&quot;xhprof_lib/utils/xhprof_lib.php&quot;;
	include_once $xhprof_root.&quot;xhprof_lib/utils/xhprof_runs.php&quot;;
	$xhprof_runs = new XHProfRuns_Default();
	$run_id = $xhprof_runs-&gt;save_run($xhprof_data, &quot;hx&quot;);
	echo &#039;&lt;a href=&quot;http://xxx.xxx.xxx.xxx/xhprof/xhprof_html/index.php?run=&#039;.$run_id.&#039;&amp;source=hx&quot; target=&quot;_blank&quot;&gt;统计&lt;/a&gt;&#039;;
 }</pre>
<p>分别运行两个脚本，点击统计即可</p>
<p>名词：<br />
1. Inclusive Time ：包括子函数所有执行时间。<br />
2. Exclusive Time/Self Time：函数执行本身花费的时间，不包括子树执行时间。<br />
3. Wall Time：花去了的时间或挂钟时间。<br />
4. CPU Time：用户耗的时间+内核耗的时间<br />
5.Inclusive CPU：包括子函数一起所占用的CPU<br />
6.Exclusive CPU：函数自身所占用的CPU</p>
<p>&nbsp;</p>
<p>然后通过xhprof_html目录的http访问url来查看结果。如：http://app/xhprof_html/?run=运行id&amp;source=命名空间（其中运行ID和命名空间可以根据xhprof生成的文件名来确定）</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131309.jpg"><img title="20120429131309" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131309.jpg" alt="" width="819" height="448" /></a></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131309_2.png"><img title="20120429131309_2" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131309_2.png" alt="" width="555" height="621" /></a></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131359.jpg"><img title="20120429131359" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131359-1024x569.jpg" alt="" width="1024" height="569" /></a></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131359_2.png"><img title="20120429131359_2" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/20120429131359_2-1024x879.png" alt="" width="1024" height="879" /></a></p>
<p>可以看出扩展要比纯php要快6~10倍</p>
<p>&nbsp;</p>
<p>在生产环境可以按访问多少个用户来开启，比如1000个访问有一次的统计</p>
<pre class="brush: php; gutter: true">if (rand(1, 1000) == 1) {
 xhprof_enable(XHPROF_FLAGS_MEMORY);
 $xhprof_on = true;
}</pre>
<p>后续：</p>
<p>比如xhprof的profile日志以文件形式保存到服务器，需要定时清理；查看时需要一个一个查看不太方便；由于xhprof生成的profile是一个大数组，所以保存到文件时使用了标准的php serialize，日志文件偏大，磁盘空间以及serialize存在效率问题(CPU 很high)</p>
<p>一些思路：可以把日志单独放到一台日志服务器上或者存入到MySQL数据库持久化存储，以后统计起来也比较方便:)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/04/29/243.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP扩展(getlocationip)根据纯真IP(qqwry.dat)获取物理地理位置开发手记</title>
		<link>http://www.phpwebgo.com/2012/04/18/230.html</link>
		<comments>http://www.phpwebgo.com/2012/04/18/230.html#comments</comments>
		<pubDate>Wed, 18 Apr 2012 14:06:49 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>
		<category><![CDATA[PHP编程]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=230</guid>
		<description><![CDATA[一、进入PHP源码根目录。 二、输入 ./ext_skel &#8211;extname=getlocationip 这时会生成一个目录getlocationip，即我们新建的PHP扩展模块。 接着进入该目录，cd getlocationip 三、编辑config.m4文件，即 vim config.m4，去掉如下图所示的三行注释 四、编写我们的扩展，用C来读取纯真IP库文件。 vim  php_getlocationip.h: /* +----------------------------------------------------------------------+ &#124; PHP Version 5 &#124; +----------------------------------------------------------------------+ &#124; Copyright (c) 1997-2012 The PHP Group &#124; +----------------------------------------------------------------------+ &#124; This source file is subject to version 3.01 of the PHP license, &#124; &#124; that is bundled with this package in the file LICENSE, and is &#124; &#124; available through [...]]]></description>
			<content:encoded><![CDATA[<p>一、进入<span style="font-family: Times New Roman;">PHP</span><span style="font-family: 宋体;">源码根目录。</span></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/1.1.jpg"><img class="alignnone size-full wp-image-231" title="1.1" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/1.1.jpg" alt="" width="761" height="73" /></a></p>
<p>二、输入 <span style="font-family: Times New Roman;">./ext_skel &#8211;extname=getlocationip</span></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/11.jpg"><img class="alignnone size-full wp-image-232" title="1" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/11.jpg" alt="" width="680" height="24" /></a></p>
<p>这时会生成一个目录<span style="font-family: Times New Roman;">getlocationip</span><span style="font-family: 宋体;">，即我们新建的</span><span style="font-family: Times New Roman;">PHP</span><span style="font-family: 宋体;">扩展模块。</span></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/21.jpg"><img class="alignnone size-full wp-image-233" title="2" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/21.jpg" alt="" width="772" height="445" /></a></p>
<p>接着进入该目录，<span style="font-family: Times New Roman;">cd getlocationip</span></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/31.jpg"><img class="alignnone size-full wp-image-234" title="3" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/31.jpg" alt="" width="773" height="110" /></a></p>
<p>三、编辑<span style="font-family: Times New Roman;">config.m4</span><span style="font-family: 宋体;">文件，即 </span><span style="font-family: Times New Roman;">vim config.m4</span><span style="font-family: 宋体;">，去掉如下图所示的三行注释</span></p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/4.jpg"><img class="alignnone size-full wp-image-235" title="4" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/4.jpg" alt="" width="773" height="272" /></a></p>
<p>四、编写我们的扩展，用<span style="font-family: Times New Roman;">C</span><span style="font-family: 宋体;">来读取纯真</span><span style="font-family: Times New Roman;">IP</span><span style="font-family: 宋体;">库文件。</span></p>
<p>vim  php_getlocationip.h:</p>
<pre class="brush: c; gutter: true">/*
  +----------------------------------------------------------------------+
  | PHP Version 5                                                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2012 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.01 of the PHP license,      |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_01.txt                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Author:  coldsea&lt;wanghaihan521#gmail.com&gt;                                                        |
  +----------------------------------------------------------------------+
*/

/* $Id: header 321634 2012-01-01 13:15:04Z felipe $ */

#ifndef PHP_GETLOCATIONIP_H
#define PHP_GETLOCATIONIP_H

extern zend_module_entry getlocationip_module_entry;
#define phpext_getlocationip_ptr &amp;getlocationip_module_entry

#ifdef PHP_WIN32
#	define PHP_GETLOCATIONIP_API __declspec(dllexport)
#elif defined(__GNUC__) &amp;&amp; __GNUC__ &gt;= 4
#	define PHP_GETLOCATIONIP_API __attribute__ ((visibility(&quot;default&quot;)))
#else
#	define PHP_GETLOCATIONIP_API
#endif

#ifdef ZTS
#include &quot;TSRM.h&quot;
#endif

PHP_MINIT_FUNCTION(getlocationip);
PHP_MSHUTDOWN_FUNCTION(getlocationip);
PHP_RINIT_FUNCTION(getlocationip);
PHP_RSHUTDOWN_FUNCTION(getlocationip);
PHP_MINFO_FUNCTION(getlocationip);

/* PHP_FUNCTION(confirm_getlocationip_compiled); */	/* For testing, remove later. */
PHP_METHOD(getlocationip,__construct);
ZEND_BEGIN_ARG_INFO_EX(getlocationip____construct_args,ZEND_SEND_BY_VAL,ZEND_RETURN_VALUE,0)
ZEND_END_ARG_INFO()

PHP_METHOD(getlocationip,find);
ZEND_BEGIN_ARG_INFO_EX(getlocationip__find_args,ZEND_SEND_BY_VAL,ZEND_RETURN_VALUE,0)
ZEND_END_ARG_INFO()

/*
  	Declare any global variables you may need between the BEGIN
	and END macros here:     

ZEND_BEGIN_MODULE_GLOBALS(getlocationip)
	long  global_value;
	char *global_string;
ZEND_END_MODULE_GLOBALS(getlocationip)
*/

ZEND_BEGIN_MODULE_GLOBALS(getlocationip)

ZEND_END_MODULE_GLOBALS(getlocationip)

/* In every utility function you add that needs to use variables
   in php_getlocationip_globals, call TSRMLS_FETCH(); after declaring other
   variables used by that function, or better yet, pass in TSRMLS_CC
   after the last function argument and declare your utility function
   with TSRMLS_DC after the last declared argument.  Always refer to
   the globals in your function as GETLOCATIONIP_G(variable).  You are
   encouraged to rename these macros something shorter, see
   examples in any other php module directory.
*/

#ifdef ZTS
#define GETLOCATIONIP_G(v) TSRMG(getlocationip_globals_id, zend_getlocationip_globals *, v)
#else
#define GETLOCATIONIP_G(v) (getlocationip_globals.v)
#endif

#endif	/* PHP_GETLOCATIONIP_H */

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim&lt;600: noet sw=4 ts=4
 */</pre>
<p>vim  getlocationip.c:</p>
<pre class="brush: c; gutter: true">/*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2012 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author:  coldsea&lt;wanghaihan521#gmail.com&gt;                                                            |
   +----------------------------------------------------------------------+
   */

/* $Id: header 321634 2012-01-01 13:15:04Z felipe $ */

#ifdef HAVE_CONFIG_H
#include &quot;config.h&quot;
#endif

#include &quot;php.h&quot;
#include &quot;php_ini.h&quot;
#include &quot;ext/standard/info.h&quot;
#include &quot;php_getlocationip.h&quot;

#define GETLOCATIONIP_ADDR_LEN 128
#define REDIRECT_MODE_1 0x01
#define REDIRECT_MODE_2 0x02

ZEND_DECLARE_MODULE_GLOBALS(getlocationip);

/* If you declare any globals in php_getlocationip.h uncomment this:
   ZEND_DECLARE_MODULE_GLOBALS(getlocationip)
   */

/* True global resources - no need for thread safety here */
/*static int le_getlocationip;*/

zend_class_entry *getlocationip_class_entry_ptr;

/*unsigned long getValue( 获取文件中指定的16进制串的值，并返回
  FILE *fp, 指定文件指针
  unsigned long start, 指定文件偏移量
  int length) 获取的16进制字符个数/长度
  */
unsigned long getValue(FILE *fp, unsigned long start, int length)
{
    unsigned long variable=0;
    long val[length],i;

    fseek(fp,start,SEEK_SET);
    for(i=0;i&lt;length;i++)
    {
        /*过滤高位，一次读取一个字符*/
        val[i]=fgetc(fp)&amp;0x000000FF;
    }
    for(i=length-1;i&gt;=0;i--)
    {
        /*因为读取多个16进制字符，叠加*/
        variable=variable*0x100+val[i];
    }
    return variable;
};

/*int getString( 获取文件中指定的字符串，返回字符串长度
  FILE *fp, 指定文件指针
  unsigned long start, 指定文件偏移量
  char **string) 用来存放将读取字符串的字符串空间的首地址
  */
int getString(FILE *fp, unsigned long start, char **string)
{
    unsigned long i=0;
    char val;
    fseek(fp,start,SEEK_SET);
    /*读取字符串，直到遇到0x00为止*/
    do
    {
        val=fgetc(fp);
        /*依次放入用来存储的字符串空间中*/
        *(*string+i)=val;
        i++;
    }while(val!=0x00);
    /*返回字符串长度*/
    return i;
};

/*void getAddress( 读取指定IP的国家位置和地域位置
  FILE *fp, 指定文件指针
  unsigned long start, 指定IP在索引中的文件偏移量
  char **country, 用来存放国家位置的字符串空间的首地址
  char **location) 用来存放地域位置的字符串空间的首地址
  */
void getAddress(FILE *fp, unsigned long start, char **country, char **location)
{
    unsigned long redirect_address,counrty_address,location_address;
    char val;

    start+=4;
    fseek(fp,start,SEEK_SET);
    /*读取首地址的值*/
    val=(fgetc(fp)&amp;0x000000FF);

    if(val==REDIRECT_MODE_1)
    {
        /*重定向1类型的*/
        redirect_address=getValue(fp,start+1,3);
        fseek(fp,redirect_address,SEEK_SET);
        /*混合类型，重定向1类型进入后遇到重定向2类型
          读取重定向后的内容，并设置地域位置的文件偏移量*/
        if((fgetc(fp)&amp;0x000000FF)==REDIRECT_MODE_2)
        {
            counrty_address=getValue(fp,redirect_address+1,3);
            location_address=redirect_address+4;
            getString(fp,counrty_address,country);
        }
        /*读取重定向1后的内容，并设置地域位置的文件偏移量*/
        else
        {
            counrty_address=redirect_address;
            location_address=redirect_address+getString(fp,counrty_address,country);
        }
    }
    /*重定向2类型的*/
    else if(val==REDIRECT_MODE_2)
    {
        counrty_address=getValue(fp,start+1,3);
        location_address=start+4;
        getString(fp,counrty_address,country);
    }
    else
    {
        counrty_address=start;
        location_address=counrty_address+getString(fp,counrty_address,country);
    }

    /*读取地域位置*/
    fseek(fp,location_address,SEEK_SET);
    if((fgetc(fp)&amp;0x000000FF)==REDIRECT_MODE_2||(fgetc(fp)&amp;0x000000FF)==REDIRECT_MODE_1)
    {
        location_address=getValue(fp,location_address+1,3);
    }
    getString(fp,location_address,location);

    return;
};

/*void getHead( 读取索引部分的范围（在文件头中，最先的2个8位16进制）
  FILE *fp, 指定文件指针
  unsigned long *start, 文件偏移量，索引的起止位置
  unsigned long *end) 文件偏移量，索引的结束位置
  */
void getHead(FILE *fp,unsigned long *start,unsigned long *end)
{
    /*索引的起止位置的文件偏移量，存储在文件头中的前8个16进制中
      设置偏移量为0，读取4个字符*/
    *start=getValue(fp,0L,4);
    /*索引的结束位置的文件偏移量，存储在文件头中的第8个到第15个的16进制中
      设置偏移量为4个字符，再读取4个字符*/
    *end=getValue(fp,4L,4);
};

/*unsigned long searchIP( 搜索指定IP在索引区的位置，采用二分查找法；
  返回IP在索引区域的文件偏移量
  一条索引记录的结果是，前4个16进制表示起始IP地址
  后面3个16进制，表示该起始IP在IP信息段中的位置，文件偏移量
  FILE *fp,
  unsigned long index_start, 索引起始位置的文件偏移量
  unsigned long index_end, 索引结束位置的文件偏移量
  unsigned long ip) 关键字，要索引的IP
  */
unsigned long searchIP(FILE *fp, unsigned long index_start, \

        unsigned long index_end, unsigned long ip)
{
    unsigned long index_current,index_top,index_bottom;
    unsigned long record;
    index_bottom=index_start;
    index_top=index_end;
    /*此处的7，是因为一条索引记录的长度是7*/
    index_current=((index_top-index_bottom)/7/2)*7+index_bottom;
    /*二分查找法*/
    do{
        record=getValue(fp,index_current,4);
        if(record&gt;ip)
        {
            index_top=index_current;
            index_current=((index_top-index_bottom)/14)*7+index_bottom;
        }
        else
        {
            index_bottom=index_current;
            index_current=((index_top-index_bottom)/14)*7+index_bottom;
        }
    }while(index_bottom&lt;index_current);
    /*返回关键字IP在索引区域的文件偏移量*/
    return index_current;
};

/*判断一个字符是否为数字字符，
  如果是，返回0
  如果不是，返回1*/
int beNumber(char c)
{
    if(c&gt;=&#039;0&#039;&amp;&amp;c&lt;=&#039;9&#039;)
        return 0;
    else
        return 1;
};

/*函数的参数是一个存储着IP地址的字符串首地址
  返回该IP的16进制代码
  如果输入的IP地址有错误，函数将返回0*/
unsigned long getIP(char *ip_addr)
{
    unsigned long ip=0;
    int i,j=0;
    /*依次读取字符串中的各个字符*/
    for(i=0;i&lt;strlen(ip_addr);i++)
    {
        /*如果是IP地址间隔的‘.’符号
          把当前读取到的IP字段的值，存入ip变量中
          （注意，ip为叠加时，乘以16进制的0x100）
          并清除临时变量的值*/
        if(*(ip_addr+i)==&#039;.&#039;)
        {
            ip=ip*0x100+j;
            j=0;
        }
        /*往临时变量中写入当前读取到的IP字段中的字符值
          叠加乘以10，因为输入的IP地址是10进制*/
        else
        {
            /*判断，如果输入的IP地址不规范，不是10进制字符
              函数将返回0*/
            if(beNumber(*(ip_addr+i))==0)
                j=j*10+*(ip_addr+i)-&#039;0&#039;;
            else
                return 0;
        }
    }
    /*IP字段有4个，但是‘.’只有3个，叠加第四个字段值*/
    ip=ip*0x100+j;
    return ip;
};

PHP_METHOD(getlocationip,__construct)
{
    char *getlocationip_path = NULL;
    int getlocationip_len;
    zval * _this_zval = NULL;
    if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC,getThis(),&quot;Os&quot;,&amp;_this_zval,getlocationip_class_entry_ptr,&amp;getlocationip_path,&amp;getlocationip_len) == FAILURE)
    {
        return;
    }
    add_property_string(_this_zval,&quot;f&quot;,getlocationip_path,1);
}

PHP_METHOD(getlocationip,find)
{
    char *ip_string = NULL;
    int ipstring_len;
    zval * _this_zval = NULL;
    unsigned long index_start,index_end,current; /*索引部分的起始位置的文件偏移量
                                                   索引部分的结束位置的文件偏移量
                                                   待搜索IP地址的索引条目的文件偏移量*/

    if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC,getThis(),&quot;Os&quot;,&amp;_this_zval,getlocationip_class_entry_ptr,&amp;ip_string,&amp;ipstring_len) == FAILURE)
    {
        return;
    }

    char *addr1 = (char *)emalloc(GETLOCATIONIP_ADDR_LEN);
    char *addr2 = (char *)emalloc(GETLOCATIONIP_ADDR_LEN);
    memset(addr1,0,GETLOCATIONIP_ADDR_LEN);
    memset(addr2,0,GETLOCATIONIP_ADDR_LEN);
    zval **tmp;
    char *getlocationip_path;
    if(zend_hash_find(Z_OBJPROP_P(_this_zval),&quot;f&quot;,sizeof(&quot;f&quot;),(void **)&amp;tmp) == FAILURE)
    {
        return;
    }
    getlocationip_path = Z_STRVAL_PP(tmp);
    //RETURN_STRING(getlocationip_path,0);

    FILE *fp = NULL;

    fp = fopen(getlocationip_path,&quot;rb&quot;);
    //RETURN_RESOURCE(fp);
    getHead(fp,&amp;index_start,&amp;index_end);
    getAddress(fp,getValue(fp,index_end+4,3),&amp;addr1,&amp;addr2);

    unsigned long ip;

    ip=getIP(ip_string);

    /*搜索IP在索引区域的条目的偏移量*/
    current=searchIP(fp,index_start,index_end,ip);

    /*获取该IP对因的国家地址和地域地址*/
    getAddress(fp,getValue(fp,current+4,3),&amp;addr1,&amp;addr2);
    //RETURN_STRING(addr1,0);
    fclose(fp);
    zval *zaddr1,*zaddr2;
    MAKE_STD_ZVAL(zaddr1);
    ZVAL_STRING(zaddr1,addr1,0);
    MAKE_STD_ZVAL(zaddr2);
    const char *del_str = &quot;CZ88.NET&quot;;
    int result = strcmp(addr2,del_str);
    //RETURN_LONG(result);
    if(result&lt;0){
        ZVAL_STRING(zaddr2,&quot;&quot;,1);
    }else{
        ZVAL_STRING(zaddr2,addr2,0);
    }
    array_init(return_value);
    add_next_index_zval(return_value,zaddr1);
    add_next_index_zval(return_value,zaddr2);
    //efree(addr1);
    //efree(addr2);
}

/* {{{ getlocationip_functions[]
 *
 * Every user visible function must have an entry in getlocationip_functions[].
 */
const zend_function_entry getlocationip_functions[] = {
    //PHP_FE(confirm_getlocationip_compiled,	NULL)		/* For testing, remove later. */
    PHP_FE_END	/* Must be the last line in getlocationip_functions[] */
};
/* }}} */

    zend_function_entry getlocationip_methods[] = {
        PHP_ME(getlocationip,__construct,NULL,ZEND_ACC_PUBLIC)
            PHP_ME(getlocationip,find,NULL,ZEND_ACC_PUBLIC)
            {NULL,NULL,NULL}
    };

/* {{{ getlocationip_module_entry
*/
zend_module_entry getlocationip_module_entry = {
#if ZEND_MODULE_API_NO &gt;= 20010901
    STANDARD_MODULE_HEADER,
#endif
    &quot;getlocationip&quot;,
    getlocationip_functions,
    PHP_MINIT(getlocationip),
    PHP_MSHUTDOWN(getlocationip),
    PHP_RINIT(getlocationip),		/* Replace with NULL if there&#039;s nothing to do at request start */
    PHP_RSHUTDOWN(getlocationip),	/* Replace with NULL if there&#039;s nothing to do at request end */
    PHP_MINFO(getlocationip),
#if ZEND_MODULE_API_NO &gt;= 20010901
    &quot;0.1&quot;, /* Replace with version number for your extension */
#endif
    STANDARD_MODULE_PROPERTIES
};
/* }}} */

#ifdef COMPILE_DL_GETLOCATIONIP
ZEND_GET_MODULE(getlocationip)
#endif

    /* {{{ PHP_INI
    */
    /* Remove comments and fill if you need to have entries in php.ini
       PHP_INI_BEGIN()
       STD_PHP_INI_ENTRY(&quot;getlocationip.global_value&quot;,      &quot;42&quot;, PHP_INI_ALL, OnUpdateLong, global_value, zend_getlocationip_globals, getlocationip_globals)
       STD_PHP_INI_ENTRY(&quot;getlocationip.global_string&quot;, &quot;foobar&quot;, PHP_INI_ALL, OnUpdateString, global_string, zend_getlocationip_globals, getlocationip_globals)
       PHP_INI_END()
       */
    /* }}} */

    /* {{{ php_getlocationip_init_globals
    */
    /* Uncomment this function if you have INI entries
       static void php_getlocationip_init_globals(zend_getlocationip_globals *getlocationip_globals)
       {
       getlocationip_globals-&gt;global_value = 0;
       getlocationip_globals-&gt;global_string = NULL;
       }
       */
    /* }}} */

    /* {{{ PHP_MINIT_FUNCTION
    */
PHP_MINIT_FUNCTION(getlocationip)
{
    /* If you have INI entries, uncomment these lines
       REGISTER_INI_ENTRIES();
       */
#ifdef ZTS
    ZEND_INIT_MODULE_GLOBALS(getlocationip,NULL,NULL);
#endif
    zend_class_entry getlocationip_class_entry;
    INIT_CLASS_ENTRY(getlocationip_class_entry,&quot;getlocationip&quot;,getlocationip_methods);
    getlocationip_class_entry_ptr = zend_register_internal_class(&amp;getlocationip_class_entry TSRMLS_CC);
    return SUCCESS;
}
/* }}} */

/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(getlocationip)
{
    /* uncomment this line if you have INI entries
       UNREGISTER_INI_ENTRIES();
       */
    return SUCCESS;
}
/* }}} */

/* Remove if there&#039;s nothing to do at request start */
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(getlocationip)
{

    return SUCCESS;
}
/* }}} */

/* Remove if there&#039;s nothing to do at request end */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(getlocationip)
{
    return SUCCESS;
}
/* }}} */

/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(getlocationip)
{
    php_info_print_table_start();
	php_info_print_table_header(2, &quot;getlocationip support&quot;, &quot;enabled&quot;);
	php_info_print_table_row(2, &quot;version&quot;, &quot;0.1&quot;);
    php_info_print_table_row(2, &quot;author&quot;, &quot;coldsea&quot;);
    php_info_print_table_row(2, &quot;homepage&quot;, &quot;www.phpwebgo.com&quot;);
  php_info_print_table_end();

    /* Remove comments if you have entries in php.ini
       DISPLAY_INI_ENTRIES();
       */
}
/* }}} */

/* Remove the following function when you have succesfully modified config.m4
   so that your module can be compiled into PHP, it exists only for testing
   purposes. */

/* Every user-visible function in PHP should document itself in the source */
/* {{{ proto string confirm_getlocationip_compiled(string arg)
   Return a string to confirm that the module is compiled in */
/* PHP_FUNCTION(confirm_getlocationip_compiled)
   {
   char *arg = NULL;
   int arg_len, len;
   char *strg;

   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &quot;s&quot;, &amp;arg, &amp;arg_len) == FAILURE) {
   return;
   }

   len = spprintf(&amp;strg, 0, &quot;Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.&quot;, &quot;getlocationip&quot;, arg);
   RETURN_STRINGL(strg, len, 0);
   }
   */
/* }}} */
/* The previous line is meant for vim and emacs, so it can correctly fold and
   unfold functions in source code. See the corresponding marks just before
   function definition, where the functions purpose is also documented. Please
   follow this convention for the convenience of others editing your code.
   */

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim&lt;600: noet sw=4 ts=4
 */</pre>
<p>&nbsp;</p>
<p>五、编译：</p>
<pre class="brush: bash; gutter: true">  ①/usr/local/php5/bin/phpize

  ②./configure --with-php-config=/usr/local/php5/bin/php-config

  ③make &amp;&amp; make install

  ④vim /usr/local/php5/lib/php.ini 

   添加以下内容：

extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/getlocationip.so

  ⑤/usr/local/apache2/bin/apachectl restart</pre>
<p>六、查看<span style="font-family: Times New Roman;">phpinfo</span><span style="font-family: 宋体;">是否加载成功，测试是否能够获取物理</span><span style="font-family: Times New Roman;">IP</span><span style="font-family: 宋体;">地址</span></p>
<pre class="brush: bash; gutter: true">vim /usr/local/apache2/htdocs/test.php

$obj = new getlocationip(&#039;./QQWry.dat&#039;);  var_dump($obj-&gt;find(&#039;202.196.98.74&#039;));</pre>
<p>输出：</p>
<p>array(2) {</p>
<p>[0]=&gt;</p>
<p>string(12) ”<span style="font-family: 宋体;">河南省开封市</span><span style="font-family: Times New Roman;">“</span></p>
<p>[1]=&gt;</p>
<p>string(8) ”<span style="font-family: 宋体;">河南大学</span><span style="font-family: Times New Roman;">“</span></p>
<p>}</p>
<p>随便写了个<span style="font-family: Times New Roman;">IP</span><span style="font-family: 宋体;">正好是我的母校 </span><span style="font-family: Times New Roman;"> <img src='http://www.phpwebgo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p>&nbsp;</p>
<p><span style="color: #0000ff;"><strong>google code地址：</strong></span></p>
<p><span style="color: #0000ff;"><strong>http://code.google.com/p/getlocationip</strong></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/04/18/230.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linux(centos)下用vim搭建php开发环境IDE</title>
		<link>http://www.phpwebgo.com/2012/04/09/214.html</link>
		<comments>http://www.phpwebgo.com/2012/04/09/214.html#comments</comments>
		<pubDate>Sun, 08 Apr 2012 16:46:25 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=214</guid>
		<description><![CDATA[让vi以vim来运行 输入alias命令： alias查看当前所有命令 下面是加入命令 alias vi=&#039;vim&#039; 这表示当你使用vi 这个命令时，其实执行的是vim。如果没有这一行，那么你必须使用vim filename来启动vim。 alias参考http://en.wikipedia.org/wiki/Alias_(command) 整体vim的设置一般是在/etc/vimrc这个文件中，不过，不建议修改他！你可以修改~/.vimrc这个文件（如果不存在，请你自行手动建立），将我们希望的设定值写入！ 比如： &#34;引号代表注释 set hlsearch &#34;高亮度反白 set backspace=2 &#34;可随时用倒退键删除 set autoindent &#34;自动缩排 set ruler &#34;可显示最后一行的状态 set showmode &#34;左下角那一行的状态 set nu &#34;可以在每一行的最前面显示行号 set bg=dark &#34;显示不同的底色色调 syntax on &#34;进行语法检验，颜色显示 set wrap &#34;自动折行 set shiftwidth=4 set tabstop=4 set softtabstop=4 set expandtab &#34;将tab替换为相应数量空格 set smartindent set encoding=utf8 &#34;设置编码为utf8 set [...]]]></description>
			<content:encoded><![CDATA[<p>让vi以vim来运行<br />
输入alias命令：<br />
alias查看当前所有命令<br />
下面是加入命令</p>
<pre class="brush: bash; gutter: true">alias vi=&#039;vim&#039;</pre>
<p>这表示当你使用vi 这个命令时，其实执行的是vim。如果没有这一行，那么你必须使用vim filename来启动vim。<br />
alias参考http://en.wikipedia.org/wiki/Alias_(command)</p>
<p>整体vim的设置一般是在/etc/vimrc这个文件中，不过，不建议修改他！你可以修改~/.vimrc这个文件（如果不存在，请你自行手动建立），将我们希望的设定值写入！<br />
比如：</p>
<pre class="brush: bash; gutter: true">&quot;引号代表注释

set hlsearch &quot;高亮度反白
set backspace=2 &quot;可随时用倒退键删除
set autoindent &quot;自动缩排
set ruler &quot;可显示最后一行的状态
set showmode &quot;左下角那一行的状态
set nu &quot;可以在每一行的最前面显示行号
set bg=dark &quot;显示不同的底色色调
syntax on &quot;进行语法检验，颜色显示
set wrap &quot;自动折行
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab &quot;将tab替换为相应数量空格
set smartindent
set encoding=utf8 &quot;设置编码为utf8
set fileencoding=utf8
set fileencodings=uft8-bom,utf8,gbk
set fileformat=unix &quot;设置文件格式
set fileformats=unix,dos,mac

&quot;开启phpcomplete插件
filetype plugin on
autocmd FileType php set omnifunc=phpcomplete#CompletePHP

&quot;开启php documentor插件
source /usr/share/vim/vim70/autoload/php-doc.vim
inoremap :call PhpDocSingle()i
nnoremap :call PhpDocSingle()
vnoremap :call PhpDocRange()

&quot;配置taglist插件
set tags=tags;
set autochdir</pre>
<p>如何安装phpcomplete插件<br />
如果是VIM7.0以上，不需要再下载 phpcomplete.vim 这个插件，因为安装时自带了，在目录/usr/share/vim/vim70/autoload/phpcomplete.vim中。<br />
在 ~/.vimrc 中添加这样两行：<br />
filetype plugin on<br />
autocmd FileType php set omnifunc=phpcomplete#CompletePHP</p>
<p>如何使用：<br />
vi index.php<br />
插入一段php代码后比如：<br />
htmlsp<br />
先按下 Ctrl+x进入^X模式,再按下 Ctrl+o， 就能看到提示列表框，以及对应的function，还有对应的函数定义比如参数等等<br />
Ctrl+n, Ctrl+p 来上下选择，ESC 来取消提示</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/1.jpg"><img class="alignnone  wp-image-221" title="1" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/1.jpg" alt="" /></a></p>
<p>如何安装php documentor插件</p>
<p>http://www.vim.org/scripts/script.php?script_id=1355</p>
<p>下载php-doc.vim<br />
cp ./php-doc.vim /usr/share/vim/vim70/autoload/php-doc.vim</p>
<p>install details<br />
Installation<br />
=========</p>
<p>For example include into your .vimrc:</p>
<p>source ~/.vim/php-doc.vim<br />
inoremap :call PhpDocSingle()i<br />
nnoremap :call PhpDocSingle()<br />
vnoremap :call PhpDocRange()<br />
根据官网提供的安装实例，我们进行以下操作：<br />
vi ~/.vimrc<br />
source /usr/share/vim/vim70/autoload/php-doc.vim<br />
inoremap :call PhpDocSingle()i<br />
nnoremap :call PhpDocSingle()<br />
vnoremap :call PhpDocRange()</p>
<p>如何使用：<br />
在函数定义出按ctrl+p即可</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/2.jpg"><img class="alignnone size-full wp-image-223" title="2" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/2.jpg" alt="" /></a></p>
<p>&nbsp;</p>
<p>如何安装NERDTree插件</p>
<p>http://www.vim.org/scripts/script.php?script_id=1658</p>
<p>然后解压，解压缩后把plugin,doc,syntax,nerdtree_plugin四个目录复制到/usr/share/vim/vim70/目录下，即可完成安装。<br />
进入vim后 :NERDTree开启</p>
<p>如何使用<br />
1、在linux命令行界面，输入vim<br />
2、输入 :NERDTree ，回车<br />
3、进入当前目录的树形界面，通过h，j键或者小键盘上下键，能移动选中的目录或文件<br />
4、按u键到上级目录，按o键打开或者关闭文件。目录前面有+号，摁Enter会展开目录，文件前面是-号，摁Enter会在右侧窗口展现该文件的内容，并光标的焦点focus右侧。<br />
5、ctr+w+h 光标focus左侧树形目录，ctrl+w+l 光标focus右侧文件显示窗口。多次摁 ctrl+w，光标自动在左右侧窗口切换<br />
6、光标focus左侧树形窗口，摁? 弹出NERDTree的帮助，再次摁？关闭帮助显示<br />
7、输入:q回车，关闭光标所在窗口</p>
<p><a href="http://www.phpwebgo.com/wp-content/uploads/2012/04/3.jpg"><img class="alignnone size-full wp-image-224" title="3" src="http://www.phpwebgo.com/wp-content/uploads/2012/04/3.jpg" alt="" /></a></p>
<p>&nbsp;</p>
<p>如何安装Taglist插件</p>
<p>Taglist和Ctags介绍<br />
Taglist是Vim的源代码浏览插件，提供了在Vim中查看文件中包含的函数列表和类的方法类表的功能。Taglist功能的实现要依赖于Ctags。Ctags是一个用于产生代码索引文件的插件，其产生的索引文件用于帮助文本编辑器或其他工具快速，准确定位符号在代码文件中的位置。Ctags可以支持很多很多语言</p>
<p>1.ctags<br />
（1）到http://ctags.sourceforge.net/下载ctags源码ctags-5.6.tar.gz<br />
wget http://prdownloads.sourceforge.net/ctags/ctags-5.6.tar.gz<br />
（2）解压并安装<br />
tar zxvf ctags-5.6.tar.gz<br />
cd ctags-5.6<br />
./configure &amp;&amp; make &amp;&amp; make install<br />
（3）使用<br />
[/home/php/src]$ ctags -R</p>
<p>“-R”表示递归创建，也就包括源代码根目录下的所有子目录下的源程序。”tags”文件中包括这些对象的列表：<br />
l 用#define定义的宏<br />
l 枚举型变量的值<br />
l 函数的定义、原型和声明<br />
l 名字空间（namespace）<br />
l 类型定义（typedefs）<br />
l 变量（包括定义和声明）<br />
l 类（class）、结构（struct）、枚举类型（enum）和联合（union）<br />
l 类、结构和联合中成员变量或函数<br />
VIM用这个”tags”文件来定位上面这些做了标记的对象，下面介绍一下定位这些对象的方法：</p>
<p>1) 用命令行。在运行vim的时候加上”-t”参数，例如：<br />
[/home/brimmer/src]$ vim -t foo_bar<br />
这个命令将打开定义”foo_bar”（变量或函数或其它）的文件，并把光标定位到这一行。<br />
2) 在vim编辑器内用”:ta”命令，例如：<br />
:ta foo_bar<br />
3) 最方便的方法是把光标移到变量名或函数名上，然后按下”Ctrl-]”。用”Ctrl-o”退回原来的地方。<br />
注意：运行vim的时候，必须在”tags”文件所在的目录下运行。否则，运行vim的时候还要用”:set tags=”命令设定”tags”文件的路径，这样vim才能找到”tags”文件。</p>
<p>在函数中移动光标<br />
[{ 转到上一个位于第一列的"{"<br />
}] 转到下一个位于第一列的”{”<br />
{ 转到上一个空行<br />
} 转到下一个空行 （[ and ] 也分别是两个指令）<br />
gd 转到当前光标所指的局部变量的定义<br />
* 转到当前光标所指的单词下一次出现的地方<br />
# 转到当前光标所指的单词上一次出现的地方<br />
Vim 的创造者是一名计算机程序员，因此这就不奇怪 Vim 中有许多帮助编写程序的功能：<br />
跳转到标识符被定义和使用的地方；在另一个窗口中预览有关的声明等等。</p>
<p>2. taglist<br />
能够列出源文件中的tag(function, class, variable, etc)并跳转.<br />
注意：taglist依赖于ctags，所以要先装ctags，否则taglist装了也没法用！<br />
到http://vim.sourceforge.net/scripts/script.php?script_id=273下载taglist_45.zip即可<br />
（2）解压得到两个文件<br />
# unzip -d taglist taglist_45.zip<br />
# cd taglist<br />
# tree<br />
.<br />
|&#8211; doc<br />
| `&#8211; taglist.txt<br />
`&#8211; plugin<br />
`&#8211; taglist.vim<br />
（3）安装<br />
cp doc/taglist.txt /usr/share/vim/vim70/doc/<br />
cp plugin/taglist.vim /usr/share/vim/vim70/plugin/<br />
编辑 vim 配置文件 .vimrc</p>
<p>在 .vimrc 文件中添加：</p>
<p>set tags=tags;<br />
set autochdir</p>
<p>注: 第一个命令里的分号是必不可少的。这个命令让vim首先在当前目录里寻找tags文件，如果没有找到tags文件，或者没有找到对应的目标，就到父目录中查找，一直向上递归。因为tags文件中记录的路径总是相对于tags文件所在的路径，所以要使用第二个设置项来改变vim的当前目录。</p>
<p>当然你如果想直接使用绝对路径，这样也是可以的：</p>
<p>set tags=/home/xxx/myproject/tags</p>
<p>3. 打开 Vim 前使用命令 ctags -R 产生 tags 文件， Vim 在启动时会自动查找并加载 tags 文件。</p>
<p>打开 Vim 之后，使用命令 :Tlist 激活 Taglist； 按两次 Ctrl + W 在两个窗口来回跳转；Ctrl + ] 或 回车键 查看函数定义(前者在 Taglist 窗口显示， 后者在源文件窗口显示）， Ctrl + O 跳回光标上次所在位置。<br />
Taglist 快捷键</p>
<p>回车键 跳到光标所在的标记的定义处(如将光标移到main函数,按回车键)<br />
o 新建一个窗口,跳到标记定义处<br />
p 预览标记定义(仍然在taglist窗口)<br />
空格 在窗口的最下面显示标记的原型(如函数原型)<br />
u 更新标记列表(比如源文件新增了一个函数,并在保存后,可在taglist窗口按u)<br />
s 更改排序方式，在按名字排序和按出现顺序排序间切<br />
d 删除光标所在的taglist文件(如用vi打开了两个文件f1.c,f2.c可以删除f1.c的标记)<br />
x 放大/缩小taglist窗口<br />
+ 展开(指标记)<br />
- 折叠<br />
* 全部展开<br />
= 全部折叠<br />
[[ 将光标移到前一个文件的起点<br />
]] 将光标移到后一个文件的起点<br />
q 退出taglist窗口</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/04/09/214.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux(centos)下源码编译方式安装lamp手记</title>
		<link>http://www.phpwebgo.com/2012/04/07/208.html</link>
		<comments>http://www.phpwebgo.com/2012/04/07/208.html#comments</comments>
		<pubDate>Fri, 06 Apr 2012 18:18:03 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=208</guid>
		<description><![CDATA[前提：安装gcc等可以编译c源码的工具 sudo -s LANG=C yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers 首先到各自官方下载好源码： 一、MySQL的安装 tar zxvf mysql-5.1.62.tar.gz cd mysql-5.1.62 ./configure --with-mysqld-user=mysql --prefix=/usr/local/mysql5 --with-extra-charset=all --without-isam [...]]]></description>
			<content:encoded><![CDATA[<p>前提：安装gcc等可以编译c源码的工具</p>
<pre class="brush: bash; gutter: true">sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers</pre>
<p>首先到各自官方下载好源码：<br />
一、MySQL的安装</p>
<pre class="brush: bash; gutter: true">
tar zxvf mysql-5.1.62.tar.gz
cd mysql-5.1.62
./configure --with-mysqld-user=mysql --prefix=/usr/local/mysql5 --with-extra-charset=all --without-isam --with-plugins=innobase --exec-prefix=/usr/local/mysql5</pre>
<p>出现以下提示后就可以编译安装了</p>
<pre class="brush: bash; gutter: true">Thank you for choosing MySQL!
Remember to check the platform specific part of the reference manual
for hints about installing MySQL on your platform.
Also have a look at the files in the Docs directory.

make &amp;&amp; make install

groupadd mysql

useradd -g mysql mysql

scripts/mysql_install_db

cp /usr/local/mysql5/share/mysql/my-medium.cnf /usr/local/mysql5/var/my.cnf

cp /usr/local/mysql5/share/mysql/mysql.server /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --level 2345 mysqld on

chown mysql:mysql -R /usr/local/mysql5/

service mysqld start

ln -s /usr/local/mysql5/bin/mysql /sbin/mysql

ln -s /usr/local/mysql5/bin/mysqladmin /sbin/mysqladmin

设定mysql密码
mysqladmin -uroot password &quot;123456&quot;
测试：
netstat -nplt | grep mysql

ps aux|grep mysql
</pre>
<p>二、Apache的安装</p>
<pre class="brush: bash; gutter: true">tar zxvf httpd-2.2.22.tar.gz
cd httpd-2.2.22
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite

make &amp;&amp; make install

/usr/local/apache2/bin/apachectl configtest

/usr/local/apache2/bin/apachectl start

/usr/local/apache2/bin/apachectl stop
修改默认启动页
vi /usr/local/apache2/conf/httpd.conf
DirectoryIndex index.html 改为
DirectoryIndex index.html index.htm default.htm default.html index.php default.php</pre>
<p>三、安装PHP模块<br />
在编译php的时候，出现如下错误php安装出错：configure: error: mcrypt.h not found. Please reinstall libmcrypt.，意思是，没有查找到mcrytp.h,需要安装libcrytp,在下面的地址下载libmarypt:</p>
<pre class="brush: bash; gutter: true">wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
安装：
tar -zxvf libmcrypt-2.5.7.tar.gz67
cd libmcrypt-2.5.768
mkdir -p /usr/local/libmcrytp
./configure prefix=/usr/local/libmcrytp/
Make
make install
然后再安装PHP

tar zxvf php-5.3.10.tar.gz
cd php-5.3.10

注意：--with-mcrypt=/usr/local/libmcrypt/，要不然会报错提示reinstall libmcrypt

./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql5 --with-mysqli=/usr/local/mysql5/bin/mysql_config --with-pdo_mysql=/usr/local/mysql5 --with-apxs2=/usr/local/apache2/bin/apxs --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbstring --with-mcrypt=/usr/local/libmcrypt/ --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap

以下安装方式【】内可以跳过，此方法基本没有安装任何扩展，只是说明后续缺哪个模块的时候再怎样安装。
【
未安装任何扩展方式，需要手动安装扩展
./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql5 --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --enable-ftp --enable-sockets

cd /ext
cd mysqli
/usr/local/php5/bin/phpize
./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/php5/bin/php-config --with-mysqli=/usr/local/mysql5/bin/mysql_config
make &amp;&amp; make install

cd curl
/usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config --enable-curl make &amp;&amp; make install

cd mbstring
/usr/local/php5/bin/phpize
./configure --with-php-con

cd pdo_mysql
/usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo_mysql=/usr/local/mysql5 /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mysqli.so /usr/local/apache2/bin/apachectl restart
Vi /usr/local/php5/lib/php.ini
extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mysqli.so extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mbstring.so extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/curl.so extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/gd.so extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/iconv.so extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/pdo_mysql.so ;extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mysqli.so

】
//make ZEND_EXTRA_LIBS=&#039;-liconv&#039;

make
make install
3：配置
cp php.ini-production /usr/local/php5/lib/php.ini
编辑httpd.conf
/usr/local/apache2/conf/httpd.conf
加载php模块，去掉注释，编译时指定apache的路径会自动去掉注释
LoadModule php5_module modules/libphp5.so
加上下面两行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

[root@localhost ~]# /usr/local/apache2/bin/apachectl start
httpd: Syntax error on line 62 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

php安装好以后
apache2 无法启动
最后一步重新启动apache报如下错误

原因是Linux有一个SELinux保护模式引起的。

Syntax error on line 268 of /usr/local/apache2/conf/httpd.conf:

Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

解决办法
原因是Linux有一个SELinux保护模式引起的。1.关闭SELINUX的方法:vi /etc linux/config 将SELINUX=enforcing 改成SELINUX=disabled 需要重启

2.不关闭SELINUX的方法:

# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so
# /usr/local/apache2/bin/apachectl start

# setenforce 1
</pre>
<p>四、安装phpmyadmin</p>
<pre class="brush: bash; gutter: true">tar -zxvf phpMyAdmin-3.5.0-rc2-all-languages.tar.gz
cp -rf phpMyAdmin-3.5.0-rc2-all-languages /usr/local/apache2/htdocs/phpmyadmin
试试浏览器访问：http://localhost/phpmyadmin
Apache开启虚拟主机功能：
vim /usr/local/apache2/conf/httpd.conf
:400 （找到大概400行）
#Include conf/extra/httpd-vhosts.conf
去掉#
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
注释掉默认的虚拟主机命令
:28,43s/^/#/g

28 #
29 # ServerAdmin webmaster@dummy-host.example.com
30 # DocumentRoot &quot;/usr/local/apache2/docs/dummy-host.example.com&quot;
31 # ServerName dummy-host.example.com
32 # ServerAlias www.dummy-host.example.com
33 # ErrorLog &quot;logs/dummy-host.example.com-error_log&quot;
34 # CustomLog &quot;logs/dummy-host.example.com-access_log&quot; common
35 #
36
37 #
38 # ServerAdmin webmaster@dummy-host2.example.com
39 # DocumentRoot &quot;/usr/local/apache2/docs/dummy-host2.example.com&quot;
40 # ServerName dummy-host2.example.com
41 # ErrorLog &quot;logs/dummy-host2.example.com-error_log&quot;
42 # CustomLog &quot;logs/dummy-host2.example.com-access_log&quot; common
43 #

拷贝37到43行内容到46行
:37,43 co 46
接着去掉46行到52行注释
:46,52s/^#//g
修改文件为：
46
47 ServerAdmin webmaster@phpwebgo.com
48 DocumentRoot &quot;/home/wwwroot/www.phpwebgo.com&quot;
49 ServerName www.phpwebgo.com
50 ErrorLog &quot;logs/www.phpwebgo.com-error_log&quot;
51 CustomLog &quot;logs/www.phpwebgo.com-access_log&quot; common
52

重启apache
/usr/local/apache2/bin/apachectl start

浏览器提示
apache You don&#039;t have permission to access / on this server.
愿意是网站根目录设置为：DocumentRoot &quot;/home/wwwroot/www.phpwebgo.com&quot;
解决办法：
vim /usr/local/apache2/conf/httpd.conf
:/Directory [搜索Directory]

118
119 Options FollowSymLinks
120 AllowOverride None
121 Order deny,allow
122 # Deny from all
123 allow from all
124

把Deny from all修改为 allow from all 即可
</pre>
<p>五、安装zend【5.3.X可以跳过】</p>
<pre class="brush: bash; gutter: true">wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

tar -zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-i386
mkdir /usr/local/php5/lib/extensions
cp ./data/5_2_x_comp/ZendOptimizer.so /usr/local/php5/lib/extensions/ZendOptimizer.so
vim /usr/local/php5/lib/php.ini
Shift+g到最后一行添加：
zend_optimizer.optimization_level=15
zend_extension=&quot;/usr/local/php5/lib/extensions/ZendOptimizer.so&quot;</pre>
<p>以上就是CentOS下安装LAMP的方法，回头试着写一个一键安装shell脚本。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/04/07/208.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>centos启动自动进入纯命令行模式</title>
		<link>http://www.phpwebgo.com/2012/04/05/205.html</link>
		<comments>http://www.phpwebgo.com/2012/04/05/205.html#comments</comments>
		<pubDate>Thu, 05 Apr 2012 02:11:58 +0000</pubDate>
		<dc:creator>coldsea</dc:creator>
				<category><![CDATA[Lamp]]></category>

		<guid isPermaLink="false">http://www.phpwebgo.com/?p=205</guid>
		<description><![CDATA[# vi /etc/inittab 编辑 init 5 为 init 3 下次启动时就自动进入控制台方式. 想进入的话打 # startx 想退出可以用桌面的注销 或者快捷键 Ctrl + Alt + Backspace 当然以上方法是比较彻底的方式. 也可以用Ctrl + Alt + (F1~F5)的方式直接切入进控制台模式 要切回的话,就需要按Ctrl + Alt + F6或F7,就会切换回去.]]></description>
			<content:encoded><![CDATA[<p># vi /etc/inittab<br />
编辑 init 5 为 init 3<br />
下次启动时就自动进入控制台方式.<br />
想进入的话打<br />
# startx<br />
想退出可以用桌面的注销<br />
或者快捷键 Ctrl + Alt + Backspace</p>
<p>当然以上方法是比较彻底的方式.<br />
也可以用Ctrl + Alt + (F1~F5)的方式直接切入进控制台模式<br />
要切回的话,就需要按Ctrl + Alt + F6或F7,就会切换回去.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpwebgo.com/2012/04/05/205.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

