CentOS-6.5 system basic optimization with optimization script
Optimized content:
(1. Set history
(2. Add common users and set sudo Permissions
(3. Remote root User Login prohibited
(4. Modify the remote port
(5. Streamline startup Server
(6. Disable selinux
(7. Configure iptables
(8. Modify the maximum number of connections ulimit
(9. Do not restart the server by pressing Ctrl + Alt + Del.
(10. Modify the default DNS
(11. install necessary software and update the yum source [epel source]
(12. Update the kernel and software to the latest version.
(13. Optimize Kernel Parameters [adjusted based on actual conditions]
(14. Remove the Last login information
(15. Disable boot to display kernel information
1. Set history
echo' exportHISTFILE=$HOME/.bash_history exportHISTSIZE= 2000 exportHISTFILESIZE= 2000 exportHISTTIMEFORMAT= "%F%T`whoami`" exportPROMPT_COMMAND= "history-a;history-c;history-r;" shopt-shistappend typeset-rPROMPT_COMMAND typeset-rHISTTIMEFORMAT'>/etc/profile.d/history.sh source/etc/profile
2. Add common users and set sudo Permissions
username= 'dyt' password= 'dyt2015' useradd$username;echo$password|passwd--stdin$username sed-i "98a$usernameALL=(ALL)NOPASSWD:ALL" /etc/sudoers
3. Remote root User Login prohibited
sed-i 's/#PermitRootLoginyes/PermitRootLoginno/' /etc/ssh/sshd_config
4. Modify the remote port
sed-i 's/#Port22/Port9527/' /etc/ssh/sshd_config /etc/init.d/sshdrestart
5. Streamline startup Server
for server in `chkconfig--list|egrep-v 'crond|network|rsyslog|sshd|iptables' |awk '{print$1}' `; do chkconfig$serveroff;done
6. Disable selinux
sed-i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config setenforce 0
7. Configure iptables
/etc/init.d/iptablesrestart iptables-F iptables-X iptables-Z iptables-AINPUT-picmp-jACCEPT iptables-AINPUT-ilo-jACCEPT # Allow Remote Access to ssh from an IP address segment iptables-AINPUT-ptcp-mtcp--dport 9527 -s 192.168 . 64.0 / 24 -jACCEPT # Enable 80 Port iptables-AINPUT-Ptcp-mtcp--dropt 80 -jACCEPT # Allow all requests from an IP address iptables-AINPUT-pall-s 124.43 . 56.90 / 30 -jACCEPT iptables-AINPUT-mstate--stateRELATED,ESTABLISHED-jACCEPT iptables-PINPUTDROP iptables-POUTPUTACCEPT iptables-PFORWARDDROP /etc/init.d/iptablessave /etc/init.d/iptablesrestart
8. Modify the maximum number of connections ulimit
# There are many methods, not necessarily this one echo '*-noproc65535' >>/etc/security/limits.conf echo '*-nofile65535' >>/etc/security/limits.conf
9. Do not restart the server by pressing Ctrl + Alt + Del.
sed-i "s/startoncontrol-alt-delete/#startoncontrol-alt-delete/g" /etc/init/control-alt- delete .conf
10. Modify the default DNS
echo "nameserver8.8.8.8" >/etc/resolv.conf echo "nameserver8.8.4.4" >>/etc/resolv.conf
11. install necessary software and update the yum source [epel source]
# Based on your company's situation, only the commonly used software and yum sources are listed here, And the yum source is changed according to the actual situation. yum-yinstallgccgcc-c++openssl-developenssh-clientswgetmakelrzszunzipzipxzntpdatelsoftelnetepel-releasevimtreekernel-develkernel
12. Update the kernel and software to the latest version.
yum-yupgrade
13. Optimize Kernel Parameters [adjusted based on actual conditions]
echo-e "net.core.somaxconn=262144" >>/etc/sysctl.conf echo-e "net.core.netdev_max_backlog=262144" >>/etc/sysctl.conf echo-e "net.core.wmem_default=8388608" >>/etc/sysctl.conf echo-e "net.core.rmem_default=8388608" >>/etc/sysctl.conf echo-e "net.core.rmem_max=16777216" >>/etc/sysctl.conf echo-e "net.core.wmem_max=16777216" >>/etc/sysctl.conf echo-e "net.ipv4.route.gc_timeout=20" >>/etc/sysctl.conf echo-e "net.ipv4.ip_local_port_range=102465535" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_retries2=5" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_fin_timeout=30" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_syn_retries=1" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_synack_retries=1" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_timestamps=0" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_tw_recycle=1" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_tw_reuse=1" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_keepalive_time=120" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_keepalive_probes=3" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_keepalive_intvl=15" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_max_tw_buckets=36000" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_max_orphans=3276800" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_max_syn_backlog=262144" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_wmem=819213107216777216" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_rmem=3276813107216777216" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_mem=94500000915000000927000000" >>/etc/sysctl.conf echo-e "net.ipv4.tcp_slow_start_after_idle=0" >>/etc/sysctl.conf echo-e "vm.swappiness=0" >>/etc/sysctl.conf echo-e "kernel.panic=5" >>/etc/sysctl.conf echo-e "kernel.panic_on_oops=1" >>/etc/sysctl.conf echo-e "kernel.core_pipe_limit=0" >>/etc/sysctl.conf # Iptables Firewall echo-e "net.nf_conntrack_max=25000000" >>/etc/sysctl.conf echo-e "net.netfilter.nf_conntrack_max=25000000" >>/etc/sysctl.conf echo-e "net.netfilter.nf_conntrack_tcp_timeout_established=180" >>/etc/sysctl.conf echo-e "net.netfilter.nf_conntrack_tcp_timeout_time_wait=120" >>/etc/sysctl.conf echo-e "net.netfilter.nf_conntrack_tcp_timeout_close_wait=60" >>/etc/sysctl.conf echo-e "net.netfilter.nf_conntrack_tcp_timeout_fin_wait=120" >>/etc/sysctl.confo
15. Remove the Last Logon Information
touch~/.hushlogin