#!/bin/bash
Cd/usr/local/src
./installmysql
./installnginx
./installphp
./installhaproxy
./installkeepalived
touch/usr/local/nginx/html/phpinfo.php
Echo-e "<?php\nphpinfo ();" >/usr/local/nginx/html/phpinfo.php
#!/bin/bash
Cd/usr/local/src
Tar zxvf cmake-2.8.5.tar.gz
CD cmake-2.8.5
./bootstrap
Make && make install
Groupadd MySQL
Useradd-g mysql-s/usr/sbin/nologin MySQL
Mkdir/usr/local/mysql
Mkdir/usr/local/mysql/data
Cd/usr/local/src
Tar zxvf mysql-5.5.17.tar.gz
CD mysql-5.5.17
Cmake-dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/usr/local/mysql/data-ddefault_charset=utf8- Ddefault_collation=utf8_unicode_ci-dwith_readline=1-dwith_ssl=system-dwith_embedded_server=1-denabled_local_ Infile=1-ddefault_collation=utf8_general_ci-dwith_myisam_storage_engine=1-dwith_innobase_storage_engine=1- Dwith_debug=0
Make && make install
Cp/usr/local/src/mysql-5.5.17/support-files/my-medium.cnf/etc/my.cnf
chmod +x/usr/local/mysql
Chown-r Mysql:mysql/usr/local/mysql
CP Support-files/mysql.server/etc/init.d/mysqld
chmod +x/etc/init.d/mysqld
Chkconfig--add mysqld
Chkconfig mysqld on
Sed "30i datadir=/usr/local/mysql/data\ndefault-storage-engine=myisam"/etc/my.cnf >./my.sem
Cp-f./my.sem/etc/my.cnf
Rm-f./my.sem
/usr/local/mysql/scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data &
#!/bin/bash
Groupadd www
Useradd-g www-s/usr/sbin/nologin www
Cd/usr/local/src
Tar zxvf pcre-7.9.tar.gz
CD pcre-7.9/
./configure
Make && make install
Cd.. /
Tar zxvf nginx-0.8.15.tar.gz
CD nginx-0.8.15/
./configure--user=www--group=www--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module
Make && make install
Touch./nginx.shell.sem
Cat >./nginx.shell.sem << "Shell"
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
#
# Chkconfig:-85 15
# Description:nginx is a high-performance Web and proxy server.
# It has a lot of features, but It\ 's isn't for everyone.
# Processname:nginx
# Pidfile:/var/run/nginx.pid
# config:/usr/local/nginx/conf/nginx.conf
Nginxd=/usr/local/nginx/sbin/nginx
Nginx_config=/usr/local/nginx/conf/nginx.conf
Nginx_pid=/var/run/nginx.pid
Retval=0
Prog= "Nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source Networking configuration.
. /etc/sysconfig/network
# Check that networking are up.
[${networking} = "No"] && exit 0
[-X $nginxd] | | Exit 0
# Start Nginx daemons functions.
Start () {
If [-e $nginx _pid];then
echo "Nginx already running ..."
Exit 1
Fi
Echo-n $ "Starting $prog:"
Daemon $nginxd-C ${nginx_config}
Retval=$?
Echo
[$RETVAL = 0] && Touch/var/lock/subsys/nginx
Return $RETVAL
}
# Stop Nginx daemons functions.
Stop () {
Echo-n $ "Stopping $prog:"
Killproc $nginxd
Retval=$?
Echo
[$RETVAL = 0] && rm-f/var/lock/subsys/nginx/var/run/nginx.pid
}
# Reload Nginx service functions.
Reload () {
Echo-n $ "Reloading $prog:"
#kill-hup ' Cat ${nginx_pid} '
Killproc $nginxd-hup
Retval=$?
Echo
}
# See how we were called.
Case "$" in
Start
Start
;;
Stop
Stop
;;
Reload
Reload
;;
Restart
Stop
Start
;;
Status
Status $prog
Retval=$?
;;
*)
echo $ "Usage: $prog {start|stop|restart|reload|status|help}"
Exit 1
Esac
Exit $RETVAL
SHELL
CP./nginx.shell.sem/etc/init.d/nginx
Rm-f./.nginx.shell.sem
chmod +x/etc/init.d/nginx
Chkconfig--add Nginx
#!/bin/bash
Mkdir-p/usr/local/jpeg6
Mkdir-p/usr/local/jpeg6/bin
Mkdir-p/usr/local/jpeg6/lib
Mkdir-p/usr/local/jpeg6/include
Mkdir-p/usr/local/jpeg6/man
Mkdir-p/usr/local/jpeg6/man1
Mkdir-p/usr/local/jpeg6/man/man1
Cd/usr/local/src
TAR-ZXVF jpegsrc.v6b.tar.gz
CD jpeg-6b
./configure--prefix=/usr/local/jpeg6/--enable-shared--enable-static
Make
Make install
Cd/usr/local/src
TAR-ZVXF libpng-1.2.16.tar.gz
CD libpng-1.2.16
./configure
Make && make install
Cd/usr/local/src
TAR-ZVXF freetype-2.3.4.tar.gz
CD freetype-2.3.4
Mkdir-p/usr/local/freetype
./configure--prefix=/usr/local/freetype
Make && make install
Cd/usr/local/src
TAR-ZVXF gd-2.0.35.tar.gz
Mkdir-p/USR/LOCAL/GD
CD gd-2.0.35
./configure--prefix=/usr/local/gd--with-jpeg=/usr/local/jpeg6/--with-png--with-zlib--with-freetype=/usr/local/ FreeType
Make && make install
./configure--prefix=/usr/local/gd--with-jpeg=/usr/local/jpeg6/--with-png--with-zlib--with-freetype=/usr/local/ FreeType
Make && make install
Cd/usr/local/src
Tar zxvf libiconv-1.13.tar.gz
CD libiconv-1.13/
./configure--prefix=/usr/local
Make && make install
Cd/usr/local/src
Tar zxvf libmcrypt-2.5.8.tar.gz
CD libmcrypt-2.5.8/
./configure
Make && make install
/sbin/ldconfig
CD libltdl/
./configure--enable-ltdl-install
Make && make install
Cd/usr/local/src
Tar zxvf mhash-0.9.9.tar.gz
CD mhash-0.9.9/
./configure
Make && make install
Ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.la
Ln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.so
Ln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4
Ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8
Ln-s/USR/LOCAL/LIB/LIBMHASH.A/USR/LIB/LIBMHASH.A
Ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la
Ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so
Ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
Ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1
Ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/
Cd/usr/local/src
Tar zxvf mcrypt-2.6.8.tar.gz
CD mcrypt-2.6.8/
/sbin/ldconfig
./configure
Make && make install
Cd/usr/local/src
Tar zxvf php-5.3.27.tar.gz
CD php-5.3.27
./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql-- With-mysqli=/usr/local/mysql/bin/mysql_config--with-iconv-dir=/usr/local--with-freetype-dir=/usr/local/ FreeType--with-jpeg-dir=/usr/local/jpeg6--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml-- Disable-rpath--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization-- With-curl--with-curlwrappers--enable-mbregex--enable-fpm--enable-mbstring--with-mcrypt--with-gd=/usr/local/gd- -enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-ldap--WITH-LDAP-SASL-- With-xmlrpc--enable-zip--enable-soap--without-pear
Make zend_extra_libs= '-liconv '
Make install
CP./php.ini-production/usr/local/php/etc/php.ini
Cd/usr/local/php/etc
CP./php-fpm.conf.default./php-fpm.conf
Ulimit-shn 65535
/usr/local/php/sbin/php-fpm
Cat >/usr/local/nginx/conf/fcgi.conf << "PARA"
Fastcgi_param Gateway_interface cgi/1.1;
Fastcgi_param Server_software Nginx;
Fastcgi_param query_string $query _string;
Fastcgi_param Request_method $request _method;
Fastcgi_param Content_Type $content _type;
Fastcgi_param content_length $content _length;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Fastcgi_param script_name $fastcgi _script_name;
Fastcgi_param Request_uri $request _uri;
Fastcgi_param Document_uri $document _uri;
Fastcgi_param document_root $document _root;
Fastcgi_param server_protocol $server _protocol;
Fastcgi_param remote_addr $remote _addr;
Fastcgi_param Remote_port $remote _port;
Fastcgi_param server_addr $server _addr;
Fastcgi_param server_port $server _port;
Fastcgi_param server_name $server _name;
# PHP only, required if PHP is built with--enable-force-cgi-redirect
Fastcgi_param Redirect_status 200;
PARA
Sed "47i location ~. *\\. (PHP|PHP5)? \$\n{\nfastcgi_pass 127.0.0.1:9000;\nfastcgi_index index.php;\ninclude fcgi.conf;\n}\n "/usr/local/ nginx/conf/nginx.conf >./nginx.sem
Cp-f./nginx.sem/usr/local/nginx/conf/nginx.conf
Rm-f./nginx.sem
#!/bin/bash
Cd/usr/local/src
Tar zxvf./haproxy-1.4.22.tar.gz
CD./haproxy-1.4.22
Make target=linux26 prefix=/usr/local/haproxy Install
Touch/usr/local/haproxy/haproxy.conf
Cat >/usr/local/haproxy/haproxy.conf << "she"
Global
Log 127.0.0.1 Local0
Maxconn 4096
Chroot/usr/local/haproxy
UID 501
GID 501
Daemon
Nbproc 1
Pidfile/usr/local/haproxy/logs/haproxy.pid
Debug
Defaults
Log 127.0.0.1 Local3
Mode http
Option Httplog
Option Httpclose
Option Dontlognull
Option Forwardfor
Option Redispatch
Retries 2
Maxconn 65535
Balance Roundrobin
Stats Uri/haproxy-stats
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
######### #以上不用动, mainly change the following parts:--->
#listen Mysql_proxy *:3306
# MySQL Load balancer
# Mode TCP
# Balance Leastconn
# server DB1 192.168.2.104:3306 weight 1
# server DB2 192.168.2.105:3306 weight 1
Listen Web_proxy *:80
Server Web1 192.168.2.103:80 check Inter rise 2 Fall 5
Server WEB2 192.168.2.104:80 check Inter rise 2 Fall 5
#server web3 192.168.2.104:80 check Inter rise 2 Fall 5
# One server can add multiple
She
#!/bin/bash
Cd/usr/local/src
Tar zxvf keepalived-1.1.15.tar.gz
CD keepalived-1.1.15
./configure--prefix=/usr/local/keepalived
Make
Make install
cd/usr/local/src/keepalived-1.1.15
CP keepalived/etc/init.d/keepalived.rh.init/etc/init.d/keepalived
chmod +x/etc/init.d/keepalived
CP keepalived/etc/init.d/keepalived.sysconfig/etc/sysconfig/keepalived
Chkconfig--add keepalived
Chkconfig--level 345 keepalived on
cp/usr/local/keepalived/sbin/keepalived/bin/
Mkdir/etc/keepalived
Touch/etc/keepalived/keepalived.conf
Cat >/etc/keepalived/keepalived.conf << "she"
! Configuration File for Keepalived
Vrrp_instance Vi_1 {
State master-to-master server, from server to (BACKUP)
Interface eth0
Mcast_src_ip 192.168.2.103--"This machine's IP address
VIRTUAL_ROUTER_ID---Identity ID, multiple servers to be the same
Priority is higher than the slave server
Advert_int 1--Check the time interval for survival
Notify/etc/mailto--Send mail scripts
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.2.119-"Virtual IP address, can write multiple
#....
}
}
She
Automatic installation of LNMP system using shell scripts