出产服务器LNMP全自动装置脚本51CTO博客 - AG环亚娱乐

出产服务器LNMP全自动装置脚本51CTO博客

2019年04月02日11时53分50秒 | 作者: 依丝 | 标签: 装置,脚本,检测 | 浏览: 883

【51CTO独家特稿】此脚本在出产效劳器上使用了一年多,能够在任何一台有网络的效劳器上主动装备LNMP。

使用方法:将nginx_php代码保存一个文件,例如nginx_php。上传到效劳器上履行。

此脚本在CentOS 5.6 i386/x86_64环境下经过。

bash nginx_php呈现提示,如下列图所示。

依据我们自己的需求挑选数字中恣意一个,开端全主动装置LNMP的国际中去吧。

假如之前装置过nginx或许 php 的话,脚本会主动检测它们是不是装置过。例如

就会提示nginx或许php 现已装置过了。

nginx_php 源码

#!/bin/bash
# author:coralzd powered by www.freebsdsystem.org
# written by coralzd 2011.09.30
# version 0.1.5 build 20110930

nginx_dir="/usr/local/nginx"
php52_dir="/usr/local/php52"
mysql_dir="/usr/local/mysql"

function check_init() #检测初始化作业有没有履行
{
 if [ `rpm -qa |grep re2c`  "re2c-0.12.1-2.el5.x86_64" ];then
 echo "init already exec!"
 exit 0
 fi
}
 
function check_nginx() #检测nginx有没有装置
{
 if [ -d /usr/local/nginx/ ];then
  echo "nginx already installed!"
 exit 1   
 fi
}

function check_php52() #检测php有没有装置
{
 if [ -d /usr/local/php52 ];then
   echo "php 5.2.17 already installed!"
  exit 1
 fi
}

