Linux Basic optimization:
1. Turn off SELinux
Temporary: [[email protected] ~]# getenforceenforcing[[email protected] ~]# setenforce 0[[email protected] ~]# Getenforcepermissive[[email protected] ~]#
Permanent:
# sed-i ' s#enforcing#disabled#g '/etc/selinux/config
2. System default Level
[Email protected] ~]# tail-n 1/etc/inittabid:3:initdefault:[[email protected] ~]#
3. Streamline boot entry
Need to start the following services, all left off
SSHD Remote Connection Service
Rsyslog Log Service
Network Services
Crond Scheduled Tasks
Sysstat Monitoring System Load Logging (Isostat provides CPU utilization and hard disk throughput Mpstat provides single or multiple processor-related data SAR responsible for collecting, reporting and storing system-active information)
Method:
For i in ' Chkconfig--list|grep-ve ' (crond|sshd|network|rsyslog|sysstat) ' |awk ' {print ' {'} ';d o chkconfig $i off;done
4. Close the firewall (learning environment use)
# service Iptables stop# service iptables Save
5. Setting the display language
[Email protected] ~]# echo $LANGen _us. UTF-8 #中文 [[email protected] ~]# cat/etc/sysconfig/i18nlang= "en_US. UTF-8 "sysfont=" Latarcyrheb-sun16 "[[email protected] ~] #echo $LANG lang=" En_us:en "#英文
6. Time synchronization
Set the start-up time and timing.
Start school, write in/etc/rc.local.
When the school is timed, the Crontab–e is edited and modified.
School Time Command
Ntpdate Time server address
[Email protected] ~]# ntpdate asia.pool.ntp.org[[email protected] ~]# crontab-l59 * * */usr/sbin/ntpdate ASIA.POOL.N tp.org &&/usr/sbin/hwclock-w[[email protected] ~]#
7, to solve the problem of SSH connection slow
Note: We recommend backing up files first
# Vim/etc/ssh/sshd_configusedns nogssapiauthentication no#/etc/init.d/sshd Reload #平滑重启
8. Common variable Settings
# tmout=20 #回话超时时间
# histsize=5 #记录的历史命令的个数
# histfilesize=20 #记录历史命令的行数
Permanent entry into force:
After writing the above command to/etc/profile
# Source/etc/profile #永久生效
9. Adjust the number of Linux system file descriptors
Description: The default value is not sufficient for high concurrency services
[[email protected] ~]# ulimit-n1024 adjustment method: [[email protected] ~]# echo "*-Nofile 65535" > >/etc/security/limits.conf
After exiting the system and then logging in to take effect
10. Kernel optimization
Note: Adapt to most web production environments
Net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_keepalive_time = 600net.ipv4.tcp_keepalive_probes = 3net.ipv4.tcp_keepalive_intvl =15net.ipv4.tcp_ retries2 = 5net.ipv4.tcp_fin_timeout = 2net.ipv4.tcp_max_tw_buckets = 36000net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_max_orphans = 32768net.ipv4.tcp_syncookies = 1net.ipv4.tcp_max_syn_backlog = 16384net.ipv4.tcp_ wmem = 8192 131072 16777216net.ipv4.tcp_rmem = 32768 131072 16777216net.ipv4.tcp_mem = 786432 1048576 1572864net.ipv4.ip_local_port_range = 1024 65000net.ipv4.ip_conntrack_max = 65536net.ipv4.netfilter.ip_conntrack_max= 65536net.ipv4.netfilter.ip_conntrack_tcp_timeout_established=180net.core.somaxconn = 16384net.core.netdev_max_backlog = 16384
11, scheduled cleanup Server temp directory junk files
[Email protected] ~]# find/var/spool/postfix/maildrop/-type F |xargs rm-f
Write a script and clean it regularly:
[[email protected] ~]# mkdir -p /server/scripts[[email protected] ~]# echo "Find /var/spool/postfix/maildrop/ -type f |xargs rm -f" >> /server/scripts/del_file.sh[[email protected] ~]# echo "00 00 * * * /bin/sh /server/scripts/del_file.sh >/dev/null 2>&1 " >>/var/ spool/cron/root[[email protected] ~]# crontab -l00 00 * * * /bin/ sh /server/scripts/del_file.sh >/dev/null 2>&1[[email protected] ~]# Df -ifilesystem inodes iused ifree iuse% Mounted on/dev/sda2 1234576 69428 1165148 6% /tmpfs 125514 1 125513 1% /dev/shm/dev/sda1 51200 44 51156 1% /boot[[email protected] ~]#
12, Hidden Linx version information display
Note: Empty the contents of these two files
[Email protected] ~]# Cat/etc/issuecentos release 6.9 (Final) Kernel \ r on an \m[[email protected] ~]# cat/etc/issue.net CentOS Release 6.9 (Final) Kernel \ r on an \m[[email protected] ~]#
13. Lock System files
[Email protected] ~]# chattr +i/etc/passwd/etc/shadow/etc/group/etc/gshadow/etc/ Inittab Note: After locking all users can not modify the file deletion if you want to be more secure to change the chattr command name [[email protected] ~]# mv/usr/bin/chattr/usr/bin/yanqi01
14. Empty the Virtual account
Look at the old boy's book or blog, not a must
15, through the firewall to set the specified IP can ping the server
16, upgrade the software version of the typical vulnerability
17. Setting of variables
1. Open Text default display line number CentOS edit/ETC/VIMRC on the last line add set Nu Save exit 2, verbose record operation command execution time and account number [[email protected] ~]# Cat/etc/profile Export histtimeformat= "%F%T ' WhoAmI '" #最后添加一行, save exit.
This article is from the "bit accumulation" blog, please be sure to keep this source http://huangyanqi.blog.51cto.com/12622147/1914103
Linux Basic optimization