查看80端口是否被监听
netstat -ntlp |grep 80
lsof | grep :80
查看3306被哪个进程占用
lsof -i :3306
修改root密码
echo "new_password" | passwd --stdin root
============== sed ==================
修改配置文件,关闭SELinux
sed -i /SELINUX/s/enforcing/disabled/g /etc/selinux/config
sed -i 's/old_word/new/g file
打印文件file的400-500行
sed -n '400,500p' file文件名
sed -i ‘s#/usr/local#/usr/src#g’ file
第七行前插入“#注释”
sed -i '7 i\ "#注释"' file.txt
============== awk ==================
日志格式如下:
123.232.208.98 - [10/Sep/2016:16:33:13 +0800] "/thread-14858-1-1.html"
200"http://www.lishiming.net/forum.php?mod=guide&view=my" "Mozilla/5.0
(Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/31.0.1650.63 Safari/537.36 TheWorld 6"
答案:
IP前10名: awk '{print $1}' access.log |sort|uniq -c|sort -rn|head
网址前10名:awk -F '"' '{print $2}’ access.log|sort|uniq -c|head
awk '{print $1}' access.log |sort -n |uniq -c |sort -nr |head -n 10
awk '$8=="500"' access.log |wc -l
awk -F: '/model name/{print $2}' /proc/cpuinfo
============== grep =================
空行所在的行号
grep -n "^$" file1
grep “.*abc$” file1
============== find =================
找到文件,权限修改为644
find /tmp/ -type f |xargs -i chmod 644 {}
找出1天内修改的
find /tmp/ -mtime +1
大于100k的文件,移动到/tmp
find /tmp/ -type f -size +100k |xargs -i mv {} /tmp/
find /tmp/ -type f -size +100k -exec mv {} /tmp \;
find dir/ -mtime +3 -type f -name ".*.log" -exec rm -rf {} \;
find dir/ -type f -size +100k -exec mv {} /tmp \;
============== end ==================
ps aux |grep pid
ifconfig eth0|grep 'inet addr'|awk -F ' ' '{print $2}'|awk -F ':' '{print $2}'
============= crontab ==============
分钟 小时 天 月 周 命令
0 3 * * * /bin/bash /usr/bin/waks.day.sh
0 4 * * 7 /bin/bash /usr/bin/baks_week.sh
===================================
2. 构建简单网站架构模型
设备:13台服务器,要求:有负载均衡和数据库主从
答案:
架构:Keepavlied + lvs + nginx/php + NFS + mysql + redis
keepalived+lvs 使用2台
Nginx+php-fpm使用5台
NFS 使用1台
Mysql双主,并使用keepalived构建高可用 使用2台
Redis 使用1台,用来存session
备份机器使用1台
监控机器使用1台
tar czvf /tmp/abc.tgz /tmp/abc
tar -cvf test.tar $(cat b.txt|tr '\n' ' ')
tar -cvf test.tar `cat b.txt|xargs`
iotop # 查看读写
sar
nload # 看流量
top 按M 查看哪个进程占用内存多
w # 看负载
--------------------
tar -zcvf test.tar.gz test
解压:tar -zxvf test.tar.gz
zip -r test.zip test
解压:unzip test.zip
gzip test
解压: gzip -d test.gz
===============================
3. 写一个脚本将数据库备份并打包至远程服务器192.168.1.1 /backup目录下
答案:
#!/bin/bash
/usr/local/mysql/bin/mysqldump -uroot --default-character-set=utf8 -p'****'
database > /tmp/data_$(date +%F).sql
[ $? -eq 0 ] && gzip /tmp/data_$(date +%F).sql
[ -f /tmp/data_$(date +%F).gz ] && rsync -av -e "ssh -p 22" /tmp/data_$(date
+%F).gz root@192.168.1.1:/backup/
============ mysql =============
备份 mysqldump -uroot -p’***’ test > /tmp/test.sql
恢复mysql -uroot -p’***’ < /tmp/test.sql
-------------------------------
vim /usr/local/sbin/backup.sh
#!/bin/bash
bakdir=/root/mysql_bak
d=`date +%F`
[ -d $bakdir ] || mkdir $bakdir
mysqldump -uroot --default-character-set=utf8 -p'****' letang >$bakdir/$d-
letang.sql
crontab:
0 1 * * * /bin/bash /usr/local/sbin/backup.sh
-------------------------------
0 0 1 1,5,10 * /bin/bash /root/testsoft.sh
30 3 * * * /bin/bash /mydata/scriptweb.sh
============== nginx ==============
启动:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
重启: /usr/local/nginx/sbin/nginx -s stop 关掉再启动
关闭:/usr/local/nginx/sbin/nginx -s stop
升级:/usr/local/nginx/sbin/nginx -s reload
netstat -lnp|awk -F'[ :/]+' '$5~/8088/{print $10}'
检查硬盘sda读写速度的命令是:
dd if=/dev/zero bs=1024 count=1000000 of=/1Gb.file
检查系统IO使用状态的命令是:iostat -d /dev/sda -k 1
查看mysql 是否加入系统启动
chkconfig --list|grep mysql
/etc/sysconfig/network 设置主机名
/etc/sysconfig/network-scripts/ifcfg-eth0 设置DNS
版权声明:本站内容全部来自于腾讯微信公众号,属第三方自助推荐收录。《linux下实用的命令组合》的版权归原作者「十年流水账」所有,文章言论观点不代表Lambda在线的观点, Lambda在线不承担任何法律责任。如需删除可联系QQ:516101458
文章来源: 阅读原文
十年流水账微信公众号:yes5144
手机扫描上方二维码即可关注十年流水账微信公众号