1.安装系统
安装系统的时候要选择英语,不要安装中文
安装系统的时候选择最小化安装,除了smart card support不选之外,其他全部选择
#选择安装包时应该按最小化原则,即不需要的或者不确定是否需要的就不安装,这样可以最大程度上确保系统安全
安装系统的时候要把网络打开
安装完成后先关闭selinux
vi /etc/selinux/config
把SELINUX=enforcing
修改为
SELINUX=disabled根据实际情况,决定是否关闭系统防火墙(如果是云主机,或者交换机上面做了安全策略,那么就把防火墙关闭)
systemctl disable firewalld.service
2.执行以下命令安装一些系统必需软件并更新系统(外网环境)
yum groupinstall "Compatibility libraries" "Base" "Development tools" -y
yum groupinstall "debugging Tools" "Dial-up Networking Support" -y
yum install tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs -y
yum install psmisc net-tools bash-completion vim-enhanced -y
yum install epel-release -y
yum update -y
外网环境:
如果yum安装软件慢的话,就更新yum源,如果不慢就不用改
更改YUM源命令
curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
内网环境:
不要永久挂载centos镜像 重启系统会进入紧急模式
3.精简系统开机启动程序
systemctl list-unit-files |grep enable|egrep -v "sshd.service|crond.service|sysstat|rsyslog|^NetworkManager.service|irqbalance.servide"|awk '{print "systemctl disable",$1}'|bash
执行完成后,重启计算机,然后使用命令
systemctl list-unit-files |grep enable
查看开机启动了哪几个服务,如果是以下服务就说明命令执行成功了
autovt@.service enabled
crond.service enabled
getty@.service enabled
NetworkManager.service enabled
rsyslog.service enabled
sshd.service enabled
sysstat.service enabled
4.设置时间同步
在计划任务里面添加
* */12 * * * /usr/sbin/ntpdate ntp3.aliyun.com >/dev/null 2>&1
每12个小时同步一次时间
5.修改最大文件描述符
先使用命令
ulimit -n
查看当前文件描述符是多少,如果是65535就不需要修改,如果小于65535就需要修改
vi /etc/security/limits.conf
在最后一行的上面添加
* - nofile 65535
优化系统内核(如果使用阿里云,不用修改这里的设置,因为阿里云已经修改好了)
添加这几个参数的作用是为了加大网络吞吐量和防止网络攻击
修改/etc/sysctl.conf文件,在文件最后输入以下内容
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
重启后,想查看有没有生效就进到/pro/sys/net目录里面查找对应的文件,查看内容即可
清除系统版本信息,输入以下命令
>/etc/issue
>/etc/issue.net
如果这俩个文件都为空就表示修改成功了
6.使用命令ssh-keygen产生公钥私钥对,正式服务器,不要使用密码登录,都使用密钥进行登录
或者使用生成随机16大小写字母数字符号组合位密码作为密码
https://blog.csdn.net/IT_ZRS/article/details/125853404?spm=1001.2014.3001.5506
修改ssh配置文件,
注意:刚安装好系统,先不要修改65行,等把所有要使用密钥连接这台机器的其他主机,都配置好可以使用密钥正常连接这台机器以后,在把65行修改成no
vi /etc/ssh/sshd_config
找到43行,修改成这样,允许使用SSH KEY连接
PubkeyAuthentication yes
65行,不允许使用密码连接
PasswordAuthentication no #{yes}
79行,改为no,加快连接速度
GSSAPIAuthentication no
115行,改为no,加快连接速度
UseDNS no
7.锁定关键系统文件
chattr +i /etc/passwd
charrt +i /etc/shadow
以上修改完成后,重启计算机,重启完后在验证一下上面的修改有没有成功,避免出现问题