#!/bin/bash#author:yuxiaoguang#date:2016/5/22# the kernel is not upgraded when updating the system using Yum -y update yum -y update# Remove the unused system default User (cannot delete postfix account, this user will affect the tar compressed backup) userdel admuserdel lpuserdel syncuserdel Shutdownuserdel haltuserdel newsuserdel uucpuserdel operatoruserdel gamesuserdel gopher# Remove the unused system default group groupdel admgroupdel lpgroupdel newsgroupdel uucpgroupdel gamesgroupdel dipgroupdel pppusersgroupdel popusersgroupdel slipusers# Lock User Passwd -l mailpasswd -l nobodypasswd -l ftp# Use the chattr command to prevent a critical file in the system from being modified, chattr -i can be restored chattr +i /etc/passwdchattr +i /etc/shadowchattr +i /etc/hostschattr +i /etc /resolv.confchattr +i /etc/fstabchattr +i /etc/sudoers# Installation System Required Package Yum -y install make gcc-c++ cmake bison-devel ncurses-devel net-snmp sysstat dstat iotop lrzsz flex byAcc libpcap libpcap-devel nfs-utils ntp zip unzip xz wget vim lsof bison openssh-clients# Sync Time Ntpdate cn.pool.ntp.orghwclock --systohcecho -e "0 0 * * * /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null" >> /var/spool/cron/root# system service #chkconfig anacron off (MySQL initialization is unsuccessful after disabling) chkconfig auditd offchkconfig iptables onchkconfig ip6tables offchkconfig Snmpd onchkconfig ntpd onchkconfig ntpdate onchkconfig cups offchkconfig acpid offchkconfig apmd offchkconfig atd offchkconfig autofs offchkconfig avahi-daemon offchkconfig bluetooth offchkconfig cpuspeed Offchkconfig firstboot offchkconfig gpm offchkconfig haldaemon offchkconfig hidd offchkconfig hplip offchkconfig isdn offchkconfig lm_sensors offchkconfig messagebus off# Close selinuxsed -i ' s/^selinux=.*$/selinux=disabled/' /etc/selinux/config# change the maximum number of processes in the system cat >> /etc /security/limits.conf << eof* soft nproc unlimited* hard nproc unlimited* soft nofile 65535* hard nofile 65535eof# change the maximum number of processes in the system cat >> /etc/security/limits.d/90-nproc.conf << EOF* soft nproc unlimited* hard nproc unlimited* soft nofile 65535* hard nofile 65535eof# The user, IP address, Shell command, and detailed operation time of the logged in system can be recorded in detail, and the information is stored in a secure place in a file for system audit and troubleshooting. Cat >> /etc/profile << eofuser_ip= ' who -u am i 2>/dev/ null| awk ' {print $NF} ' |sed -e ' s/[()]//g ' histdir=/usr/etc/.historyif [ -z $USER _ip ]thenuser_ip= ' hostname ' fiif [ ! -d $HISTDIR ]thenmkdir -p $HISTDIRchmod 777 $HISTDIRfiif [ ! -d $HISTDIR/${logname} ]thenmkdir -p $HISTDIR/${logname}chmod 300 $HISTDIR /${logname}fiexport histsize=2000dt= ' date +%y%m%d_%h%m%s ' export histfile= "$HISTDIR/${logname}/$ {user_ip}.history. $DT "export histtimeformat=" [%y.%m.%d %h:%m:%s] "chmod 600 $HISTDIR/ ${logname}/*.history* 2>/dev/nullulimit -shn 65535ulimit -shu unlimitedulimit -SHd unlimitedulimit -SHm unlimitedulimit -SHs unlimitedulimit -SHt unlimitedulimit -shv unlimitedeof# Change the VI alias, change the default display line number, display the terminal color CAT&NBSP;>>&NBSP;&NBSP;/ETC/BASHRC << eofexinit= ' set nu showmode expandtab softtabstop=4 shiftwidth=4 ' Export exiniteditor=vimexport editoralias vi= ' vim ' ps1= ' \[\033[01;32m\][\[\033[01;31m\]\u\[\033[ 01;33m\]@\[\033[01;31m\]\h \[\033[01;33m\]\w\[\033[01;32m\]]\$ \e[0m ' eofsource /etc/bashrc# optimized system core Sysctl.confmodprobe bridgelsmod|grep bridgemodprobe ip_conntrackcat >> /etc/sysctl.conf < < eofnet.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_ fin_timeout = 5 net.ipv4.tcp_max_tw_buckets = 20000net.ipv4.ip_local_port_range = 1024 65000net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_max_orphans = 262144net.ipv4.tcp_ keepalive_time = 30net.core.rmem_max = 8388608net.core.rmem_default = 65536net.core.wmem_max = 8388608net.core.wmem_default = 65536net.ipv4.tcp_mem = 8388608 8388608 8388608net.ipv4.tcp_rmem = 4096 87380 8388608net.ipv4.tcp_wmem = 4096 65536 8388608vm.swappiness =5eofsysctl -p# hiding server System Information mv /etc/issue /etc/issuebakmv /etc/issue.net /etc/issue.netbak# installation htopcd /softwget -c http://hisham.hm/ htop/releases/1.0.3/htop-1.0.3.tar.gz tar zxvf htop-1.0.3.tar.gzcd htop-1.0.3./ configuremake && make installrm -rf /soft/htop-1.0.3# installation Iftopcd /softwget -c http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gztar zxvf iftop-0.17.tar.gzcd iftop-0.17./configuremake && make installrm -rf / soft/iftop-0.17
This article is from the "light-ops commune" blog, please be sure to keep this source http://gugpu.blog.51cto.com/3002132/1775955
Linux System initialization scripts