使用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

时间: 2024-10-20 05:18:12

使用shell脚本完自动安装lnmp系统的相关文章

Shell 脚本来自动监控 Linux 系统的内存

# vim /scripts/swap-warning.sh #!/bin/bash #提取本服务器的IP地址信息 IP=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "` #系统分配的交换分区总量 swap_total=`free -m | grep Swap | awk '{print $2}'` #当前剩余的交换分区free大小 swap_free=`

Centos6.5上面用Shell脚本一键编译安装mysql5.5.47

操作系统及其mysql配置文件说明:Linux系统:Centos6.5 cat /etc/centos_release     查看centos版本信息 [[email protected] ~]# cat /etc/centos-release CentOS release 6.5 (Final) uname -r        #显示操作系统的发行版号 [[email protected] ~]# uname -r 2.6.32-431.el6.x86_64 uname -a      #显

shell脚本一键在线安装redis数据库(使用函数实现)

shell脚本一键在线安装redis数据库(使用函数实现) 前面的文章给出了有关手工编译安装redis的流程,并且在模拟搭建redis集群时给出了在线安装redis的过程,于是就想着自己写好在线安装的redis脚本,本文主要使用shell函数来实现并且验证在线安装的过程,执行无误后就想着分享出来. PS:系统环境为Centos7.4 脚本如下: #!/bin/bash function checkroot(){ if [ $UID -ne 0 ] then echo "|------------

Linux基础之-利用shell脚本实现自动监控系统服务

目的:监控集群内nginx及nfs服务运行是否正常,如任一服务异常,则发送邮件通知用户 条件:1. 主机及子机IP地址,hostname已确定: 2. 主机与子机能够免密通讯,即基于密匙通讯(相关命令:ssh-keygen;ssh-copy-id -i web1); 需要的文件:    1. python邮件发送工具: 2. nfc.sh监控脚本,监控nginx及nfs服务状态,并调用mail发送工具通知用户: 3. nfc-install.sh监控部署脚本,运行在主机,为子机配置文件,执行命令

PXE自动安装Linux 系统

                 PXE自动安装Linux 系统 1.PXE简介2119731621 当需要安装的操作系统比较多时,手动安装是不现实的,这个时候就要借助PXE了. PXE全称是:Preboot Excution Environment 预启动执行环境是由Intel公司研发的基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统 PXE可以引导和安装Windows,linux等多种操作系统. 2. 实验步骤 (1) 环境准

一个自动安装LNMP的简洁Shell脚本

此脚本在生产服务器上使用了一年多,本脚本崇尚简单唯美,只需要一个脚本就可以在任何一台有网络的服务器上自动配置LNMP.本脚本会在脚本执行目录下,建packages目录用于存放LNMP所需要的软件.大家安装完可以删除该目录. 使用方法:1.把shell脚本的内容保存为nginx_php2.root权限下运行:chmod u+x nginx_php; ./nginx_php init; ./nginx_php ins_mysql-server; ./nginx_php ins_mysql-clien

无人值守自动安装linux系统

PXE基本原理概述 什么是PXE? PXE:pre-boot executionenvironment预启动执行环境 由intel公司开发的技术 工作于C/s的网络模式 Client通过网络从server下载映像,并通过网络启动操作系统 应用场景 liveOS OS安装 PXE基本原理 1 Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC 地址),如果合法则返回Client的IP 地址,同时将启动文件pxel

shell 搭配 python 自动安装zabbix监控端详解

脚本环境 1.linux centos 7 系统2.光盘镜像文件已挂载3.系统可连接外网4.字体链接:https://pan.baidu.com/s/1m9WJys5aGuUi-WgBG-zrxw 提取码:qq6r 实验步骤 1.上传字体文件和zabbix脚本到Linux系统/root目录下 方法一:挂载 方法二:通过Xftp软件上传 2.脚本zabbix.sh详解 #!/bin/bash#this is auto install lamp + zabbix shell!##获取ip地址ip=`

自动安装 linux 系统方法一:

基于图形软件生成应答文件,实现自动安装 linux 操作系统 1.yum install -y system-config-kickstart 安装生成自动化安装操作系统的应答文件 2.system-config-kickstart              执行生成应答文件的图形化工具 3.自动化安装基于网络方式安装,提前配置好 HTTP 服务器 4.安装 boot loader 5.清空 MBR.删除所有分区.初始化标签.创建分区 6.添加个网卡: eth0,提前搭建好 DHCP 服务器 7