码迷,mamicode.com
首页 > 其他好文 > 详细

lnmp脚本

时间:2017-09-20 16:43:02      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:lnmp

#!/bin/bash
#Function: Install LNMP
#Author: wang
#Date: 20170809

nginx_install(){
useradd www -u 509 -s /bin/bash -m
mkdir -p /opt/server/nginx/temp

#Install the make GCC
yum -y install gcc gcc-c++ automake autoconf libtool make

#Installing PCRE library (to rewrite)
cd /root/package
echo "Start installing PCRE..."
#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz  #shixiao
#wget http://120.52.73.48/jaist.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
tar fxz pcre-8.37.tar.gz
cd pcre-8.37
./configure
make && make install
A=`echo $?`
if [ $A == 0 ];then
        echo "The GCC has been successfully installed !!!"
        cd ..
else
        echo "GCC installed there is a problem, the script will exit !!!"
        exit 1
fi

#Install zlib library (for gzip compression)
echo "Start the installation zlib library..."
#wget http://zlib.net/zlib-1.2.8.tar.gz
tar fxz zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install

B=`echo $?`
if [ $B == 0 ];then
        echo "Zlib has been successfully installed !!!"
        cd ..
else
        echo "Zlib installed there is a problem, the script will exit !!!"
        exit 1
fi

#Install the SSL
echo "Install the SSL ..."
wget http://www.openssl.org/source/openssl-1.0.1p.tar.gz -P /usr/local/src/
cd /usr/local/src
tar fxz openssl-1.0.1p.tar.gz
cd openssl-1.0.1p
./config
make && make install

C=`echo $?`
if [ $C == 0 ];then
        echo "SSL has been successfully installed !!!"
        cd /root/package
else
        echo "SSL installed there is a problem, the script will exit !!!"
        exit 1
fi

#Install nginx
echo "Begin to install nginx ..."
#wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar fxz nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/opt/server/nginx \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_sub_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_spdy_module \
--with-ipv6 \
--http-fastcgi-temp-path=/opt/server/nginx/temp/fastcgi \
--http-client-body-temp-path=/opt/server/nginx/temp/client \
--http-proxy-temp-path=/opt/server/nginx/temp/proxy \
--http-scgi-temp-path=/opt/server/nginx/temp/scgi \
--http-uwsgi-temp-path=/opt/server/nginx/temp/uwsgi \
--with-openssl=/usr/local/src/openssl-1.0.1p
make && make install

D=`echo $?`
if [ $D == 0 ];then
        echo "Nginx successful installation !!!"
        cd ..
else
        echo "Nginx installation has a problem, the script exits !!!"
        exit 1
fi

cd /lib64
ln -s libpcre.so.0.0.1 libpcre.so.1

#To optimize configuration file nginx.conf
cat > /opt/server/nginx/conf/nginx.conf << EOF
user  www;
worker_processes  4;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  20480;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    server_tokens off;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 6;
    tcp_nodelay on;
    client_header_timeout 15;
    client_body_timeout 15;
    send_timeout 15;
    client_max_body_size 10m;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout        300;
    fastcgi_buffer_size 2048k;
    fastcgi_buffers 4 2048k;
    fastcgi_busy_buffers_size 2048k;
    fastcgi_temp_file_write_size 2048k;

    gzip on;
    gzip_buffers 4 32k;
    gzip_comp_level 9;
    gzip_min_length 1k;
    gzip_http_version 1.1;
    gzip_types text/css text/xml application/javascript application/msword application/pdf;

    allow  182.18.19.162; #gongsi
    allow  211.157.168.138; #gongsi
#    deny   all;

    include /opt/server/nginx/vhosts/*.conf;
}
EOF

mkdir /opt/server/nginx/vhosts -p
touch /opt/server/nginx/vhosts/fengkong.conf
cat > /opt/server/nginx/vhosts/fengkong.conf << EOF
log_format fengkong.wanglibao.com
 ‘\$http_x_forwarded_for - \$remote_addr [\$time_local] "\$request" ‘
 ‘\$status \$body_bytes_sent "\$http_referer" ‘
 ‘"\$http_user_agent" \$http_x_clientip‘;

    server {
        listen       80;
        server_name  fengkong.wanglibao.com;
        access_log  logs/fengkong.wanglibao.com.access.log fengkong.wanglibao.com;
        error_log  logs/fengkong.wanglibao.com.error.log error;
        root   /app/fengkong/web;


        location / {
        index  admin.php index.php index.html index.htm;
        }

        location ~ \.php\$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /app/fengkong/web\$fastcgi_script_name;
        include        fastcgi_params;
        }

        location ~ .*\.(git|svn|gitignore)\$ {
            deny all;
        }
    }
EOF

#Start the nginx
echo "Start the nginx..."
/opt/server/nginx/sbin/nginx
netstat -ntpl

}

php_install(){
#Install some libraries
echo "===========Install some libraries...============"
yum  install epel-release -y
yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel libiconv readline-devel gdbm-devel

#Installing PHP
echo "================Installing PHP...==================="
cd /root/package/
mkdir -p /opt/server/php
#wget http://cn2.php.net/distributions/php-5.6.14.tar.gz
tar fxz php-5.6.14.tar.gz
cd php-5.6.14
./configure \
--prefix=/opt/server/php \
--with-mysql=/opt/server/mysql \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-freetype-dir \
--with-png-dir \
--with-libxml-dir=/usr \
--enable-xml \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-fpm \
--with-mcrypt \
--with-gettext \
--enable-mbstring \
--with-curl \
--with-curlwrappers \
--disable-debug  \
--disable-rpath \
--enable-inline-optimization \
--with-bz2  \
--with-zlib \
--enable-sockets \
--with-xmlrpc \
--enable-dba \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--with-gdbm \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--with-pcre-regex \
--with-gd \
--enable-gd-native-ttf \
--with-jpeg-dir \
--with-openssl \
--enable-ftp \
--with-readline \
--enable-shared \
--with-pear \
--with-iconv
make
make install
A=`echo $?`
if [ $A == 0 ];then
        echo "=============PHP installation is successful!!!============="
else
        echo "=============PHP installation failure!!!=============="
        exit 1
fi

#Configure PHP-FPM
echo "===============Configure PHP-FPM...================"
/bin/cp /root/package/php-5.6.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /root/package/php-5.6.14/php.ini-production /opt/server/php/lib/php.ini
chmod +x /etc/init.d/php-fpm
chkconfig --add /etc/init.d/php-fpm
chkconfig php-fpm on
cd /opt/server/php/etc
/bin/cp php-fpm.conf.default php-fpm.conf

cat >php-fpm.conf<<EOF
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = error
rlimit_files = 32768

[www]
user = www
group = www
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
pm = dynamic
pm.max_children = 1024
pm.start_servers = 16
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.process_idle_timeout = 15s;
pm.max_requests = 2048
access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
slowlog = /opt/server/php/var/log/$HOSTNAME.log.slow
request_slowlog_timeout = 3
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f dengyong@wanglibank.com
EOF

#Install the pdo module
echo "=============Install the pdo module !!! ====================="
cd /root/package/php-5.6.14/ext/pdo
/opt/server/php/bin/phpize
./configure --with-php-config=/opt/server/php/bin/php-config --enable-pdo=shared
make
make install
D=`echo $?`
if [ $D == 0 ];then
        echo "=============The pdo module installation is successful !!!============="
else
        echo "============The pdo module installation failed !!!=============="      
        exit 1
fi

#Install the pdo mysql module
echo "=================Install the pdo mysql module !!! ==========================="
cd /root/package/php-5.6.14/ext/pdo_mysql
/opt/server/php/bin/phpize
./configure --with-php-config=/opt/server/php/bin/php-config
make
make install
E=`echo $?`
if [ $E == 0 ];then
        echo "=============The pdo mysql module installation is successful !!!============="
else
        echo "============The pdo mysql module installation failed !!!=============="      
        exit 1
fi

#Modify the PHP.ini file
echo "==================Modify the PHP.ini file !!!  ========================"
cat >> /opt/server/php/lib/php.ini << EOF
extension=pdo_mysql.so
;extension=pdo.so
;extension=xhprof.so
zend_extension=opcache.so

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=300
opcache.fast_shutdown=1
opcache.enable_cli=1

EOF

G=`echo $?`
if [ $G == 0 ];then
        :
else
        echo "============The PHP file php.ini error exit !!!=============="      
        exit 1
fi

/opt/server/php/sbin/php-fpm -t
H=`echo $?`
if [ $H == 0 ];then
        :
else
        echo "============PHP has syntax errors, please check !!!=============="      
        exit 1
fi

#Start the PHP-FPM
echo "=============Start the PHP-FPM...==============="
/etc/init.d/php-fpm start
netstat -ntpl
}

mysql_install(){
#Install cmake
echo "===========================Install cmake openssl ncurses ...====================="
yum -y install cmake openssl openssl-devel ncurses-devel gcc gcc-c++

#Create a mysql user
echo "========================Create a mysql user...==================="
groupadd  mysql
useradd -g mysql mysql

cd /root/package/
mkdir /opt/server/mysql/data -p

#Mysql installation
echo "======================Mysql installation...====================="
#wget http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.14.tar.gz
tar fxz mysql-5.6.14.tar.gz
cd mysql-5.6.14
cmake . -DCMAKE_INSTALL_PREFIX=/opt/server/mysql \
-DMYSQL_DATADIR=/opt/server/mysql/data \
-DINSTALL_PLUGINDIR=plugin \
-DINSTALL_SHAREDIR=share \
-DINSTALL_LIBDIR=lib64 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DMYSQL_UNIX_ADDR=/opt/server/mysql/mysqld.sock \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=OFF \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_PROFILING=0
make
make install

A=`echo $?`
if [ $A == 0 ];then
        echo "=================== Mysql installation is successful !!! ======================"
        cd ..
else
        echo "=================== Mysql installation failure !!! ======================="
        exit 1
fi

chown -R mysql.mysql /opt/server/mysql
#/bin/cp /opt/server/mysql/support-files/my-default.cnf /etc/my.cnf
rm -fr /etc/my.cnf
rm -fr /opt/server/mysql/my.cnf

cat >> /etc/my.cnf << EOF
[client]
port            = 3306
socket          = /opt/server/mysql/mysqld.sock
[mysqld]
port            = 3306
socket          = /opt/server/mysql/mysqld.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 100M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 1024K
read_rnd_buffer_size = 5120K
myisam_sort_buffer_size = 8M
slow_query_log = 1
#log=/tmp/mysqlquery.log
slow_query_log_file=/opt/server/mysql/logs/mysql_slow.log
long-query-time=1
log-bin=mysql-bin
server-id       = 1
sql_mode = 0
[mysqldump]
quick
#max_allowed_packet = 16M
#wait_timeout=28800
#interactive_timeout = 2880000
max_allowed_packet = 100M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

EOF

 

#To initialize the database
cd /opt/server/mysql
./scripts/mysql_install_db --user=mysql --basedir=/opt/server/mysql/
B=`echo $?`
if [ $B == 0 ];then
        echo "=================== To initialize the database successfully !!! =================="
else
        echo "==================== Database initialization failed !!! ================"
        exit 1
fi

mv /opt/server/mysql/my.cnf /opt/server/mysql/my.cnf_bak

#Mysql added to the system service
echo "===================== Mysql added to the system service...=============="
cp /opt/server/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 235 mysql on

#Start the mysql
echo "==================Start the mysql...========================"
/etc/init.d/mysql start
netstat -ntpl
}

case $1 in
    nginx)  nginx_install
    ;;
    php)  php_install
    ;;
    mysql)  mysql_install
    ;;
    all) 
    nginx_install
    php_install
    mysql_install
    ;;
    *) echo "Usage: `dirname $0`/`basename $0` [nginx|php|mysql|all]"
    ;;
esac

本文出自 “12632850” 博客,请务必保留此出处http://12642850.blog.51cto.com/12632850/1967047

lnmp脚本

标签:lnmp

原文地址:http://12642850.blog.51cto.com/12632850/1967047

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!