CentOS6.5 server security reinforcement and performance optimization

Source: Internet
Author: User
This article introduces how to adjust system parameters to increase the usage of system memory, CPU, and kernel resources, and disable unnecessary services and ports to improve system security, make full use of the availability of the system. I learned about Linux and made the following summary labels for system optimization: CentOS

Users who often play with Linux systems know more or less about system parameter optimization and how to enhance system security. some of the default system parameters are conservative, therefore, we can adjust system parameters to increase the usage of system memory, CPU, and kernel resources, and disable unnecessary services and ports to improve system security, make full use of the availability of the system. I learned about Linux and made the following summary on system optimization:
Operating system: CentOS 6.5 _ x64 minimal installation

1. host name settings


Copy codeThe code is as follows:
[Root @ localhost ~] # Vi/etc/sysconfig/network
HOSTNAME = test.com
[Root @ localhost ~] # Hostname test.com # temporarily effective


2. disable SELinux


Copy codeThe code is as follows:
[Root @ localhost ~] # Vi/etc/selinux/config
SELINUX = disabled
[Root @ localhost ~] # Setenforce # temporary effect
[Root @ localhost ~] # Getenforce # View selinux status


3. clear the firewall and set rules


Copy codeThe code is as follows:
[Root @ localhost ~] # Iptables-F # clear firewall rules
[Root @ localhost ~] # Iptables-L # View firewall rules
[Root @ localhost ~] # Iptables-a input-p tcp -- dport 80-j ACCEPT
[Root @ localhost ~] # Iptables-a input-p tcp -- dport 22-j ACCEPT
[Root @ localhost ~] # Iptables-a input-p tcp -- dport 53-j ACCEPT
[Root @ localhost ~] # Iptables-a input-p udp -- dport 53-j ACCEPT
[Root @ localhost ~] # Iptables-a input-p udp -- dport 123-j ACCEPT
[Root @ localhost ~] # Iptables-a input-p icmp-j ACCEPT
[Root @ localhost ~] # Iptables-P INPUT DROP
[Root @ localhost ~] #/Etc/init. d/iptables save


# Enable the corresponding port as needed



4. add common users and perform sudo authorization management


Copy codeThe code is as follows:
[Root @ localhost ~] # Useradd user
[Root @ localhost ~] # Echo "123456" | passwd -- stdin user # set the password
[Root @ localhost ~] # Vi/etc/sudoers # Open the Command with "do" or add all user permissions
Root ALL = (ALL) ALL
User ALL = (ALL) ALL


5. disable root remote logon.


Copy codeThe code is as follows:
[Root @ localhost ~] # Vi/etc/ssh/sshd_config
PermitRootLoginno
PermitEmptyPasswords no # Disable empty password logon
UseDNSno # Disable DNS query


6. disable auto-start services that do not need to be started



7. delete unnecessary system users



8. disable and restart the ctl-alt-delete key combination.


Copy codeThe code is as follows:
[Root @ localhost ~] # Vi/etc/init/control-alt-delete.conf
# Exec/sbin/shutdown-r now "Control-Alt-Deletepressed" # Comment out

9. adjust the file descriptor size


Copy codeThe code is as follows:
[Root @ localhost ~] # Ulimit-n # The default value is 1024.
1024
[Root @ localhost ~] # Echo "ulimit-SHn 102400">/etc/rc. local # set automatic start to take effect

10. remove system-related information


Copy codeThe code is as follows:
[Root @ localhost ~] # Echo "Welcome to Server">/etc/issue
[Root @ localhost ~] # Echo "Welcome to Server">/etc/redhat-release

11. modify the history record


Copy codeThe code is as follows:
[Root @ localhost ~] # Vi/etc/profile #10 change Records
HISTSIZE = 10

12. synchronize system time


Copy codeThe code is as follows:
[Root @ localhost ~] # Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime # set the Shanghai Time zone
[Root @ localhost ~] # Ntpdate cn.pool.ntp.org; hwclock-w # sync time and write to blos hardware Time
[Root @ localhost ~] # Crontab-e # set the task plan to be synchronized at every day
0 ***/usr/sbin/ntpdate cn.pool.ntp.org; hwclock-w

13. kernel parameter optimization


Copy codeThe code is as follows:
[Root @ localhost ~] # Vi/etc/sysctl. conf # add the following parameters at the end
Net. ipv4.tcp _ syncookies = 1 #1: enable SYN Cookies. when a SYN wait queue overflow occurs, enable Cookies to prevent a small number of SYN attacks. The default value is 0.
Net. ipv4.tcp _ tw_reuse = 1 #1 is to enable reuse and allow TIME_AIT sockets to be reused for new TCP connections. the default value is 0.
Net. ipv4.tcp _ tw_recycle = 1 # Number of TCP retransmission failures. the default value is 15. you can release kernel resources by reducing the number of times.
Net. ipv4.ip _ local_port_range = 4096 65000 # port range available for applications
Net. ipv4.tcp _ max_tw_buckets = 5000 # The system maintains the maximum number of TIME_WAIT sockets at the same time. if this number is exceeded, the TIME_WATI socket is immediately cleared and warning information is printed. the default value is 180000.
Net. ipv4.tcp _ max_syn_backlog = 4096 # enter the maximum request queue of SYN flood. the default value is 1024.
Net. core. netdev_max_backlog = 10240 # maximum device queue of data packets allowed to be sent to the queue. the default value is 300.
Net. core. somaxconn = 2048 # maximum number of listen pending requests. the default value is 128.
Net. core. wmem_default = 8388608 # default value of the size of the sending cache
Net. core. rmem_default = 8388608 # accept the default value of the socket buffer size (in bytes)
Net. core. rmem_max = 16777216 # maximum size of the receiving buffer
Net. core. wmem_max = 16777216 # maximum size of the sending buffer
Net. ipv4.tcp _ synack_retries = 2 # Number of retries in the SYN-ACK handshake status. the default value is 5.
Net. ipv4.tcp _ syn_retries = 2 # Number of external SYN handshake retries. the default value is 4.
Net. ipv4.tcp _ tw_recycle = 1 # enable quick recovery of TIME_WAIT sockets in TCP connections. the default value is 0.
Net. ipv4.tcp _ max_orphans = 3276800 # the maximum number of TCP sockets in the system is not associated with any user file handle. if this number is exceeded, the orphan connection is reset immediately and a warning message is printed.
Net. ipv4.tcp _ mem = 94500000 915000000 927000000
Net. ipv4.tcp _ mem [0]: lower than this value, TCP has no memory pressure;
Net. ipv4.tcp _ mem [1]: Enter the memory pressure stage;
Net. ipv4.tcp _ mem [2]: higher than this value, TCP rejects socket allocation. The memory unit is page, which can be adjusted based on the physical memory size. if the memory is large enough, you can adjust it accordingly. The above memory unit is page, not byte.

So far, the basic optimization and adjustment of CentOS 6.5 _ x64 minimal installation system have been completed, and the system needs to be restarted.

This article is from the "Penguin" blog.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.