3)安装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/
mv /root/package/openssl-1.0.1p.tar.gz /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-pdo-mysql=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

常用脚本lnmp的更多相关文章

  1. MS SQL 日常维护管理常用脚本(二)

    监控数据库运行 下面是整理.收集监控数据库运行的一些常用脚本,也是MS SQL 日常维护管理常用脚本(一)的续集,欢迎大家补充.提意见. 查看数据库登录名信息   Code Snippet SELEC ...

  2. Inno Setup的常用脚本

    Inno Setup的常用脚本 分类: VC++神奇理论 2012-12-06 10:07 3234人阅读 评论(2) 收藏 举报 安装不同的目录: [Files] Source: "我的程 ...

  3. 常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript

    常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript Javascript现阶段还不适合用来做独立开发,它的天下还是在web应用 ...

  4. shell常用脚本

    shell常用脚本 author:headsen chen  2017-10-17 15:36:17 个人原创,转载请注明,否则依法追究法律责任 1,vim  name.grep.sh 2,cat   ...

  5. Google常用脚本

    1.Tampermonkey 可下载常用脚本:https://greasyfork.org/zh-CN 2.常用FQSetupVPN 3.百度药丸屏蔽广告 4.百度文档可粘贴,下载 5.VIP视频可看

  6. 游戏编程之Unity常用脚本类的继承关系

    前言学习Unity开发引擎的初学者会接触大量的脚本类,而这些类之间的关系往往容易被忽略.本文对Unity引擎开发中的一些常用类及其关系进行了简单的归纳总结. 博文首发地址:http://tieba.b ...

  7. Linux 常用脚本

    Linux 常用脚本   修改表列属性   sql可任意修改,若数据库正好在执行机器上,可去掉ip地址 echo 为输出   #!/bin/shfor((i=0;i<256;i++));do   ...

  8. oracle 常用脚本以及语句

    oracle 常用脚本以及语句 一.oracle 安装10G 单机初始化环境: #!/bin/bash #关闭selinuxsed -i 's\SELINUX=enforcing\SELINUX=di ...

  9. PowerDesigner 设计数据库中常用脚本

    PowerDesigner 设计数据库中常用脚本 数据库设计 物理模型设置 Name转Comment脚本 '********************************************** ...

随机推荐

  1. iOS引用类型

    强引用, 默认引用类型.被强引用指向的内存不被释放.强引用会对被引用对象的引用计数器+1,从而扩展对象的生命周期. 弱引用, 弱引用是医用特殊的引用类型.它不会增加引用计数器,因而不会扩展对象的生命周 ...

  2. #include<stdio.h> #include "stdio.h"

    https://baike.baidu.com/item/#include <stdio.h> #include <stdio.h> 编辑 #include<stdio. ...

  3. Type Operators instanceof is used to determine whether a PHP variable is an instantiated object of a certain class/a class that implements an interface

    w 0-instanceof is used to determine whether a PHP variable is an instantiated object of a certain cl ...

  4. Orchard Core 中数据库使用postgresql-10

    在配置好Startup.cs后,运行程序: 首先需要设置一些基本信息.这里我试着配置如下,数据库使用postgresql,连接字符串像这样: Host=192.168.0.111;UserName=u ...

  5. 【Python全栈-jQuery】jQuery基础知识

    前端学习之jQuery 一. jQuery是什么? <1> jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. < ...

  6. js:return [ expression ],return false,return true,return的区别

    1.return [ expression ] return返回值实际上是对window.event.returnvalue进行设置. 2.return false,阻止默认的行为, ① 当给a标签绑 ...

  7. git的配置操作

    git配置信息 一.配置git config git config user.name 'yourName' git config user.name 'yourEmail@gmail.com' 二. ...

  8. 转载:caffe中的Reshape层

    http://blog.csdn.net/terrenceyuu/article/details/76228317 #作用:在不改变数据的情况下,改变输入的维度 layer { name: " ...

  9. python+rabbitMQ实现生产者和消费者模式

    (一)安装一个消息中间件,如:rabbitMQ (二)生产者 sendmq.py import pika import sys import time # 远程rabbitmq服务的配置信息 user ...

  10. sql server 复制常见问题及查看

    1.SQL Server同步复制问题排查方法http://blog.csdn.net/roy_88/article/details/41481059 2.[同步复制常见错误处理1]当IDENTITY_ ...