[root@bash ~]# cat /etc/redhat-release //查看版本内核 CentOS Linux release 7.5.1804 (Core) date是查看时间 crontab -l //查看有没有定时任务 crontab -e //添加定时任务 ; //在两个shell命令之间用;隔离可以一次执行两条shell
sed -i '/SELINUX/{s/permissive/disabled/}' /etc/selinux/config
原理:通过检测不同版本系统内核,用不同版本的关闭防火墙的方式来关闭防火墙 if egrep "7.[0-9]" /etc/redhat-release &>/dev/null; then systemctl stop firewalld systemctl disable firewalld elif egrep "6.[0-9]" /etc/redhat-release &>/dev/null; then service iptables stop chkconfig iptables off fi
if ! grep HISTTIMEFORMAT /etc/bashrc; then echo 'export HISTTIMEFORMAT=" %F %T `whoami` "' >> /etc/bashrc fi 日期 时间 [root@bash ~]# export HISTTIMEFORMAT=" %F %T `whoami` " [root@bash ~]# history 1 2023-03-29 08:51:28 root cat /etc/redhat-release 2 2023-03-29 08:59:07 root export HISTTIMEFORMAT=" %F %T `whoami` " 3 2023-03-29 08:59:11 root history
if ! grep "TMOUT=600" /etc/profile &>/dev/null; then echo " export TMOUT=600" >> /etc/profile fi 例如600秒未操作就断开连接
sed -i 's/#PermitRootLogin yes/PermitRootLogin no' /etc/ssh/sshd_config
原理,定时任务的标准的输出和报错会相当前用户发送一个邮件,邮件存放在/var/mail/ 久而久之会占用许 多磁盘空间,把存放在/etc/crontab 下发送的用户root替换成空,就找不到发送的用户,就不会发送 sed -i 's/^MAILTO=root/MAILTO=""' /etc/crontab
if ! grep "* soft nofile 65535" /etc/security/limits.conf &>/dev/null; then cat >> /etc/security/limits.conf <<EOF * soft nofile 65535 * hard nofile 65535 EOF fi
cat >> /etc/sysctl.conf << EOF net.ipv4.tcp_syncookies = 1 //防止sync洪水 0为关闭 net.ipv4.tcp_max_tw_buckets =20480 //最大的队列长度 net.ipv4.tcp_max_syn_backlog = 20480 //接受syn的最大长度 net.core.netdev_max_backlog = 262144 //最大网卡连接 net.ipv4.tcp_fin_timeout = 20 //4次握手超时缩短一下
echo "0" > /proc/sys/vm/swappiness 这里面是权重值,权重值越大,swap几率就越大,越小,swap几率就越小 设置0就尽可能不使用swap
yum install -y gcc make autoconf vim sysstat net-tools iostat iftop iotp lrzsz
yum install -y doc2unix windows下写的脚本转为unix linux格式 doc2unix 文件名 转换格式 sourc /etc/bashrc