CentOS7系统优化

阿里云源(可选)

CentOS7和epel-7

1
2
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

关闭selinux

1
2
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

配置最大文件打开数和用户最大进程数

1
2
3
4
5
6
echo -ne "  
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
" >>/etc/security/limits.conf

ssh优化

1
2
sed -i -e 's/#Port 22/Port 2012/' /etc/ssh/sshd_config
echo "UseDNS no" >>/etc/ssh/sshd_config

停用自带防火墙

1
2
systemctl stop firewalld
systemctl disable firewalld

安装常用工具(可选)

1
yum install net-tools lrzsz lsof telnet wget nmap dos2unix screen tcpdump vim sysstat bind-utils ntpdate -y

命令历史记录(可选)

1
2
3
4
cat >> /etc/profile <<'EOF'
export PROMPT_COMMAND='{ date "+[ %Y%m%d %H:%M:%S `whoami` `echo $SSH_CLIENT`] `history 1 | { read x cmd; echo "$cmd"; }`"; } >> /opt/.history'
EOF
touch /opt/.history && chmod 777 /opt/.history

安装iptables防火墙(可选)

1
yum install iptables-services