在公司搭建网站服务器时写了这个脚本,是基于CentOS 6 Minimal版本的。。。 #!/bin/bash ########################## Written By Qitan #################################### ################## BLOG: http://blog.catjia.com ################################# #################### EMAIL: qqing_lai@hotmail.com ############################## ########################## DATE: 2011-11-09 #################################### PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH SRC=`find / -name qq_lamp.sh |sed 's/qq_lamp.sh//g'` FETI=/usr/local/fetion SCRI=/usr/local/sbin # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to setup operation system" exit 1 fi clear echo -e "33[7m" printf "===========================================================================n" printf " SETUP OPERATION SYSTEM AND INSTALL LAMP--WRITTEN BY EYO-QITAN. n" printf " Email: qqing_lai@hotmail.com n" printf " Blog: http://blog.catjia.com Website: www.goego.net n" printf " Install_Log File: qq_lamp.log Path: /root n" printf "===========================================================================n" echo -e "33[0m" sleep 1 printf "n" echo -e "33[7m" printf " Are you sure to install LAMP (it will continue after 5sec)? [y/n]: " echo -e "33[0m" read -t 5 -n 1 qq_lamp if [[ $qq_lamp != n ]]; then echo -e "33[7m" printf "###########################################################################n" printf "Warning:You should download ZendGuardLoader(zend optimizer) manually first!n" printf "###########################################################################n" echo -e "33[0m" printf "Would you download ZendGuardLoader manually? (Continue install after 20sec) [y/n]:" read -t 20 down if [[ $down == y ]]; then printf "n" echo -e "33[7m" printf "nInstall exit, please download ZendGuardLoader manually first, and MOVE to $script, then rerun this script... n" echo -e "33[0m" exit 0 fi sleep 1 ######## Warning: It will FORMAT The Partition Which Selected.############## printf "nWhich partition would you want to mount to /data (it will continue after 20sec without input)?" read -t 20 -p "(Default Partition: /dev/sda5):" parti if [ "$parti" = "" ]; then parti="/dev/sda5" fi #printf "n==================================================================n" #printf "nWarning: It Will FORMAT The Partition You Selected, If Install Continue ? [y/n]:n" #printf "n==================================================================n" #read -n 1 formatpar #if [[ $formatpar != n ]]; then #printf "Format Partition Which You Selected...n" #mkfs.ext4 $parti #else # exit 1 #fi #Create Data Directory mkdir /data/ && echo "$parti /data/ ext4 defaults 0 0" >> /etc/fstab mount -a mkdir -p /data/www/{logs,wwwroot} && mkdir -p /data/mysql/data printf "nPlease input an E-mail to receive Notification:" read -t 20 -p "(Default E-mail: 617526722@qq.com):" re_mail if [ "$re_mail" = "" ]; then $re_mail="617526722@qq.com" fi printf "nPlease input Mobile NO. to send and receive Notification:" read -t 20 -p "(Default Mobile NO.: 12345678900):" mobile if [ "$mobile" = "" ]; then $mobile="12345678900" fi printf "nPlease input Fetion Password:" read -t 20 -p "(Default Password: passwd99):" mpasswd if [ "$mpasswd" = "" ]; then $mpasswd="passwd99" fi printf "nWould you install Desktop Environment and VNCServer? [y/n]:" read -t 10 -p "(Default: n):" desk if [ "$desk" = "" ]; then desk="n" fi printf "nWhere would you install LAMP (it will continue install after 20sec without input)?" read -t 20 -p "(Default Dir: /usr/local):" dir if [ "$dir" = "" ]; then dir="/usr/local" fi printf "nPlease input hostname (it will continue after 20sec without input):" read -t 20 -p "(Default hostname: www.goego.net):" hostname if [ "$hostname" = "" ]; then hostname="www.goego.net" fi sed -i '/HOSTNAME/d' /etc/sysconfig/network echo "HOSTNAME=$hostname" >> /etc/sysconfig/network printf "nHow much of your Memory: n" printf " a. mem <= 64M n b. mem = 128M n c. mem = 512M n d. mem = 1-2G n e. mem >= 4G n Please Select [a, b, c, d, e]:" read -t 20 -p "(Default Select: e):" mem case "$mem" in a) mycnf="my-small.cnf";; b) mycnf="my-medium.cnf";; c) mycnf="my-large.cnf";; d) mycnf="my-huge.cnf";; ""|e) mycnf="my-innodb-heavy-4G.cnf";; esac printf "nPlease Set MySQL Password for root (it will continue after 20sec without input):" read -t 20 -p "(Default Password: eyoadmin):" rpass if [ "$rpass" = "" ]; then rpass="eyoadmin" fi # printf "nCreate MySQL Database (it will continue after 20sec without input):" # read -t 20 -p "(Default Database: eyo):" db # if [ "$db" = "" ]; then # db="eyo" # fi # printf "nCreate an user for $db Database (it will continue after 20sec without input):" # read -t 20 -p "(Default Database User: eyoadmin):" dbser # if [ "$dbser" = "" ]; then # dbser="eyoadmin" # fi printf "nPlease Setup MySQL Password for eyoadmin (it will continue after 20sec without input):" read -t 20 -p "(Default Password: eyoadmin):" passwd if [ "$passwd" = "" ]; then passwd="eyoadmin" fi printf "nPlease Setup FTP User Name(it will continue after 20sec without input):" read -t 20 -p "(Default User Name: qitan):" ftper if [ "$ftper" = "" ]; then ftper="qitan" fi printf "nPlease Setup FTP User Password (it will continue after 20sec without input):" read -t 20 -p "(Default User Password: qitan@99):" ftpasswd if [ "$ftpasswd" = "" ]; then ftpasswd="qitan@99" fi # Check if MySQL already running rsql=`ps -ef |grep mysqld |awk '{if($3==1)print $0}' |awk '{if($1="root")print $3}'` if [ "$rsql" = "1" ]; then printf "MySQL already running, would you stop and remove it? Warning: it will DELETE all Databases. (Continue after 20sec) [y/n]:n" read -t 20 -p "(Default: y):" unsql else unsql=yes fi printf "Would you change default repo to 163 repo? [y/n]:n" read -t 20 -p "(Default: n):" repo case "$repo" in y) repos="yes";; ""|n) repos="no";; esac else exit 0 fi # Setup Firewall chkconfig iptables off /etc/init.d/iptables stop sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config chkconfig sshd on #################### Off services unnecessary --Begin ########################## service_all_list=( NetworkManager acpid atd bluetooth cups auditd avahi-daemon fcoe ip6tables iptables iscsi iscsid lldpad lvm2-monitor mdmonitor netfs nfslock rpcbind rpcgssd rpcidmapd udev-post ) service_all_len=${#service_all_list[*]} i=0 while [ $i -lt $service_all_len ] do chkconfig ${service_all_list[$i]} off /etc/init.d/${service_all_list[$i]} stop let i++ done chkconfig network on #################### Off services unnecessary --End ########################## # Check if network is working # Network cannot work, setup follow: ping -c 3 www.baidu.com > /dev/null 2>&1 if [ $? != 0 ]; then clear echo -e "33[7m" printf "===========================================================================n" printf " SETUP OPERATION SYSTEM AND INSTALL LAMP--WRITTEN BY EYO-QITAN. n" printf " Email: qqing_lai@hotmail.com Website: www.goego.net n" printf " Install Log File: qq_lamp.log Path: /root n" printf "===========================================================================n" echo -e "33[0m" printf "n" echo -e "33[7m" printf " Your Network Cannot Work, Would You Setup First? n (Setup will start after 10sec) [y/n]: " echo -e "33[0m" read -t 10 -n 1 setnet if [[ $setnet != n ]]; then printf "nWhich Network Adapter would be setup [eth0] [eth1] [eth2] [...]:" read -t 20 -p "(Default Network Adapter: $eth_hw):" eth_hw if [ "$eth_hw" = "" ]; then eth_hw="eth0" fi printf "nPlease input ip address (it will continue after 20sec without input):" read -t 20 -p "(Default IP: 192.168.10.222):" ipaddr if [ "$ipaddr" = "" ]; then ipaddr="192.168.10.222" fi printf "nPlease input broadcast (it will continue after 20sec without input):" read -t 20 -p "(Default broadcast: 192.168.10.255):" broadcast if [ "$broadcast" = "" ]; then broadcast="192.168.10.255" fi printf "nPlease input netmask (it will continue after 20sec without input):" read -t 20 -p "(Default netmask: 255.255.255.0):" netmask if [ "$netmask" = "" ]; then netmask="255.255.255.0" fi printf "nPlease input network (it will continue after 20sec without input)" read -t 20 -p "(Default network: 192.168.10.0):" network if [ "$network" = "" ]; then network="192.168.10.0" fi printf "nPlease input gateway (it will continue after 20sec without input):" read -t 20 -p "(Default gateway: 192.168.10.1):" gateway if [ "$gateway" = "" ]; then gateway="192.168.10.1" fi printf "nPlease input Main DNS (it will continue after 20sec without input):" read -t 20 -p "(Default Main DNS: 211.162.78.2):" dns1 if [ "$dns1" = "" ]; then dns1="211.162.78.2" fi printf "nPlease input From DNS (it will continue after 20sec without input):" read -t 20 -p "(Default From DNS: 211.162.78.1):" dns2 if [ "$dns2" = "" ]; then dns2="211.162.78.1" fi sleep 1 cat > /etc/sysconfig/network-scripts/ifcfg-$eth_hw <<EOF DEVICE="$eth_hw" ONBOOT="yes" EOF ifup $eth_hw hwaddr=`ifconfig |grep $eth_hw |awk '{print $5}'` cat >> /etc/sysconfig/network-scripts/ifcfg-$eth_hw <<EOF BOOTPROTO=static HWADDR=$hwaddr IPADDR=$ipaddr BROADCAST=$broadcast NETMASK=$netmask NETWORK=$network GATEWAY=$gateway EOF /etc/init.d/network restart cat > /etc/resolv.conf <<EOF nameserver $dns1 nameserver $dns2 EOF else printf "n" exit 0 fi fi # Check if network is ok again ping -c 3 www.baidu.com > /dev/null 2>&1 if [ $? != 0 ]; then printf "`date` Network cannot work, install will quit, please check manually.n" |tee /root/qq_lamp.log exit 0 fi yum -y install wget ftp ntp kernel kernel-devel && ntpdate time.nist.gov # Install Desktop Environment and VNC Server if [ "$desk" = "y" ]; then yum -y groupinstall "Desktop" "X Window System" && yum -y install vnc-server sed -i '$ aVNCSERVERS="1:root"' /etc/sysconfig/vncservers sed -i 's/twm/gnome-session/g' /root/.vnc/xstartup chkconfig vncserver on vncserver <<EOF eyoqqing eyoqqing EOF # /etc/init.d/vncserver start fi # Changge repo to 163 if [ "$repos" = "yes" ]; then wget -c http://mirrors.163.com/.help/CentOS6-Base-163.repo && mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak && mv CentOS6-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo fi #################################### Install LAMP... ########################### # Download Files... ############################################################################ Warning: Cannot download zend, you should download it manually first !!! ############################################################################ function func() { if [ -s $file ]; then printf "n" echo "$file Found." else printf "n" echo "$file not found, download now..." wget -c $url if [ -s $file ]; then echo "$file already download." printf "n" else echo -e "33[7m" echo "$file cannot download, please download manually and rerun this script." >> /root/qq_lamp.log echo -e "33[0m" exit 0 fi fi } function file_down() { local file=httpd-2.2.21.tar.bz2 url=http://labs.renren.com/apache-mirror//httpd/httpd-2.2.21.tar.bz2 func local file=cmake-2.8.6.tar.gz url=http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz func local file=mysql-5.5.16.tar.gz url=http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.16.tar.gz/from/http://mirror.services.wisc.edu/mysql/ func local file=php-5.3.8.tar.bz2 url=http://cn2.php.net/get/php-5.3.8.tar.bz2/from/this/mirror func local file=phpMyAdmin-3.4.7-all-languages.tar.bz2 url=http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.7/phpMyAdmin-3.4.7-all-languages.tar.bz2 func local file=xcache-1.3.2.tar.gz url=http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz func local file=ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz url=http://blog.catjia.com/wp-content/uploads/2012/02/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz func local file=rpmforge-release-0.5.2-2.el6.rf.i686.rpm url=http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm func } # function file_down() file_down # Download files from ftp server #ftp -n <<EOF #open 192.168.10.228 #user qitan qitan@228 #bin #get cmake-2.8.6.tar.gz #get httpd-2.2.21.tar.bz2 #get mysql-5.5.16.tar.gz #get php-5.3.8.tar.bz2 #get phpMyAdmin-3.4.7-all-languages.tar.bz2 #get rpmforge-release-0.5.2-2.el6.rf.i686.rpm #get xcache-1.3.2.tar.gz #get ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz #bye #EOF ############################################################################ Warning: Cannot download zend, you should download it manually first !!! ############################################################################ # wget -c http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.16.tar.gz/from/http://mirror.services.wisc.edu/mysql/ http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.7/phpMyAdmin-3.4.7-all-languages.tar.bz2 http://labs.renren.com/apache-mirror//httpd/httpd-2.2.21.tar.bz2 http://cn2.php.net/get/php-5.3.8.tar.bz2/from/this/mirror http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz # Can not download zend optimizer # wget -c http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23.i386.tar.gz # Add additional resource/rpm rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt rpm -K rpmforge-release-0.5.2-2.el6.rf.i686.rpm rpm -i rpmforge-release-0.5.2-2.el6.rf.i686.rpm sleep 1 yum -y install make gcc gcc-c++ autoconf automake vim ntsysv crontab* man ImageMagick-devel rar unrar unzip ncurses-devel zlib* flex* libxml* libmcrypt* mhash* libcurl-devel libtool libtool-ltdl-devel* bison bison-devel libjpeg* gd gd-devel openssl* cronolog bzip2-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel && yum -y update sleep 3 # Install AMP... # Install phpMyAdmin alias cp='cp' && tar -jxvf phpMyAdmin-3.4.7-all-languages.tar.bz2 && cp -r phpMyAdmin-3.4.7-all-languages /data/www/wwwroot/eyo/phpMyAdmin && source /root/.bashrc cat > /data/www/wwwroot/eyo/phpMyAdmin/config.inc.php <<EOF <?php /* This is needed for cookie based authentication to encrypt password in * cookie */ $cfg['blowfish_secret'] = 'qitan99'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ /* * Servers configuration */ $i = 0; /* * First server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = false; $cfg['UploadDir'] = ''; $cfg['SaveDir'] = ''; ?> EOF # Install Cmake and MySQL printf "Start install cmake...n" tar -zxvf cmake-2.8.6.tar.gz && cd cmake-2.8.6 && ./configure && gmake && make install && make clean # Check if MySQL already running # rsql=ps -ef |grep mysqld |awk '{if($3==1)print $0}' |awk '{if($1="root")print $3}' # if [ "$rsql" = "1" ]; then # printf "MySQL already running, stop and remove it? Warning: it will DELETE all Databases. (Continue after 20sec) [y/n]:n" if [ "$unsql" != "n" ]; then printf "Start install MySQL...n" if [ "$rsql" = "1" ]; then printf "Remove MySQL now...n" killall mysqld && cd / yum remove mysql* rm -rf {/,/root/,/opt/,/etc/,/usr/,/usr/etc/,/usr/local/,/usr/local/etc/,/var/,/var/local/,/var/opt/}/mysql fi cd $SRC # rm -rf /usr{/local,}/bin/{my*,innochecksum,msql2mysql,perror,replace,resolveip,resolve_stack_dump} groupadd mysql && useradd mysql -g mysql -s /sbin/nologin -d /data/mysql/data/ && chown mysql.mysql -R /data/mysql tar -zxvf mysql-5.5.16.tar.gz && cd mysql-5.5.16 && cmake -DCMAKE_INSTALL_PREFIX=$dir/mysql -DMYSQL_DATADIR=/data/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_DEBUG=0 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 && make && make install && make clean cp -r support-files/$mycnf /etc/my.cnf && sed -i '47 askip-grant-tables' /etc/my.cnf && chmod +x scripts/mysql_install_db && ./scripts/mysql_install_db --user=mysql --basedir=$dir/mysql --datadir=/data/mysql/data cp -r support-files/mysql.server /etc/rc.d/init.d/mysqld && sed -i '46,47s/^/#/' /etc/rc.d/init.d/mysqld && sed -i '46 abasedir='$dir'/mysql/' /etc/rc.d/init.d/mysqld && sed -i '48 adatadir=/data/mysql/data/' /etc/rc.d/init.d/mysqld && chmod +x /etc/rc.d/init.d/mysqld && chkconfig --levels 345 mysqld on && ln -sf $dir/mysql/bin/* /usr/local/bin/ && ln -sf $dir/mysql/bin/* /usr/bin/ /etc/init.d/mysqld start mysql -n <<EOF drop database test; use mysql; delete from user where user=''; update user set password=password('$rpass') where user='root'; grant all privileges on *.* to root@"%" identified by '$rpass'; create database eyo; grant all privileges on eyo.* to eyoadmin@localhost identified by '$passwd'; grant all privileges on eyo.* to eyoadmin@"%" identified by '$passwd'; flush privileges; quit EOF sed -i '/skip-grant-tables/d' /etc/my.cnf /etc/init.d/mysqld restart else printf "MySQL already running, skip install again." fi sleep 3 # Install Apache # Check if apache already running httpd=`netstat -ant |grep :::80 |awk '{print $4}' |awk -F : '{print $4}'` if [ "$httpd" = "80" ]; then printf "Apache already running, stop and remove it now...n" killall httpd && cd / yum remove httpd* rm -rf {/,/root/,/opt/,/etc/,/usr/,/usr/etc/,/usr/local/,/usr/local/etc/,/var/,/var/local/,/var/opt/}/{apache,apache2} sed -i '/apachectl/d' /etc/rc.d/rc.local cd $SRC fi printf "Start install Apache...n" groupadd www && useradd www -g www -s /sbin/nologin -d /data/www && chown www.www /data/www/wwwroot && chmod 777 /data/www/wwwroot cd ../ && tar -jxvf httpd-2.2.21.tar.bz2 && cd httpd-2.2.21 && ./configure --prefix=$dir/apache2 --with-ssl=/usr/ --enable-ssl --enable-so --enable-mime-magic --enable-cache --enable-mem-cache --with-included-apr --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support && make && make install && make clean && echo "$dir/apache2/bin/apachectl start" >> /etc/rc.d/rc.local # Install PHP printf "Start install PHP...n" cd ../ && tar -jxvf php-5.3.8.tar.bz2 && cd php-5.3.8 && ./configure --prefix=$dir/php --with-apxs2=$dir/apache2/bin/apxs --with-config-file-path=$dir/php/etc --with-mysql=$dir/mysql --with-libxml-dir --with-jpeg-dir=/usr/lib/ --with-gd --enable-gd-native-ttf --with-png-dir --with-bz2 --with-freetype-dir --with-iconv --with-zlib-dir --with-openssl=/usr/ --with-mcrypt --enable-soap --enable-magic-quotes --enable-ftp --enable-mbstring --enable-exif --disable-cgi --with-pear --enable-zip --with-mhash --with-openssl --enable-inline-optimization --disable-ipv6 --disable-cli --with-mysqli=$dir/mysql/bin/mysql_config --enable-bcmath --with-curl && make && make install && make clean mkdir $dir/php/etc && cp -r php.ini-production $dir/php/etc/php.ini && sed -i 's/^;date.timezone =.*/&ndate.timezone = Asia/Chongqing/' $dir/php/etc/php.ini && ln -sf $dir/php/bin/* /usr/local/bin/ && ln -sf $dir/php/bin/* /usr/bin/ # Install Xcache cd .. && tar -zxvf xcache-1.3.2.tar.gz && cd xcache-1.3.2 && $dir/php/bin/phpize && ./configure --with-php-config=$dir/php/bin/php-config --enable-xcache --enable-xcache-optimizer --enable-xcache-coverager && make && make install && make clean cat >> $dir/php/etc/php.ini <<EOF ;add the following code at the end of file php.ini [xcache-common] zend_extension = $dir/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so [xcache.admin] xcache.admin.user = "admin" ;如何生成md5密码: echo -n "passwd"| md5sum xcache.admin.pass = "f50dff779a142c7e0987755a247109f7" [xcache] ; Change xcache.size to tune the size of the opcode cache xcache.size = 24M xcache.shm_scheme = "mmap" xcache.count = 4 xcache.slots = 8K xcache.ttl = 0 xcache.gc_interval = 0 ; Change xcache.var_size to adjust the size of variable cache xcache.var_size = 8M xcache.var_count = 1 xcache.var_slots = 8K xcache.var_ttl = 0 xcache.var_maxttl = 0 xcache.var_gc_interval = 300 xcache.test = Off xcache.readonly_protection = On xcache.mmap_path = "/tmp/xcache" xcache.coredump_directory = "" xcache.cacher = On xcache.stat = On xcache.optimizer = Off [xcache.coverager] xcache.coverager = On xcache.coveragedump_directory = "" EOF # If ZendGuardLoader have download manually, install zend optimizer # Install Zend Optimizer if [ -s ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz ]; then cd ../ && tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz && cp -r ZendGuardLoader-php-5.3-linux-glibc23-i386 $dir/php/lib/php/extensions/ cat >> $dir/php/etc/php.ini <<EOF zend_extension = $dir/php/lib/php/extensions/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so zend_loader.enable=1 zend_loader.disable_licensing=0 EOF fi # Combined Apche and PHP # Modify file httpd.conf sed -i 's/#ServerName www.example.com:80/ServerName localhost/' $dir/apache2/conf/httpd.conf sed -i 's/ServerAdmin you@example.com/ServerAdmin qitan@goego.net/g' $dir/apache2/conf/httpd.conf sed -i 's/AddType application/x-gzip .gz .tgz.*/&n AddType application/x-httpd-php .php/' $dir/apache2/conf/httpd.conf sed -i 's/DirectoryIndex index.html/DirectoryIndex index.html index.htm index.php/' $dir/apache2/conf/httpd.conf sed -i '122 a Allow from all' $dir/apache2/conf/httpd.conf cat >> $dir/apache2/conf/httpd.conf <<EOF Include conf/extra/httpd-mpm.conf Include conf/extra/httpd-info.conf Include conf/extra/httpd-vhosts.conf Include conf/extra/httpd-default.conf <IfModule mod_expires> ExpiresActive On ExpiresDefault A60 ExpiresByType image/x-icon A2592000 ExpiresByType application/x-javascript A2592000 ExpiresByType text/css A2592000 ExpiresByType image/gif A604800 ExpiresByType image/png A604800 ExpiresByType image/jpeg A604800 ExpiresByType text/plain A604800 ExpiresByType application/x-shockwave-flash A604800 ExpiresByType video/x-flv A604800 ExpiresByType application/pdf A604800 ExpiresByType text/html A60 </IfModule> <IfModule mod_deflate.c> SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript </IfModule> EOF # Setup vhost cd $dir/apache2/conf/extra && mv httpd-vhosts.conf httpd-vhosts.conf.bak cat > httpd-vhosts.conf <<EOF NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "/data/www/wwwroot/eyo" ServerName $hostname ErrorLog "/data/www/logs/$hostname.error.log" # CustomLog "|/usr/sbin/cronolog /data/www/logs/$hostname.access.log.%Y%m%d" combined CustomLog "/data/www/logs/$hostname-access_log" combined <Directory "/data/www/wwwroot/eyo"> # Options None # AllowOverride None Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> <location /server-status> SetHandler server-status Order Deny,Allow Deny from all Allow from 127.0.0.1 </location> </VirtualHost> EOF mv httpd-default.conf httpd-default.conf.bak cat > httpd-default.conf <<EOF Timeout 60 KeepAlive On MaxKeepAliveRequests 500 KeepAliveTimeout 15 UseCanonicalName Off AccessFileName .htaccess ServerTokens Prod ServerSignature Off HostnameLookups Off EOF mv httpd-info.conf httpd-info.conf.bak cat > httpd-info.conf <<EOF <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1 </Location> <Location /server-info> SetHandler server-info Order deny,allow Deny from all Allow from .example.com </Location> ExtendedStatus On EOF mv httpd-mpm.conf httpd-mpm.conf.bak cat > httpd-mpm.conf <<EOF <IfModule !mpm_netware_module> PidFile "logs/httpd.pid" </IfModule> <IfModule !mpm_winnt_module> <IfModule !mpm_netware_module> LockFile "logs/accept.lock" </IfModule> </IfModule> <IfModule mpm_prefork_module> ServerLimit 1000 StartServers 10 MinSpareServers 10 MaxSpareServers 20 MaxClients 1000 MaxRequestsPerChild 5000 </IfModule> <IfModule mpm_worker_module> StartServers 4 MaxClients 300 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 </IfModule> <IfModule mpm_beos_module> StartThreads 10 MaxClients 50 MaxRequestsPerThread 10000 </IfModule> <IfModule mpm_netware_module> ThreadStackSize 65536 StartThreads 250 MinSpareThreads 25 MaxSpareThreads 250 MaxThreads 1000 MaxRequestsPerChild 0 MaxMemFree 100 </IfModule> <IfModule mpm_mpmt_os2_module> StartServers 2 MinSpareThreads 5 MaxSpareThreads 10 MaxRequestsPerChild 0 </IfModule> <IfModule mpm_winnt_module> ThreadsPerChild 150 MaxRequestsPerChild 0 </IfModule> EOF # Vhost Directory and basic setup mkdir /data/www/wwwroot/eyo && chmod 777 /data/www/wwwroot/eyo cat > /data/www/wwwroot/eyo/index.html <<EOF <html> <head> <title>LAMP Install Success.</title> </head> <body> <p>########################## Written By Qitan ####################################</p> <p>####################### BLOG: http://blog.catjia.com ################################</p> <p>####################### EMAIL: qqing_lai@hotmail.com ##############################</p> <p>########################## DATE: 2011-11-09 ###################################</p> <p>################# LAMP Have Successfully Installed., enjoy it! ############################</p> </body> </html> EOF cat > /data/www/wwwroot/eyo/phpinfo.php <<EOF <html> <head> <title>LAMP Install Success.</title> </head> <body> <p>########################## Written By Qitan ####################################</p> <p>####################### BLOG: http://blog.catjia.com ################################</p> <p>####################### EMAIL: qqing_lai@hotmail.com ##############################</p> <p>########################## DATE: 2011-11-09 ###################################</p> <p>################# LAMP Have Successfully Installed., enjoy it! ############################</p> </body> </html> <?php phpinfo(); ?> EOF $dir/apache2/bin/apachectl start # Install Vsftpd printf "Start install VSFTPD...n" yum -y install vsftpd chkconfig vsftpd on && /etc/init.d/vsftpd start mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak cat > /etc/vsftpd/vsftpd.conf <<EOF anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES ftpd_banner=Welcome to GoeGo FTP service. chroot_list_enable=YES chroot_list_file=/etc/vsftpd/chroot_list listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES setproctitle_enable=YES ##Follow command for pasv mode set #pasv_enable=YES #pasv_min_port=24700 #pasv_max_port=24800 EOF # Create FTP User echo $ftper > /etc/vsftpd/chroot_list useradd -d /data/www/wwwroot/ -g ftp -s /sbin/nologin $ftper echo "$ftpasswd" |passwd --stdin $ftper /etc/init.d/vsftpd restart /etc/init.d/vsftpd stop && /etc/init.d/mysqld stop && $dir/apache2/apachectl stop ##################### Maintenance Scripts -- Begin ############################# # Download Fetion wget -c http://blog.catjia.com/wp-content/uploads/file/downloads/fetion.tar.bz2 && tar -jxvf fetion.tar.bz2* -C /usr/local/ && echo "/usr/local/fetion/" >> /etc/ld.so.conf && ldconfig && $FETI/fetion > /dev/null # Warning: You need to send msg to test if Fetion is working (Note: First time send need to enter a verification code) # Check if Apache is running. cat > $SCRI/check_80.sh <<EOF #!/bin/sh host=`hostname` httpd=`netstat -tunpl | grep :::80 | awk '{print $4}' | awk -F : '{print $4}'` if [ "$httpd" != 80 ] then $dir/apache2/bin/apachectl start > /dev/null 2>&1 $FETI/fetion --mobile=$mobile --pwd=$pwd --to=$mobile --msg-utf8="$host Apache service (Port: 80) is down, try to start now..." else echo "`date`, $host Apache service is running." | mail -s "$host Apache Check" $re_mail fi sleep 3 httpd=`netstat -tunpl | grep :::80 | awk '{print $4}' | awk -F : '{print $4}'` if [ "$httpd" != 80 ] then $FETI/fetion --mobile=$mobile --pwd=$mpasswd --to=$mobile --msg-utf8="$host Cannot start Apache service, please login server check manually!" fi EOF # Check if MySQL is running. cat > $SCRI/check_3306.sh <<EOF #!/bin/sh host=`hostname` mysqld=`ps -ef |grep mysqld |awk '{if($3==1)print $0}'|awk '{if($1=="root")print $3 }'` if [ "$mysqld" != 1 ] then /etc/init.d/mysqld start > /dev/null 2>&1 $FETI/fetion --mobile=$mobile --pwd=$mpasswd --to=$mobile --msg-utf8="$host MySQL service (Port: 3306) is down, try to start now..." else echo "`date`, $host MySQL service is running." | mail -s "$host MySQL Check" $re_mail fi sleep 3 mysqld=`ps -ef |grep mysqld |awk '{if($3==1)print $0}'|awk '{if($1=="root")print $3 }'` if [ "$mysqld" != 1 ] then $FETI/fetion --mobile=$mobile --pwd=$mpasswd --to=$mobile --msg-utf8="$host Cannot start MySQL service, please login server check manually." fi EOF # Check Memory userd status cat > $SCRI/memcheck.sh <<EOF #!/bin/sh # Check memory used statu. free_used=`free -m |grep Mem |awk '{print $3}'` if [ "$free_used" -ge "3800" ] then echo "Memory used greater than 3800 MB, please check your Web Server's status" > /usr/local/sbin/mem.txt $FETI/fetion --mobile=$mobile --pwd=$mpasswd --to=$mobile --msg-utf8="Memory used greater than 3800 MB, please check your Web Server's status" |mail -s "WebGoeGo Mem Used More" $re_mail < /usr/local/sbin/mem.txt > /dev/null rm -rf /usr/local/sbin/mem.txt else echo 'Memory used is normal.' > /dev/null fi EOF # Check Disk used status cat > $SCRI/diskcheck.sh <<EOF #!/bin/sh # Check partition sda2 (/) and sda5 (/data) sda2_used=`df |grep sda2 |awk '{print $5}' | sed 's/%//g'` sda5_used=`df |grep sda5 |awk '{print $5}' | sed 's/%//g'` if [[ "$sda2_used" -ge "70" ]] || [[ "$sda5_used" -ge "85" ]] then echo "Disk used nearly full: `df |grep sda[2,5]` Please check your Web Server's status" > /usr/local/sbin/disk.log $FETI/fetion --mobile=$mobile --pwd=$mpasswd --to=$mobile --file-utf8=/usr/local/sbin/disk.log |mail -s "WebGoeGo Disk Used More" $re_mail < /usr/local/sbin/disk.log rm -rf /usr/local/sbin/disk.log else echo 'Disk used is normal.' > /dev/null fi EOF # Check if Website is working cat > $SCRI/web.sh <<EOF #!/bin/sh # Monitor Website server_all_list=( www.goego.net www.www.7tan.info ) date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S") # Send Msg to alert by Mail and Fetion. send_msg_alert() { if [[ $2 = "0" ]] || [[ $2 = "2" ]]; then echo "`date +'%Y-%m-%d %H:%M:%S'` $1 " > http_down.log mail -s "Web Server (GoeGo or www.7tan.info) Down" $re_mail < http_down.log | $FETI/fetion --mobile=$mobile --pwd=$mpasswd --to=$mobile --msg-utf8=$1 fi } server_all_len=${#server_all_list[*]} i=0 while [ $i -lt $server_all_len ] do server_ip=$(echo ${server_all_list[$i]} | awk -F ':' '{print $1}') server_port=$(echo ${server_all_list[$i]} | awk -F ':' '{print $2}') server_message=" " if curl -m 10 -G http://${server_all_list[$i]}/ > /dev/null 2>&1 then #status: 0,http down 1,http ok 2,http down but ping ok status=1 echo "WebServer${server_ip},Port${server_port}is working!"; server_message="WebServer${server_ip}, Port${server_port}is working!"; else if curl -m 30 -G http://${server_all_list[$i]}/ > /dev/null 2>&1 then status=1 echo "WebServer${server_ip},Port${server_port}is working!" server_message="WebServer${server_ip}, Port${server_port}is working!"; else if ping -c 3 $server_ip > /dev/null 2>&1 then status=2 echo "WebServer${server_ip}, Port${server_port}cannot access Website,but can ping!"; server_message="WebServer${server_ip}, Port${server_port}cannot access Website,but can ping!"; else status=0 echo "WenServer${server_ip}, Port${server_port}cannot access Website, and cannot ping!"; server_message="WebServer${server_ip}, Port${server_port}cannot access Website, and cannot ping!"; fi fi fi send_msg_alert "${server_message}" "${status}"; let i++ done EOF cat >> /var/spool/cron/root <<EOF */10 * * * * $SCRI/check_3306.sh */10 * * * * $SCRI/check_80.sh */1 * * * * $SCRI/memcheck.sh 0 */6 * * * $SCRI/diskcheck.sh EOF ##################### Maintenance Scripts -- End ############################# # Create log file... ipadd=`ifconfig $eth_hw |grep "inet addr" |awk '{print $2}' |awk -F : '{print $2}'` cat > /root/qq_lamp.log <<EOF ===============================================================================n SETUP OPERATION SYSTEM AND INSTALL LAMP--WRITTEN BY EYO-QITAN. Email: qqing_lai@hotmail.com Website: www.goego.net Install_Log File: qq_lamp.log Path: /root ===============================================================================n `date` Warning: You need to send msg to test if Fetion is working (Note: First time send need to enter a verification code) Fetion Location: $FETI Maintenance Scripts Locatio: $SCRI Packages Install Location: $dir Data Location: /data/ Packages Install: cmake-2.8.6.tar.gz httpd-2.2.21.tar.bz2 mysql-5.5.16.tar.gz php-5.3.8.tar.bz2 phpMyAdmin-3.4.7-all-languages.tar.bz2 xcache-1.3.2.tar.gz ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz IP Address: $ipadd Hostname: $hostname MySQL ROOT Password: $rpass MySQL Database: eyo MySQL eyo User: eyoadmin MySQL eyo Password: $passwd FTP User Name: $ftper FTP User Password: $ftpasswd ===============================================================================n ===============================================================================n LAMP Have Successfully Installed., enjoy it! Written by EYO-Qitan. Email: qqing_lai@hotmail.com Website: www.goego.net ===============================================================================n EOF echo -e "33[7m" printf "=======================================================================n" printf " LAMP Have Successfully Installed., enjoy it! n" printf " Written by EYO-Qitan. n" printf " Email: qqing_lai@hotmail.com Website: www.goego.net n" printf "=======================================================================n" echo -e "33[0m" yum -y install sendmail mail* && chkconfig sendmail on && /etc/init.d/sendmail start mail -s "LAMP successfully installed and REBOOT now" $re_mail < /root/qq_lamp.log > /dev/null 2>&1 echo "*/5 * * * * ntpdate 210.72.145.44" >> /var/spool/cron/root echo "net.ipv4.ip_local_port_range=1024 65535" >> /etc/sysctl.conf && /sbin/sysctl -p cat >> /etc/security/limits.conf <<EOF * soft nofile 65535 * hard nofile 70000 EOF sleep 5 reboot ########################### HAPPY ENDDING ################################
(责任编辑:IT) |