- 系统基本信息查看
cat /proc/cpuinfo //查看cpu信息
uname -a //查看系统内核 - 挂载磁盘
在192.168.1.30服务器上
/etc/init.d/nfs start //启动nfs
vi /etc/exports
增加: /data 192.168.1.1(rw,sync,fsid=0) 192.168.1.2(rw,sync,fsid=0)
service nfs restart //重启nfs
在192.168.1.1和192.168.1.2上分别执行
mount -t nfs 192.168.1.30:/data /data // 将30上的/data挂载到本机的/data - 查找文件
find . -type f -size +100M -print0 | xargs -0 du -h | sort -nr //查找大于100M的文件
find -type f -mtime +30 //查找30天以前的文件
grep -rn “hello,world!” *
find .| xargs grep -ri “hello,world” -l - iptables防火墙
yum install -y iptables //安装iptables
iptables -L -n // 查看
vi /etc/sysconfig/iptables
iptables -I INPUT -s 192.168.1.30 -j ACCEPT // 接收来自30服务器的所有请求
iptables -A INPUT -p tcp –dport 40022 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -p tcp –dport 40022 -j ACCEPT
etc/init.d/iptables restart //重启iptables - crontab定时器
crontab -l
servic crond start // stop restart reload status
/etc/crontab /var/spool/cron /etc/crond.d/
vi cronhello.cron
15,30,45,59 * * * * echo “hello” >> hello.txt // 每隔15min执行打印
crontab cronhello.cron - 用户权限
vi /etc/sudoers
增加 liufang ALL=(ALL) NOPASSWD: ALL - 用户操作
查看系统中有哪些用户:cut -d : -f 1 /etc/passwd
查看可以登录系统的用户:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1 - 杀死进程
kill -9 $(ps -ef | grep ‘test.jar’ | grep -v grep | awk ‘{print $2}’)
kill -s 9 `pgrep firefox`
pkill -9 firefox (pkill=pgrep+kill)
killall -9 firefox
pgrep firefox | xargs kill -s 9 - 配置开机启动
chmod +x /etc/rc.d/rc.local
echo ‘/data/tomcat/bin/startup.sh’ >> /etc/rc.d/rc.local - haproxy
vi /etc/haproxy/haproxy.cfg 编辑
haproxy -f /etc/haproxy/haproxy.cfg -c 校验
service haproxy restart 重启 查看哪些IP连接了memecached
netstat -naptl | grep “192.168.1.30:11211” | awk -F ‘[ :]*’ ‘{print $6}’ | sort -ru同理查看哪些连接了mysql
netstat -naptl | grep “192.168.1.30:3306” | awk -F ‘[ :]*’ ‘{print $6}’ | sort -ru
查看哪些连接了zookeeper
echo cons| nc 127.0.0.1 2181 // cons conf dump envi stat
- 免密登录
ssh-keygen -t rsa // 在本机生成密钥
ssh-copy-id -i ~/.ssh/id_rsa.pub “-p 40022 root@192.168.1.30” // 将密钥存储到192.168.1.30服务器上
ssh-copy-id -p 40022 root@192.168.1.30 //将密钥存储
cat ~/.ssh/id_rsa.pub | ssh -p 40022 root@192.168.1.30 ‘cat >> ~/.ssh/authorized_keys’ //将密钥存储到30服务器上
免密失败
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
service sshd restart
带上密码操作sshpass
sshpass -p 123456 ssh -p 60022 root@192.168.1.21 // 直接将密码放到参数中远程连接
sshpass -p ‘123456’ scp root@host_ip:/home/test/t ./tmp/ 将目标机器的文件拷贝到本地
在第一次远程操作的时候可能会失败,因为本机需要对目标机器添加信任,可以修改本机的ssh配置
vi /etc/ssh/ssh_config
#StrictHostKeyChecking ask 改成
StrictHostKeyChecking nossh复制文件
scp -P 40022 hello.zip liufang@192.168.1.30:~ // -P指定端口- ssh执行命令
ssh root@192.168.1.30 -p40022 ‘bash -s’ < /opt/test.sh //将本地test.sh文件上传到30服务器并且执行 -p40022是指定服务器端口 - 上传下载
yum install -y lrzsz // 安装rzsz
rz -y//上传 -y 覆盖上传
sz filename//下载
- -
有一个node第三方插件用node渲染后总是报错,原因是node不识别document,所以给打包后的代码加上try{}catch{}
num=`grep -n "document.addEventListener('click', function (e) {" dist/server.js|awk '{split($0,a,":");print a[1]}'`
sed -i "$num s/^.*$/try{document.addEventListener('click',function(e){/" dist/server.js
num=$[num+6]
sed -i "$num s/^.*$/});}catch(e){console.error(e);}/" dist/server.js
上面的程序执行第二次就会出现问题
#!/bin/bash
num=`grep -n "^[ ]*document.addEventListener('click', function (e) {" dist/server.js|awk '{split($0,a,":");print a[1]}'`
echo $num
if [ -n "$num" -a "$num" = "${num//[^0-9]/}" ]
then
sed -i "$num s/^.*$/try{document.addEventListener('click',function(e){/" dist/server.js
num=$[num+6]
sed -i "$num s/^.*$/});}catch(e){console.error(e);}/" dist/server.js
else
echo no match
fi
把所有的文件名首字母大写
for file in `ls`;do mv $file `echo $file|sed 's/\b[a-z]/\U&/'`;done;
把所有的文件名首字母小写
for file in `ls`;do mv $file `echo $file|sed 's/\b[A-Z]/\L&/'`;done;