function check_mysql() #检测mysql有没有装置
{
  if [ -d /usr/local/mysql/ ];then
  echo -n "mysql already installed!"
  exit 1
  fi
}
function init() #体系初始化作业
{
yum -y install wget gcc gcc-c++ autoconf bison flex re2c  libmhash libjpeg libjpeg-devel libpng libpng-devel \
freetype freetype-devel gd gd-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-devel libidn libidn-devel openssl openssl-devel 
   
echo -n "starting download nginx_php ..."
cat > list << "EOF" &&
nginx-1.0.1.tar.gz
php-5.2.17.tar.gz
php-5.2.17-fpm-0.5.14.diff.gz
libiconv-1.13.1.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.5.tgz
mhash-0.9.9.9.tar.gz
mysql-5.1.58.tar.gz
suhosin-patch-5.2.17-0.9.7.patch
pcre-8.10.tar.gz
autoconf-2.13.tar.gz
eaccelerator-0.9.5.3.tar.bz2
PDO_MYSQL-1.0.2.tgz
libunwind-0.99.tar.gz
ImageMagick.tar.gz
imagick-2.3.0.tgz
google-perftools-1.6.tar.gz
fcgi.conf
php.ini
php-fpm
nginxd
my.cnf
nginx.conf
php-fpm.conf
EOF
mkdir packages
    for i in `cat list`
do
if [ -s packages/$i ]; then
  echo "$i [found]"
else
  echo "Error: $i not found!!!download now......"
  wget http://www.freebsdsystem.org/linux/nginx-php/$i -P packages/
fi

done
mv packages/nginxd /etc/init.d/
mv packages/php-fpm /etc/init.d/
chmod 755 /etc/init.d/*
chkconfig add nginxd
chkconfig add php-fpm
echo "create the eaccelerator directory to /data0/cache"
mkdir /data0/cache
echo "create the mysql data directory to /data0/mysql/data"
mkdir -p /data0/mysql/data
echo "PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile
source  /etc/profile
groupadd -g 80 www &&  useradd www -s /sbin/nologin -g www -u 80
groupadd -g 3306 mysql && useradd mysql -s /sbin/nologin -g mysql -u 3306
echo "www and mysql user && group create!"
cd packages/
/bin/rm -rf list
echo -e "All of installed sucussful!"

}
function is_version() #检测体系是64位的仍是32位的?
{
if [ `uname -m`  "x86_64" ];then
tar zxf libunwind-0.99.tar.gz
tar zxvf libunwind-0.99.tar.gz
cd libunwind-0.99/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
cd ../
else
    echo "your system is 32bit ,not install libunwind lib!"
fi

}
function ins_nginx()#装置nginx
{
check_nginx
cd packages/
is_version
tar zxf google-perftools-1.6.tar.gz
cd google-perftools*
./configure
make
make install
cd ..
tar zxf pcre-8.10.tar.gz
cd pcre-*
./configure 
make
make install 
cd ..
tar zxf nginx-1.0.1.tar.gz
cd nginx-1.0.1
./configure prefix=${nginx_dir} user=www group=www with-http_stub_status_module 
make && make install
cd .. 
rm -rf /usr/local/nginx/conf/nginx.conf
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf 
cp nginx.conf /usr/local/nginx/conf/
cp fcgi.conf /usr/local/nginx/conf/
echo "nginx installed sucussfully!"
}
function ins_mysqlserver()# 装置mysql效劳端
{
cd packages/
tar zxf mysql-5.1.58.tar.gz
cd mysql-5.1.58
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
./configure prefix=/usr/local/mysql enable-assembler with-server-suffix=-DZWWW enable-thread-safe-client enable-local-infile enable-thread-safe-client with-big-tables with-charset=utf8 with-client-ldflags=-all-static with-collation=utf8_general_ci with-extra-charsets=all with-mysqld-ldflags=-all-static with-mysqld-ldflags=-ltcmalloc  with-mysqld-user=mysql with-plugins=partition,myisammrg with-pthread with-unix-socket-path=/tmp/mysql.sock without-ndb-debug 
make && make install 
cp support-*/mysql.server /etc/init.d/mysqld
cp my.cnf /etc/
chmod 744 /etc/init.d/mysqld
cd /usr/local/mysql
chown -R mysql:mysql .
rm -rf sql-bench mysql-test
mkdir -p /data0/mysql/relaylog/
mkdir -p /data0/mysql/binlog/
chown -R mysql.mysql /data0/mysql
/usr/local/mysql/bin/mysql_install_db user=mysql basedir=/usr/local/mysql datadir=/data0/mysql/data
echo "mysql server  5.1.58 installed successfully!"
}
function ins_mysqlclient() #装置mysql客户端
{
cd packages/
tar zxf mysql-5.1.58.tar.gz
cd mysql-5.1.58
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
./configure "prefix=${mysql_dir}" "with-mysqld-user=mysql" "without-debug" "with-charset=utf8"  "with-extra-charsets=all"  "with-pthread" "with-big-tables" "enable-thread-safe-client" "enable-assembler" "with-readline" "with-ssl" "enable-local-infile"  "without-server" 
make && make install
cd /usr/local/mysql
chown -R mysql:mysql .
rm -rf sql-bench mysql-test
echo "mysql client  5.1.58 installed successfully!"
}
function ins_php52()#装置php 
{
check_php52
cd packages/
tar zxf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure prefix=/usr/local
make
make install
cd ../
tar zxf autoconf-2.13.tar.gz
cd autoconf-2.13
./configuire prefix=/usr
make && make install
cd ..
tar zxf 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 ../../
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
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/bin/libmcrypt-config /usr/bin/libmcrypt-config

tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../

tar zxf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17/
patch -p1 -i ../suhosin-patch-5.2.17-0.9.7.patch
./buildconf force  
./configure prefix=${php52_dir} with-mysql=/usr/local/mysql with-mysqli=/usr/local/mysql/bin/mysql_config with-config-file-path=${php52_dir}/etc  with-iconv-dir=/usr/local with-freetype-dir with-jpeg-dir with-png-dir with-zlib with-libxml-dir=/usr enable-xml disable-rpath enable-discard-path enable-safe-mode enable-bcmath enable-shmop enable-sysvsem enable-inline-optimization with-curl with-curlwrappers enable-mbregex enable-fastcgi enable-fpm enable-force-cgi-redirect enable-mbstring with-mcrypt with-gd enable-gd-native-ttf with-openssl with-mhash enable-pcntl enable-sockets with-ldap with-ldap-sasl with-xmlrpc enable-zip enable-soap enable-suhosin enable-ftp 
make ZEND_EXTRA_LIBS=-liconv
make install
cd ..
cp php.ini /usr/local/php52/etc/
cp php-fpm.conf /usr/local/php52/etc/

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf.d/mysql_lib.conf
/sbin/ldconfig
echo "php52 installed successfully!"
}

