[root@192-16.x.x xiewenming]# curl myip.ipip.net 当前 IP:42.62.x.x 来自于:中国 北京 北京 联通/电信
www.17ce.com cdn解析网站测试
如果遇到 -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory,解决办法如下:
vi /etc/environment add these lines... LANG=en_US.utf-8 LC_ALL=en_US.utf-8
结束php进程,主进程除外
ps -ef|grep php|grep -v grep|cut -c 9-15|xargs kill -9
用指定用户执行脚本或命令
su - tomcat -c /usr/local/tomcat/bin/startup.sh
切换root执行
sudo sh tomcat.sh start
查查哪个目录的inode节点使用的多
[root@opt]# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/vda2 576K 497K 80K 87% / tmpfs 235K 5 235K 1% /dev/shm [root@192-168-3-157 var]# for i in /*; do echo $i; find $i| wc -l;done ... /var 363753 [root@var]# for i in /var/*; do echo $i; find $i| wc -l;done [root@var]#time find /var/spool/postfix/maildrop -type f -delete
其它其中删除目录下面有大量文件的方法
#相同的测试数据 #方法1 time rsync -a --delete /dev/null / test/ --16s #方法2 time find ./ -type f -exec rm {} ; --43 分钟 #方法3 time find ./ -type f -delete --9分钟 #方法4 python import os import time stime=time.time() for pathname,dirnames,filenames in os.walk('/home/username/test'): for filename in filenames: file=os.path.join(pathname,filename) os.remove(file) ftime=time.time() print ftime-stime --8分钟
ssh -t 可以创建一个虚拟终端,这样就可以执行一些如 vim / htop 之类的命令,也包括 sudo 之类
ssh -t 192.168.56.134 "vi xiewenming.txt"
sudo 使用需要tty可以通知/etc/sudoers 默认是需要的,有时远程执行sudo命令提示需要一个tty,可以把默认下面这行注释掉
[root@xiewenming]# grep tty /etc/sudoers Defaults requiretty
使用$!调用上一个命令的最后一个参数
[root@linux-node1 ~]# ll -d /etc/sysconfig/network-scripts/ drwxr-xr-x. 2 root root 4096 Dec 5 03:39 /etc/sysconfig/network-scripts/ [root@linux-node1 ~]# cd !$ cd /etc/sysconfig/network-scripts/ [root@linux-node1 network-scripts]#
当系统可用内存不足是可以用下面的命令回收系统可用内存命令,
Nov 22 09:47:43 192-168-3-150 kernel: XFS: possible memory allocation deadlock in kmem_alloc (mode:0x250) 这里有报错内存死锁,有时候用下面这条命令可以解决问题
echo 1 > /proc/sys/vm/drop_caches
查看系统ip连接及流量统计信息
iotop可以查看IO读写请求
删除用户及家目录
userdel -r 用户名
清空nginx cache脚本
#!/bin/bash cache_purge(){ PURGE_URL=$1 URL_NAME=$(echo -n $PURGE_URL | md5sum | awk '{print $1}') FILE_NAME=$(echo $URL_NAME | awk '{print "/data/cdn_cache/proxy_cache_dir/"substr($0,length($0),1)"/"substr($0,length($0)-2,2)"/"$0}') rm -rf $FILE_NAME } purge_file(){ PURGE_FILE=$1 for url in $(cat $PURGE_FILE);do cache_purge $url done } purge_url(){ PURGE_URL=$1 cache_purge $PURGE_URL } usage(){ echo $"Usage: $0 <url_file | 'url'>" } main (){ if [ "$#" -ne 1 ];then usage; else if [ -f $1 ];then purge_file $1; else purge_url $1; fi fi } main $1
重启tomcat脚本
#!/bin/bash TOMCAT_PATH=/usr/local/tomcat usage(){ echo "Usage: $0 [start|stop|status|restart]" } status_tomcat(){ ps aux | grep java | grep tomcat | grep -v 'grep' } start_tomcat(){ /usr/local/tomcat/bin/startup.sh } stop_tomcat(){ TPID=$(ps aux | grep java | grep tomcat | grep -v 'grep' | awk '{print $2}') kill -9 $TPID sleep 5; TSTAT=$(ps aux | grep java | grep tomcat | grep -v 'grep' | awk '{print $2}') if [ -z $TSTAT ];then echo "tomcat stop" else kill -9 $TSTAT fi cd $TOMCAT_PATH rm temp/* -rf rm work/* -rf } main(){ case $1 in start) start_tomcat;; stop) stop_tomcat;; status) status_tomcat;; restart) stop_tomcat && start_tomcat;; *) usage; esac } main $1
MySQL5.6在CentOS6上面的安装脚本
[root@192-168-3-201 src]# more Setup_Mysql-5.6.30.sh #!/bin/bash echo '+++++++++++++++++++++++++++++++++++++++++' echo '+ 欢迎使用Mysql-5.6.30自动部署安装脚本!+' echo '+ +' echo '+ 系统版本:CentOS-6.6 CentOS-6.7 +' echo '+ +' echo '+ Mysql版本:5.6.30 Cmake版本:3.5.2 +' echo '+ +' echo '+ 自动部署程序制作者:刘琪 +' echo '+++++++++++++++++++++++++++++++++++++++++' read -p '请创建Mysql数据库root账户的安全密码:' password #配置163-Yum源 mkdir /usr/local/src/Backup cp -a /etc/yum.repos.d/* /usr/local/src/Backup/ rm -rf /etc/yum.repos.d/* mv /usr/local/src/CentOS6-Base-163.repo /etc/yum.repos.d/ yum=`ls /etc/yum.repos.d/` if [ $yum = $yum ] then yum clean all yum listrepo else echo $yum163'这个Yum源没有安装成功!' kill=`ps aux | grep Setup | awk -F " " '{print $2}'` kill -9 $kill fi #安装依赖包和解压Mysql-5.6.30 Cmake-3.5.2的安装包 yum groupinstall "开发工具" -y yum install ncurses-devel vim -y tar xvf /usr/local/src/cmake-3.5.2.tar.gz tar xvf /usr/local/src/mysql-5.6.30.tar.gz #安装Cmake软件包--> cd /usr/local/src/cmake-3.5.2 ./configure --prefix=/usr/local/cmake && make && make install #安装Mysql-5.6.30软件包--> cd /usr/local/src/mysql-5.6.30 /usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci make && make install #检车是否有rpm安装包残余--> mysqlrpm=`rpm -qa | grep mysql` if [ $mysqlrpm = $mysqlrpm ] then yum remove `rpm -qa | grep mysql` -y else echo $mysqlrpm'这些软件不存在' fi #系统防火墙临时关闭和SElinux临时关闭 /etc/init.d/iptables stop setenforce 0 #创建Mysql账户并且指定uid号码和gid号码 useradd -M -u 27 -s /sbin/nologin mysql groupmod -g 27 mysql #设置Mysql所有者和所属组权限 chown mysql.mysql -R /usr/local/mysql/ #初始化Mysql数据库 cd /usr/local/mysql/ ./scripts/mysql_install_db --user=mysql #Mysql启动服务加载至系统当中 echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig --list mysqld #设置Mysql数据库目录所有者和所属组权限 chown mysql.mysql -R /usr/local/mysql/data/ #启动Mysql服务并且设置Mysql数据库root账户密码 service mysqld start cd /usr/local/mysql/ /usr/local/mysql/bin/mysqladmin -u root password "$password" #Mysql-5.6.30安装完毕后做一些系统归档工作 mkdir /usr/local/src/Yum-163 cp -a /etc/yum.repos.d/CentOS6-Base-163.repo /usr/local/src/Yum-163/ echo '++++++++++++++++++++++++++++++++++++++++++++' echo '+ Mysql5.6.30源码包安装成功!!! +' echo '+ +' echo "+ Mysql-5.6.30_root账户密码是:$password <------ OK!" echo '+ +' echo '+ Mysql版本:5.6.30 Cmake版本:3.5.2 +' echo '+ +' echo '+ 自动部署程序制作者:刘琪 +' echo '++++++++++++++++++++++++++++++++++++++++++++'
初始化系统和查看系统基础信息脚本CentOS6
#!/bin/bash #desc:System initialization for RedHat OS4.7 32&64bit #create:2010/12/06 #!/bin/bash cat << EOF ############################################################ check out OS info && SYSTEM initialization ############################################################ please make sure your selection from the menu : 1) System initialization 2) Check out servers hardware info 3) Check out software info 4) Check out system environment 5) Check all info For example: 1 2 3 EOF echo -n " Please enter your selection: " ###########Begin Check servers hardware info################### hardware_info() { if [ -x /usr/sbin/dmidecode ] then : else echo "The dmidecode is not exist.please checkout." exit 0 fi ID=0 if [ $UID -ne $ID ] then echo "Must root to run this scripts." exit 0 fi echo -e "