#!/bin/bash OS_Version=`head -1 /etc/issue|awk -F[" ".] ‘{print $3}‘` Source_Dir=/root/tools host_ip=`ifconfig eth0|sed -n ‘2p‘|sed -n ‘[email protected]^.*dr:\(.*\) Bca.*[email protected]\[email protected]‘` if [ ! -e $Source_Dir ];then mkdir -p $Source_Dir fi menu(){ cat<<EOF ---------------------------------------- 1.System Initialize 2.Install Nginx 3.Install Php-fpm 4.Install Mysql 5.Exit ---------------------------------------- EOF read -p "Please Enter Your Choice[1-5]:" num } install_nginx(){ echo -e "Start Install Nginx" id nginx if [ $? -ne 0 ];then groupadd nginx useradd -g nginx -s /sbin/nologin -M nginx fi yum install -y pcre-devel openssl-devel cd $Source_Dir tar xf nginx-1.6.2.tar.gz cd nginx-1.6.2 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module make && make install if [ $? -eq 0 ];then echo -e "Finished Install Nginx" fi cd .. cat > /etc/init.d/nginx <<eof #!/bin/bash #chkconfig: - 85 15 #description: nginx is a World Wide Web server. It is used to serve path="/usr/local/nginx" RETVAL=0 prog="nginx" . /etc/init.d/functions start(){ if [ ! -f \$path/logs/nginx.pid ] then [ -x \$path/sbin/nginx ] || exit 1 \$path/sbin/nginx RETVAL=\$? if [ -f \$path/logs/nginx.pid ] then action "Nginx startup" /bin/true else action "Nginx startup" /bin/false fi else echo "Nginx is running." fi return \$RETVAL } stop(){ if [ ! -f \$path/logs/nginx.pid ] then echo "Nginx is not running." else [ -x \$path/sbin/nginx ] || exit 1 if [ -f \$path/logs/nginx.pid ] then kill \`cat \$path/logs/nginx.pid\` RETVAL=\$? sleep 2 fi if [ ! -f \$path/logs/nginx.pid ] then action "Nginx is stopped." /bin/true else action "Nginx is stopped." /bin/false fi fi return \$RETVAL } case "\$1" in start) start RETVAL=\$? ;; stop) stop RETVAL=\$? ;; restart) stop sleep 2 start RETVAL=\$? ;; reload) \$path/sbin/nginx -s reload RETVAL=\$? ;; status) status \$prog RETVAL=\$? ;; *) echo "USAGE:\$0 {start|stop|restart|reload|status}" esac exit \$RETVAL eof chmod +x /etc/init.d/nginx /etc/init.d/nginx start chkconfig nginx on } install_php(){ echo -e "Start Install Php-fpm" yum -y install libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel openldap-devel libmcrypt-devel cp /usr/lib64/libldap* /usr/lib/ cd $Source_Dir tar xjf php-5.3.27.tar.bz2 cd php-5.3.27 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libcurl --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --with-gettext --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd make && make install if [ $? -eq 0 ];then cp php.ini-production /etc/php.ini cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm chmod +x /etc/rc.d/init.d/php-fpm chkconfig php-fpm on cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf sed -i ‘[email protected] = [email protected] = [email protected]‘ /usr/local/php/etc/php-fpm.conf sed -i ‘[email protected] = [email protected] = [email protected]‘ /usr/local/php/etc/php-fpm.conf sed -i ‘[email protected]_children = [email protected]_children = [email protected]‘ /usr/local/php/etc/php-fpm.conf sed -i ‘[email protected]_servers = [email protected]_servers = [email protected]‘ /usr/local/php/etc/php-fpm.conf sed -i ‘[email protected]_spare_servers = [email protected]_spare_servers = [email protected]‘ /usr/local/php/etc/php-fpm.conf sed -i ‘[email protected]_spare_servers = [email protected]_spare_servers = [email protected]‘ /usr/local/php/etc/php-fpm.conf sed -i "[email protected] = 127.0.0.1:[email protected] = ${host_ip}:[email protected]" /usr/local/php/etc/php-fpm.conf /etc/init.d/php-fpm start fi echo -e "Finished Install Php-fpm" } install_mysql(){ echo -e "Start Install Mysql" yum -y install ncurses-devel id mysql if [ $? -ne 0 ];then groupadd mysql useradd -g mysql -s /sbin/nologin -M mysql fi cd $Source_Dir tar xf mysql-5.1.47.tar.gz cd mysql-5.1.47 ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-readline --with-big-tables --with-plugins=all --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static make && make install cd .. chown -R mysql:mysql /usr/local/mysql mkdir -p /data/3306/data cp /usr/local/mysql/share/mysql/my-medium.cnf /data/3306/my.cnf.ori cat>/data/3306/my.cnf<<eof [client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /data/3306/mysql.sock basedir = /usr/local/mysql datadir = /data/3306/data pid-file = /data/3307/mysql.pid log-bin = /data/3307/mysql-bin skip-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M log-bin=mysql-bin binlog_format=mixed server-id = 1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout [mysqld_safe] log_error=/data/3306/mysql_3306.err pid-file=/data/3306/mysqld.pid eof cat>/data/3306/mysql<<eof #!/bin/bash port=3306 mysql_user="root" mysql_pwd="" CmdPath="/usr/local/mysql/bin" mysql_sock="/data/\${port}/mysql.sock" #startup function function_start_mysql(){ if [ ! -e "\$mysql_sock" ];then printf "Starting MySQL...\n" /bin/sh \${CmdPath}/mysqld_safe --defaults-file=/data/\${port}/my.cnf 2>&1 > /dev/null & else printf "MySQL is running...\n" exit fi } #stop function function_stop_mysql(){ if [ ! -e "\$mysql_sock" ];then printf "MySQL is stopped...\n" exit else printf "Stoping MySQL...\n" \${CmdPath}/mysqladmin -u \${mysql_user} -p\${mysql_pwd} -S /data/\${port}/mysql.sock shutdown fi } #restart function function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql sleep 2 function_start_mysql } case \$1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: /data/\${port}/mysql {start|stop|restart}\n" ;; esac eof chmod 700 /data/3306/mysql /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/3306/data --user=mysql chown -R mysql:mysql /data /data/3306/mysql start echo -e "Finished Install Mysql" } menu case $num in 1) echo -e "Start System Initialize" for service in `chkconfig --list|grep "3:on"|awk ‘{print $1}‘|grep -vE "network|sshd|crond|rsyslog"` do chkconfig $service off done /etc/init.d/iptables stop sed -i "[email protected][email protected][email protected]" /etc/selinux/config cd /etc/yum.repos.d /bin/mv CentOS-Base.repo CentOS-Base.repo.bak if [ ${OS_Version} -eq 6 ];then wget http://mirrors.aliyun.com/repo/Centos-6.repo /bin/mv Centos-6.repo CentOS-Base.repo rpm -ivh http://mirrors.aliyun.com/epel/6Server/epel-release-6-8.noarch.rpm yum makecache sleep 2 elif [ ${OS_Version} -eq 5 ];then wget http://mirrors.aliyun.com/repo/Centos-5.repo /bin/mv Centos-5.repo CentOS-Base.repo rpm -ivh http://mirrors.aliyun.com/epel/5Server/x86_64/epel-release-5-4.noarch.rpm yum makecache sleep 2 fi cd ~ yum install -y ntp /usr/sbin/ntpdate ntp.api.bz echo "/usr/sbin/ntpdate ntp.api.bz" >>/etc/rc.local ulimit -SHn 65535 echo "ulimit -SHn 65535" >> /etc/rc.local cat >>/etc/security/limits.conf <<eof * hard nofile 65535 eof cat >> /etc/sysctl.conf << eof net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 1200 net.ipv4.ip_local_port_range = 1024 65535 eof /sbin/sysctl -p yum -y install gcc gcc-c++ make automake autoconf echo -e "Finished System Initialize" menu ;; 2) install_nginx menu ;; 3) install_php menu ;; 4) install_mysql menu ;; 5) exit 1 ;; *) echo "Please Enter Your Choice:" exit 1 esac
时间: 2024-10-10 21:17:21