使用开源工具来做运维监控,如nagios报警,munin/cacti监控,puppet配置


查看nginx编译参数:/usr/local/nginx/sbin/nginx -V

查看php编译参数:/usr/local/php/bin/php -i | grep configure


拷贝目录, 忽略大图片目录

rsync -rt --exclude="static/p_w_picpaths/upload" web/ web-test


指定内容出现在文件中的总行数

cat all.log |grep 'data size:' | wc -l

含子目录查找 grep oldWord `find ./ -name "*.sh"` grep -ir oldWord *.sh(not work anymore)

批量文件替换 sed -i 's|oldWord|newWord|g' *.sh

含子目录替换 sed -i 's|oldString|newString|g' `find ./ -name "*.sh" -type f`


查找三个月没有更新的文件(!!!如果没有结果, 则会列出所有文件)

ls -lhtr `find /logs/ -iname '*.log' -type f -not -mtime -90`

删除三个月没有更新的文件

find /logs/ -iname '*.log' -type f -not -mtime -90 -exec rm -f {} \;

 

删除当前目录的子目录中的文件, 但保留每个子目录修改时间最新的两个文件

for dd in `dir -d *` ; do cd $dd; rm -f `ls -t |sed 1,2d |tr '\n' ' '`; cd ..; done

 

搜索当前目录的子目录大小为1M-1023M之间, 从大到小排列, 取前20个, 删除这些子目录中的最后修改时间为48小时之前的.log文件并进行删除

要先执行du -h --max-depth=1 |grep M |sort -nr |head -n 20查看确保第一列不是当前目录./

find `du -h --max-depth=1 |grep M |sort -nr |head -n 20 |awk '{print $2}' |tr '\n' ' '` -iname '*.log' -type f -not -mtime -2 -exec rm -f {} \;

 

设置用户的默认umask

umask 0022 增加到.bashrc

递归设置文件权限为644

find /path -type f -exec chmod 644 {} \;

递归设置目录权限为755

find /path -type d -exec chmod 755 {} \;

 

当前目录下所有文件, 不含子目录和子目录中的文件, 两种方式输出的格式不一样

ll |grep -v ^d 或 find ./ -maxdepth 1 -iname '*' -type f

 

rm后可以接多个文件, 文件名可以用正则表达式

一般用rm -fr (force, recursive)


ls --help |more

man ls


chown; chgrp

chmod u+x myStart.sh







free -m

top

du -h --max-depth

du -h --max-depth=1 |grep G |sort -n

du -h --max-depth=1 |grep M |sort -nr |head

 

ps aux | grep java

强行结束 kill -9

结束所有 killall

重启程序 kill -HUP


wget http://members.3322.org/dyndns/getip


ipcs -a


fuser -mv /usr

ps -fp "PID1 PID2"


sqlplus '' /as sysdba ''

nohup curl "" > output.txt

nohup curl "" > /dev/null

crontab -l

crontab -e

>/dev/null  2>&1  &


mysqld_safe --bind-address=127.0.0.1

memcached -d -m 512 -u user -l 127.0.0.1 -p 11211 -P /tmp/memcached.pid

telnet 127.0.0.1 11211





which mysql

whereis php

find / -name 'java'


yum check-update

yum update kernel kernel-source

 

yum install xmms-mp3

yum remove licq

 

yum list mozilla*

yum list updates

yum list installed


view or find installed software:

rpm -ivh [file_name]

rpm -qa |more

rpm -q software_name (rpm -q ftp) (rpm -q apache)(rpm -qa | grep httpd)

uninstall: rpm -e or rpm -ev







linux调优:

http://www.phpchina.com/download/handbook/linux-html/type17.html


vi /etc/inittab

change 'id:5:initdefault:' to 'id:3:initdefault:'


(change linux to English)

temporary:

#export LC_ALL=POSIX

persistent:

编辑/etc/sysconfig/目录下的i18n文件,将LC_ALL=POSIX





/etc/samba/smb.conf

1.hosts allow = 192.168.0.

security = share

2.[share_name]

comment = #comment

path = /home/share

browseable = 

writable = 

guest ok = 

3.

id nobody

uid=99(nobody) gid=99(nobody) groups=99(nobody)

chown -R nobody:nobody /home/share

4. ;service iptables stop

service network restart

service smb start


zip -r -9 products.zip products/ good_products.xml bad_products.xml

tar -czf

tar -xjf filename.tar.bz2

tar cf blog.tar blog --exclude blog/static/p_w_picpaths/upload

c: create; x: extract; z: gzip format; j: bz2 format


scp -rCp user@IP:source destination

scp -rCp source user@IP:destination


vimdiff scp://user@IP:port/~/blog/static/js/common.js ~/Documents/www/blog/static/js/common.js

diff -r <(md5 ~/Documents/workspace/proj-blog/target/proj-blog-0.0.1-SNAPSHOT.jar) <(ssh -p port user@IP 'md5sum /usr/local/tomcat/proj-web/webapps/proj-web-0.0.1-SNAPSHOT/WEB-INF/lib/proj-blog-0.0.1-SNAPSHOT.jar')