1. 程式人生 > >系統安裝後的基礎優化

系統安裝後的基礎優化

系統基礎優化

系統安裝後的基礎優化

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進行改名,防止服務器攻破被利用

系統安裝後的基礎優化