function ins_php52ext() #装置php 扩展
{
cd packages/
tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5/
${php52_dir}/bin/phpize
./configure with-php-config=${php52_dir}/bin/php-config
make
make install
cd ../

tar jxf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
${php52_dir}/bin/phpize
./configure enable-eaccelerator=shared with-eaccelerator-shared-memory with-php-config=${php52_dir}/bin/php-config
make
make install
cd ../

tar zxf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
tar zxf imagick-2.3.0.tgz
cd imagick-2.3.0/
${php52_dir}/bin/phpize
./configure with-php-config=${php52_dir}/bin/php-config
make
make install
cd ..

echo "php52 extension installed successfully!"

}
cat << EOF
-* The script is advocating a simple aesthetic, only one file to complete downloading, extract, configure, compile and install Nginx php mysql *-
-* 1  only install nginx                                         *-
-* 2  only install nginx php                                       *-
-*  3  installation of all(include nginx php mysql)                               *-
-*  4  only download software, no installation other                                *-
-* 5  only install php 5.2.17                                      *-
-* 6  only install mysql server 5.1.58                                   *-
EOF
read -p "Now select the top option to install LNMP...1|2|3|4|5|6:" selectopt
case "$selectopt" in
   "1")
   init
    ins_nginx
   ;;
   "2")
    init
    ins_nginx
    ins_mysqlclient
    ins_php52
   ins_php52ext
   ;;
   "3")
    init
    ins_nginx
    ins_mysqlserver
    ins_php52
    ins_php52ext
   ;;
   "4")
    init
   ;;
    "5")
   ins_php52
   ins_php52ext 
   ;;
   "6")
   ins_mysqlserver
   ;;
     *)
    echo "$0 nginx_php"
  ;;
esac

nginx_php 各部分功用叙述

不论装置nginx php和mysql,假如脚本检测体系没有履行脚本的时分,将会主动履行初始化作业(包含yum 装置相关组件和下载一切的软件包以及装备nginx php效劳)

nginx_php里的函数init 表明初始化,分几步来履行初始化:

1) yum 装置nginx php mysql相关组件

2) 在没有发现当时目录有packages的情况下, wget 下载软件包、装备文档、效劳脚本到创立的packages下,之后删去软件列表。

3) 设置nginx和php-fpm效劳

4) 创立eaccelerator 缓存目录/data0/cache,创立mysql数据目录/data0/mysql/data

5) 将mysql bin途径参加体系PATH中。

6) 创立myql组和mysql用户,www组和www用户

函数check_init表明,检测初始化作业有没有履行。

函数check_nginx表明,检测nginx有没有装置

函数check_php52表明,检测php有没有装置

函数check_mysql表明,检测mysql有没有装置

函数is_version表明,检测体系是64位的仍是32位的,假如是64位的话,就装置libunwind库,由于google-perftools在64位体系顶用到了libunwind库,在32位的是不需求装置libunwind库的。

函数ins_nginx表明装置nginx,其中有判别体系是否是64位,以便于顺畅装置google-pertfools。

函数ins_mysqlclient表明装置mysql 客户端,这是让php 能够衔接mysql server。

函数ins_mysqlserver表明装置mysql 效劳端,并设置mysql装置目录为mysql组和mysql用户一切,现已装备mysql体系库。

函数ins_php52表明装置php,包含libiconv、autoconf、libmcrypt、mhash、mcrypt、suhosin等装置。并装备php.ini

函数ins_php52ext表明装置php的扩展,包含mecache、eacceletator、imagick等装置。

 

【51CTO.com独家特稿,转载请注明原文作者和出处。】

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表AG环亚娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章