使用shell脚本完自动安装lnmp系统

#!/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 not 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 is 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 "$1" 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 was 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

##########以上不用动,主要改以下部分:--->
#listen mysql_proxy *:3306
# mysql负载均衡
#    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 2000 rise 2 fall 5
        server web2 192.168.2.104:80 check inter 2000 rise 2 fall 5
        #server web3 192.168.2.104:80 check inter 2000 rise 2 fall 5
        # 一行一个服务器可以加多个
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                  --> 主服务器,从服务器为(BACKUP)
        interface eth0
        mcast_src_ip 192.168.2.103     --》 本机的IP地址
        virtual_router_id 51             --> 标识id,多个服务器要相同
        priority 100                  -->  优先级要高于从服务器
        advert_int 1                     -->  检查存活的时间间隔
    notify /etc/mailto            -->  发送邮件的脚本
        authentication {
                auth_type PASS
                auth_pass 1111
        }
        virtual_ipaddress {
                192.168.2.119           --》  虚拟的IP地址,可以写多个
                #....
        }
}
she

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。