Centos生产环境运维常用命令

﹏ヽ暗。殇╰゛Y 2023-01-18 04:18 217阅读 0赞

Centos生产环境运维常用命令

1、防火墙

  1. #1、查看防火墙状态:
  2. systemctl status firewalld
  3. #2、开启防火墙:
  4. systemctl start firewalld
  5. #3、查看防火墙状态:
  6. systemctl status firewalld
  7. #4、开放|移除某个端口:
  8. firewall-cmd --permanent --zone=public --add|remove-port=3306-3310/tcp
  9. #5、重启防火墙:
  10. firewall-cmd --reload
  11. #6、查看已开放端口:
  12. firewall-cmd --zone=public --list-ports
  13. #7、设置firewalld开机自启动:
  14. systemctl enable firewalld

2、Python

  1. #1、flask start.sh
  2. nohup python3 app.py >> App.log 2>&1 &
  3. #2、根据端口杀进程
  4. netstat -lnp|grep port
  5. kill -9 port
  6. #2.1、根据端口杀进程 shutdown_port.sh脚本
  7. read -p "Please input a need to kill port : " port
  8. pid=$(netstat -anp|grep $port |awk '{printf $7}'|cut -d/ -f1)
  9. kill -9 $pid
  10. #3、linux后台不停止执行python脚本文件
  11. nohup python3 -u demo.py > demo.log 2>&1 &

3、Vim

  1. #1、删除一行
  2. dd
  3. #2、清空日志文件
  4. truncate -s 0 demo.log

4、Crontab

  1. #1、bak.sh(备份/home文件到/bak下,备份MySQL全部数据库到/bak下)
  2. #!/bin/bash
  3. #----------------------------------------------------
  4. #Bak File
  5. #currTime=$(date +"%Y-%m-%d %T")
  6. currTime=$(date +"%Y-%m-%d")
  7. tar -czvf /bak/BaiduYunOs_$currTime-Bak.tar.gz /home
  8. #----------------------------------------------------
  9. #Bak Database
  10. mysqldump -h 127.0.0.1 -P 3306 -u root -pXXXXX --all-databases > /bak/backdb_$currTime-bak.sql
  11. #----------------------------------------------------
  12. #2、每周六凌晨3点执行bak.sh
  13. crontab -e
  14. #!/bin/bash
  15. 0 3 * * 6 xxxx./bak.sh

5、Linux

  1. #1、添加普通用户,修改密码
  2. su root
  3. chattr +i /etc/passwd
  4. useradd mocha
  5. passwod mocha
  6. #2、禁止root用户ssh
  7. vim /etc/ssh/sshd_config
  8. 修改
  9. PermitRootLogin no
  10. MaxAuthTries 3
  11. 保存退出后重启sshd服务
  12. systemctl restart sshd.service
  13. #3、查看无效登录次数、IP用户
  14. grep "Failed password for invalid user" /var/log/secure | awk '{print $13}' | sort | uniq -c | sort -nr | more

发表评论

表情:
评论列表 (有 0 条评论,217人围观)

还没有评论,来说两句吧...

相关阅读