系统:Centos7
1.将Linux系统中UID大于等于1000的普通用户都删除
#!/bin/bash
user=$(awk -F: ‘$3>=1000{print $1}’ /etc/passwd)
for i in $user
do
userdel -r $i
done
2.自动优化LINUX内核参数
#!/bin/bash
cat >> /usr/lib/sysctl.d/00-system.conf <<EOF
fs.file-max=65535 #可以分配的文件句柄的最大数目
net.ipv4.tcp_timestamps = 0 #启用时间戳,1代表开启,0代表关闭
net.ipv4.tcp_synack_retries = 5 #
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_tw_recycle =1 #用于快速回收处于TIME_WAIT状态的socket连接
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timout = 30
#net.ipv4.tcp_keepalive_time =120
net.ipv4.ip_local_port_range =1024 65535
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmin = 4096
kernel.sem = 5010 641280 5010 128
net.core.wmem_default = 262144
net.core.wmem_max=262144
net.core.rmem_default=4194304
net.core.rmem_max=4194304
net.ipv4.tcp_fin_timeout =10
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_sack =0
EOF
sysctl -p
3.检测MySQL数据库连接数量
#!/bin/bash
log_file=/var/log/mysql_count.log
user=root
passwd=123456
while:
do
sleep 2
count=`mysqladmin -u “$user” -p “$passwd” status| awk ‘{print $4}’`
Echo “`date +%Y-%m-%d`并发连接数:$count” >>$log_file
done