Linux init script

Source: Internet
Author: User
Tags curl openldap

The following script is used for initialization scripts for Linux systems and can be executed immediately after the server system is installed. The script combined with some of Daniel's parameters, has been passed under CentOS 5.
How to use: Copy it and save it as a shell file, such as init.sh. Upload it to the Linux server and execute SH init.sh. We recommend that you execute the system immediately after installation.
Script code:

#!/bin/bash
# Configure Yum Source
Cd/tmp
Wget-c http://yum.baseurl.org/download/3.4/yum-3.4.3.tar.gz
Tar zxf yum-3.4.3.tar.gz
CD yum-3.4.3
./yummain.py Install Yum-y
Cd..
RM-RF yum-3.4.3*
Sed-i ' [email protected]^[email protected]#[email protected] '/etc/yum.conf
Yum Clean All
Yum Check-update
mv/etc/yum.repos.d/centos-debuginfo.repo/etc/yum.repos.d/centos-debuginfo.repo$ (Date +%m%d)
mv/etc/yum.repos.d/centos-media.repo/etc/yum.repos.d/centos-media.repo$ (Date +%m%d)
mv/etc/yum.repos.d/centos-vault.repo/etc/yum.repos.d/centos-vault.repo$ (Date +%m%d)
# Remove Obsolete RPM Package
If [-Z] $ (cat/etc/redhat-release | grep ' 5\. '); Then
Yum-y groupremove "FTP server" "Text-based Internet" "Windows File Server" "PostgreSQL Database" "News Server" "MySQL Dat Abase "" DNS Name Server "Web server" "Dialup Networking Support" "Mail Server" "Ruby" "office/productivity" "Sound and Vi Deo "x Window System" "X Software Development" "Printing support" "OpenFabrics Enterprise Distribution"
Else
Yum-y groupremove "FTP server" "PostgreSQL database Client" "PostgreSQL database Server" "MySQL database Server" "MySQL D Atabase client "Web Server" "Office Suite and Productivity" "Ruby support" "X Window System" "Printing Client" "desktop*"
Fi
# Update RPM Package
Yum-y Update
# Install Dependencies Package
Yum-y install gcc gcc-c++ make autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2 -devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel Curl Curl-devel E2fspro GS e2fsprogs-devel krb5-devel libidn libidn-devel OpenSSL openssl-devel nss_ldap openldap Openldap-devel Openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool Libtool-ltdl Bison gd-devel vim-enhanced Pcre-devel Zip unzip SendMail
Chkconfig--list | awk ' {print ' Chkconfig "$" Off "} ' >/tmp/chkconfiglist.sh;/bin/sh/tmp/chkconfiglist.sh;rm-rf/tmp/ chkconfiglist.sh
Chkconfig Crond on
Chkconfig irqbalance on
Chkconfig Network on
Chkconfig sshd on
Chkconfig Rsyslog on #CentOS 6
Chkconfig syslog on #CentOS/rhel 5
Chkconfig iptables on
Chkconfig SendMail on
Service SendMail Restart
#/etc/hosts
["$ (hostname-i)"! = "127.0.0.1"] && sed-i "[Email protected]^127.0.0.1\ (. *\) @127.0.0.1 ' hostname ' \[email PR Otected] "/etc/hosts
# Close SELINUX
Setenforce 0
Sed-i ' s/^selinux=.*$/selinux=disabled/'/etc/selinux/config
# Initdefault
Sed-i ' s/^id:.*$/id:3:initdefault:/'/etc/inittab
/sbin/init Q
# PS1
Echo ' ps1= ' \[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\w\[\e[0m\]]\\$ \[\e[33;40m\] "' >>/etc /profile
# Record Command
Sed-i ' S/^histsize=.*$/histsize=100/'/etc/profile
echo "Export prompt_command=" {msg=\$ (History 1 | {read x y; echo \ $y;}); user=\$ (WhoAmI); echo \$ (date \ "+%y-%m-%d%h:%m:%s\"): \ $user: \ ' pwd\ '/:\ $msg----\$ (who am I); } >>/tmp/\ ' hostname\ '. \ ' whoami\ '. History-timestamp ' ">>/root/.bash_profile
# wrong password five times locked 180s
Sed-i ' 4a auth required pam_tally2.so deny=5 unlock_time=180 '/etc/pam.d/system-auth
# alias VI
sed "[email protected] mv=.* @alias mv= ' mv-i ' \nalias [email protected]"/ROOT/.BASHRC
echo ' syntax on ' >>/ETC/VIMRC
#/etc/security/limits.conf
Cat >>/etc/security/limits.conf <<eof
* Soft Nproc 65535
* Hard Nproc 65535
* Soft Nofile 65535
* Hard Nofile 65535
Eof
echo "Ulimit-sh 65535" >>/etc/rc.local
#/etc/sysctl.conf
Sed-i ' s/net.ipv4.tcp_syncookies.*$/net.ipv4.tcp_syncookies = 1/g '/etc/sysctl.conf
Cat >>/etc/sysctl.conf << EOF
fs.file-max=65535
Net.ipv4.tcp_tw_reuse = 1
Net.ipv4.tcp_tw_recycle = 1
Net.ipv4.ip_local_port_range = 1024 65000
Eof
Sysctl-p
If [-Z] $ (cat/etc/redhat-release | grep ' 6\. '); Then
Sed-i ' s/3:2345:respawn/#3:2345:respawn/g '/etc/inittab
Sed-i ' s/4:2345:respawn/#4:2345:respawn/g '/etc/inittab
Sed-i ' s/5:2345:respawn/#5:2345:respawn/g '/etc/inittab
Sed-i ' s/6:2345:respawn/#6:2345:respawn/g '/etc/inittab
Sed-i ' s/ca::ctrlaltdel/#ca:: ctrlaltdel/g '/etc/inittab
Sed-i ' [email protected]=.*[email protected]= ' en_US. UTF-8 "@g '/etc/sysconfig/i18n
Else
Sed-i ' [email protected]^[email protected]#[email protected] '/etc/init/control-alt-delete.conf
Fi
/sbin/init Q
# Set TimeZone
Rm-rf/etc/localtime
Ln-s/usr/share/zoneinfo/asia/shanghai/etc/localtime
# Update Time
Echo ' */5 * * * * */usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1 ' >/var/spool/cron/root;chmod 600/var/spoo L/cron/root
/sbin/service Crond Restart
# iptables
Cat >/etc/sysconfig/iptables << EOF
# Firewall configuration written by System-config-securitylevel
# Manual Customization of this file are not recommended.
*filter
: INPUT DROP [0:0]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [0:0]
: Syn-flood-[0:0]
-A input-i lo-j ACCEPT
-A input-m state--state related,established-j ACCEPT
-A input-p tcp-m state--state new-m TCP--dport 22-j ACCEPT
-A input-p tcp-m state--state new-m TCP--dport 80-j ACCEPT
-A input-p icmp-m limit--limit 100/sec--limit-burst 100-j ACCEPT
-A input-p icmp-m limit--limit 1/s--limit-burst 10-j ACCEPT
-A input-p tcp-m tcp--tcp-flags fin,syn,rst,ack syn-j Syn-flood
-A input-j REJECT--reject-with icmp-host-prohibited
-A syn-flood-p tcp-m limit--limit 3/sec--limit-burst 6-j RETURN
-A syn-flood-j REJECT--reject-with icmp-port-unreachable
COMMIT
Eof
/sbin/service iptables Restart
Source/etc/profile
# # #install Tmux
mkdir Tmux
CD Tmux
Wget-c http://downloads.sourceforge.net/tmux/tmux-1.8.tar.gz
Tar xzf libevent-2.0.21-stable.tar.gz
CD libevent-2.0.21-stable
./configure
Make && make install
Cd.. /
Tar xzf tmux-1.8.tar.gz
CD tmux-1.8
cflags= "-i/usr/local/include" ldflags= "-l//usr/local/lib"./configure
Make && make install
Cd.. /.. /
RM-RF Tmux
If [' getconf word_bit ' = ' + '] && [' getconf long_bit ' = ' 64 ']; Then
Ln-s/usr/local/lib/libevent-2.0.so.5/usr/lib64/libevent-2.0.so.5
Else
Ln-s/usr/local/lib/libevent-2.0.so.5/usr/lib/libevent-2.0.so.5
Fi
# # #install Htop
mkdir Htop
CD Htop
Tar xzf htop-1.0.2.tar.gz
CD htop-1.0.2
./configure
Make && make install
Cd.. /.. /
RM-RF Htop

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.