centos7系统安装后的基础优化

 

1、更改远程连接用户和端口

[root@linux-node1 ~]# cp /etc/ssh/sshd_config{,.bak_$(date +%F)}
[root@linux-node1 ~]# vim /etc/ssh/sshd_config
Port 28888                   #更改ssh远程连接端口
PermitRootLogin no    #禁止 root 用户 ssh 远程登录
PermitEmptyPasswords no    #禁止空密码登录
GSSAPIAuthentication no     #为防止 GSSAPI 导致 SSH 连接变慢
UseDNS no                           #禁止使用 DNS

2、关闭 SELINUX

[root@linux-node1 ~]# sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config
[root@linux-node1 ~]# getenforce
Disabled

3、修改字符集

[root@linux-node1 ~]# vim /etc/locale.conf 
LANG="en_US.UTF-8"
[root@linux-node1 ~]# source /etc/locale.conf
[root@linux-node1 ~]# echo $LANG
en_US.UTF-8

4、关闭防火墙和清除iptables规则

[root@linux-node1 ~]# systemctl status firewalld.service
[root@linux-node1 ~]# systemctl stop firewalld.service
[root@linux-node1 ~]# systemctl disable firewalld.service
[root@linux-node1 ~]# iptables -F
[root@linux-node1 ~]# iptables-save

5、设置Linux服务器时间同步

[root@linux-node1 ~]# yum install -y ntpdate
[root@linux-node1 ~]# ntpdate time1.aliyun.com
28 Mar 09:51:17 ntpdate[3090]: step time server 203.107.6.88 offset 165452.420118 sec
[root@linux-node1 ~]# date
Wed Mar 28 09:51:22 CST 2018
[root@linux-node1 ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@linux-node1 ~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate time1.aliyun.com > /dev/null 

6、配置历史命令记录数和账户登录超时环境变量

[root@linux-node1 ~]# echo "export TMOUT=300" >> /etc/profile    #配置连接超时时间控制变量
[root@linux-node1 ~]# echo "export HISTSIZE=5" >> /etc/profile    #命令行的历史记录数量变量
[root@linux-node1 ~]# echo "export HISTFILESIZE=5" >> /etc/profile  #历史记录文件的命令数量变量
[root@linux-node1 ~]# source /etc/profile

7、调整Linux系统文件描述符数量

文件描述符是由无符号整数表示的句柄,进程使用它来标识打开的文件。文件描述符与包括相关信息(如文件的打开模式、文件的位置类型、文件的初始类型等)的文件对象相关联,这些信息被称作文件的上下文。文件描述符的有效范围是0到OPEN_MAX

[root@linux-node1 ~]# ulimit -n
1024
[root@linux-node1 ~]# echo '*    -    nofile    65535' >> /etc/security/limits.conf 
[root@linux-node1 ~]# ulimit -n
65535 

8、锁定系统关键性文件

[root@linux-node1 ~]# chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab 
[root@linux-node1 ~]# mv /usr/bin/chattr /usr/bin/666  #对chattr进行改名,防止服务器攻破被利用

猜你喜欢

转载自www.cnblogs.com/jimmy-xuli/p/9010078.html