系統初始化指令碼

來源:互聯網
上載者:User

今天有幾台伺服器要上線,花時間寫了一個初始化的指令碼,跟大家分享一下。歡迎大家提意見,協助我讓其功能更加完善

#!/bin/bash# author: gm100861# mail: gm100861@gmail.com# blog: http://www.gm100861.com# date: 2013-06-25if [ $(id -u) != 0 ];thenecho "Must be root can do this."exit 9fi# set privilegeschmod 600 /etc/passwdchmod 600 /etc/shadowchmod 600 /etc/groupchmod 600 /etc/gshadowecho "Set important files privileges sucessfully"# yum repo addcat > /etc/yum.repos.d/thrid-repository.repo <<EOF[epel]name=Extra Packages for Enterprise Linux 6 - $basearchbaseurl=http://epel.mirror.ucloud.cn/epel/6/$basearchfailovermethod=priorityenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6[remi]name=Les RPM de remi pour Enterprise Linux $releasever - $basearchbaseurl=http://remi.mirror.ucloud.cnenabled=0gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi[rpmforge]name = RHEL - RPMforge.net - dagbaseurl = http://rpmforge.mirror.ucloud.cn/redhat/el6/en/$basearch/rpmforgeenabled = 1protect = 0gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-daggpgcheck = 0[rpmforge-extras]name = RHEL - RPMforge.net - extrasbaseurl = http://rpmforge.mirror.ucloud.cn/redhat/el6/en/$basearch/extrasenabled = 1protect = 0gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-daggpgcheck = 0EOFyum clean all &>/dev/nullyum makecache &>/dev/nullecho "add thired repository sucessfully"# Turn off unnecessary servicesservice=($(ls /etc/init.d/))for i in ${service[@]}; docase $i insshd|network|syslog|iptables|crond)chkconfig $i on;;*)chkconfig $i off;;esacdone#set ulimitcat >> /etc/security/limits.conf << EOF* soft nofile 65535* hard nofile 65535EOF# set sysctlcat > /etc/sysctl.conf << EOFnet.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0kernel.sysrq = 0kernel.core_uses_pid = 1kernel.msgmnb = 65536kernel.msgmax = 65536kernel.shmmax = 68719476736kernel.shmall = 4294967296net.ipv4.tcp_max_tw_buckets = 6000net.ipv4.tcp_sack = 1net.ipv4.tcp_window_scaling = 1net.ipv4.tcp_rmem = 4096 87380 4194304net.ipv4.tcp_wmem = 4096 16384 4194304net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.netdev_max_backlog = 262144net.core.somaxconn = 262144net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_syncookies = 1net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_fin_timeout = 1net.ipv4.tcp_keepalive_time = 1200net.ipv4.ip_local_port_range = 1024 65535vm.swappiness = 0EOFecho "0 0 * * * /usr/sbin/ntpdate cn.pool.ntp.org &>/dev/null" >>/var/spool/cron/root# set iptablesiptables -Fiptables -Xiptables -Ziptables -I INPUT -i lo -j ACCEPTiptables -A INPUT -p tcp --dport 22 -j ACCEPTiptables -A INPUT -p tcp --dport 80 -j ACCEPTiptables -A INPUT -p tcp --dport 443 -j ACCEPTiptables -A INPUT -p icmp --icmp-type 0 -m limit --limit 3/second --limit-burst 5 -j ACCEPTiptables -A INPUT -p icmp --icmp-type 8 -m limit --limit 3/second --limit-burst 5 -j ACCEPTiptables -A INPUT -p udp --sport 53 -j ACCEPTiptables -A INPUT -p tcp --sport 53 -j ACCEPTiptables -P INPUT DROP#iptables -P FORWARD DROP#iptables -P OUTPUT DROP/etc/init.d/iptables saveecho "All things is init ok! "


本文出自 “吖吖個呸” 部落格,請務必保留此出處http://gm100861.blog.51cto.com/1930562/1229616

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.