用tar打包备份时使用tar exclude排除指定目录,测试了很多次都不成功,正确的用法是:
tar zcv -f etc.tar.gz /etc --exclude=/etc/passwd --exclude=/etc/sysconfig打包的目录和排除的目录后都不要带/号,否则排除目录无效。
发布时间:May 20, 2012 // 分类:Linux基础 // No Comments
用tar打包备份时使用tar exclude排除指定目录,测试了很多次都不成功,正确的用法是:
tar zcv -f etc.tar.gz /etc --exclude=/etc/passwd --exclude=/etc/sysconfig打包的目录和排除的目录后都不要带/号,否则排除目录无效。
发布时间:May 20, 2012 // 分类:备份存储 // No Comments
inotify-tools是linux下通过inotify机制监控文件变化的命令行工具,可实时监控服务器文件变化并记录,如果服务器出现问题可协助查找原因,安装要求内核大于2.6.13。
查看服务器是否符合安装要求:
uname -a
Linux centos5.7-x64 2.6.18-274.17.1.el5 ll /proc/sys/fs/inotify/
-rw-r--r-- 1 root root 0 05-15 01:12 max_queued_events
-rw-r--r-- 1 root root 0 05-15 01:12 max_user_instances
-rw-r--r-- 1 root root 0 05-15 01:12 max_user_watches服务器如有安装EPEL源可使用yum安装:
yum install inotify-tools编译安装:
cd /usr/local/src/
wget --no-check-certificate https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure
make
make install
ldconfig -vinotify相关参数:
/proc/sys/fs/inotify/max_queued_events #请求events数的最大值
/proc/sys/fs/inotify/max_user_instances #每个user可创建的instances数量上限
/proc/sys/fs/inotify/max_user_watches #可监控的目录最大数inotifywait是一个监控等待事件,可配合shell实时监控记录文件系统,常用参数:
--timefmt 时间格式
%y年 %m月 %d日 %H小时 %M分钟
--format 输出格式
%T时间 %w路径 %f文件名 %e状态
-m 始终保持监听状态,默认触发事件即退出。
-r 递归查询目录
-q 打印出监控事件
-e 定义监控的事件,可用参数:
open 打开文件
access 访问文件
modify 修改文件
delete 删除文件
create 新建文件
attrb 属性变更应用示例:
实时监控wwwroot目录下新建或修改的文件并输出:
inotifywait -mrq -e modify,create --timefmt '%y-%m-%d %H:%M' --format '%T %f %e' /home/wwwroot/输出如下:
12-05-14 20:43 favicon.ico
12-05-14 20:43 favicon.ico
12-05-14 20:43 tab_console_down.gif
12-05-14 20:43 tab_console_down.gif
12-05-14 20:43 tab_graphs.gif
12-05-14 20:43 tab_graphs.gif 发布时间:May 19, 2012 // 分类:Shell // No Comments
Awk和Sed是Linux下很强大的两个文件处理工具,在编写Shell的时候经常要调用变量,记录调用方法。
1.Awk中调用方法:
1.1.使用"'$var'"方式:
#/bin/bash
num=1
awk -F: '{print $"'$num'"}' /etc/passwd1.2.通过awk -v参数定义:
#!/bin/bash
num=1
awk -v a=$num -F: '{print $a}' /etc/passwd2.Sed中调用方法:
#!/bin/bash
#https://www.haiyun.me
for ((i=1; i<25; i++))
do
ip=`sed -n "$i"p ip.txt`
sed -i ''"$i"' s/$/ '"$ip"'/' ip-mac.txt
done 发布时间:May 19, 2012 // 分类:PHP // No Comments
因程序原因需临时添加snmp支持,不想重新编译php,可动态编译添加snmp模块。
进入PHP源码扩展目录:
cd php-5.2.17/ext/snmp
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install加载模块:
cat >> /usr/local/php/etc/php.ini <<EOF
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension=snmp.so
EOF重新加载配置文件,查看snmp.so是否加载。
php -m 发布时间:May 19, 2012 // 分类:Apache // No Comments
网站目录或网页出现变动要使用301重定向转移权重,有时域名也要将www.haiyun.me重定向到www.haiyun.me,本文记录下Apaceh下301重定向方法,Nginx下301重定向请参考:https://www.haiyun.me/archives/nginx-301.html
1.使用RedirectMatch和Redirect重定向,这两个命令使用方法相似,RedirectMatch支持正则表达式,可以批量重定向。
使用语法:
Redirect [status] URL URL
RedirectMatch [status] regex URL[status]可用参数:
permanent 返回永久性重定向状态码(301),表示此资源的链接变动是永久性的。
temp 返回临时性重定向状态码(302),默认值。
seeother 返回一状态码(303),表示此资源已经被替代。
gone 返回状态码(410),表示此资源已经被永久性地删除了。如果指定了这个状态码,则URL参数将被忽略。应用示例:
Redirect permanent /index.html https://www.haiyun.me/index.php
RedirectMatch 301 (.*).gif$ https://www.haiyun.me/$1.jpg2.使用URL重写模块mod_rewrite重定向
RewriteEngine on
rewritecond %{http_host} ^www.haiyun.me [nc] #定义主机名变量,匹配执行下条规则。
rewriterule ^/(.*)$ https://www.haiyun.me/$1 [r=301,nc] #301重定向到www.haiyun.me,nc不区分大小写。