CentOS 6.5 initialization optimization script

Source: Internet
Author: User

CentOS 6.5 initialization optimization script
#!/bin/bashecho"This is the system initialization script. Run it with caution! "input_fun(){OUTPUT_VAR=$1INPUT_VAR=""while[-z$INPUT_VAR];doread-p"$OUTPUT_VAR"INPUT_VARdoneecho$INPUT_VAR}input_again(){MYHOSTNAME=$(input_fun"pleaseinputthehostname:")DOMAINNAME=$(input_fun"pleaseinputthedomainname:")CARD_TYPE=$(input_fun"pleaseinputcardtype(eth0):")IPADDR=$(input_fun"pleaseinputipaddress(192.168.100.1):")NETMASK=$(input_fun"pleaseinputnetmask(255.255.255.0):")GATEWAY=$(input_fun"pleaseinputgateway(192.168.100.1):")MYDNS1=$(input_fun"pleaseinputDNS1(114.114.114.114):")MYDNS2=$(input_fun"pleaseinputDNS2(8.8.4.4):")}input_againMAC=$(ifconfig$CARD_TYPE|grep"HWaddr"|awk-F[""]+'{print$5}')#SETCOMPUTERNAMEcat>/etc/sysconfig/network<<ENDFNETWORK=yesHOSTNAME=$MYHOSTNAMEENDFcat>/etc/sysconfig/network-scripts/ifcfg-$CARD_TYPE<<ENDFDEVICE=$CARD_TYPEBOOTPROTO=staticHWADDR=$MACNM_CONTROLLED=yesONBOOT=yesTYPE=EthernetIPV6INIT=noIPADDR=$IPADDRNETMASK=$NETMASKGATEWAY=$GATEWAYENDF/etc/init.d/networkrestartcat>/etc/hosts<<ENDF127.0.0.1$MYHOSTNAME$MYHOSTNAME.$DOMAINNAMElocalhost$IPADDR$MYHOSTNAME$MYHOSTNAME.$DOMAINNAMElocalhostENDFcat>/etc/resolv.conf<<ENDFdomain$DOMAINNAMEsearch$DOMAINNAMEnameserver$MYDNS1nameserver$MYDNS2ENDF# Disable SEKINUXsed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/sysconfig/selinuxsetenforce0# Modifying the number of opened filesecho"*softnofile66666">>/etc/security/limits.confecho"*hardnofile66666">>/etc/security/limits.conf# Optimizing Kernel Parameterscat>>/etc/sysctl.conf<<ENDFnet.ipv4.tcp_max_syn_backlog=65536net.core.netdev_max_backlog=32768net.core.somaxconn=32768net.core.wmem_default=8388608net.core.rmem_default=8388608net.core.rmem_max=16777216net.core.wmem_max=16777216net.ipv4.tcp_timestamps=0net.ipv4.tcp_synack_retries=2net.ipv4.tcp_syn_retries=2net.ipv4.tcp_tw_recycle=1#net.ipv4.tcp_tw_len=1net.ipv4.tcp_tw_reuse=1net.ipv4.tcp_mem=94500000915000000927000000net.ipv4.tcp_max_orphans=3276800net.ipv4.ip_local_port_range=102465535ENDFsysctl-p# Shut Down services not used by the Systemforserverin`chkconfig--list|grep3:on|awk'{print$1}'`dochkconfig--level3$serveroffdoneforserverincrondnetworkrsyslogsshddochkconfig--level3$serverondone# Adding users and sudo Elevation of Privilegeuser_add(){USERNAME=$(input_fun"pleaseinputnewusername:")useradd$USERNAMEpasswd$USERNAME}user_addchmod+w/etc/sudoersecho"$USERNAMEALL=(ALL)ALL">>/etc/sudoerschmod-w/etc/sudoers# Set Time and time zone Synchronizationyum-yinstallntpdate/usr/sbin/ntpdatetime.nist.govecho"*/5****root/usr/sbin/ntpdatetime.nist.gov1>/dev/null2>&1">>/var/spool/cron/root# Configure SSHDsed-i'/^#Port/s/#Port22/Port65535/g'/etc/ssh/sshd_configsed-i'/^#UseDNS/s/#UseDNSyes/UseDNSno/g'/etc/ssh/sshd_configsed-i's/#PermitRootLoginyes/PermitRootLoginno/g'/etc/ssh/sshd_configsed-i's/#PermitEmptyPasswordsno/PermitEmptyPasswordsno/g'/etc/ssh/sshd_configiptables-AINPUT-ptcp--dport65535-jACCEPT/etc/init.d/sshdrestart

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.