一个简洁的全自动安装LNMP服务器环境的Shell脚本分享_linux shell

此脚本在生产服务器上使用了一年多,本脚本崇尚简单唯美,只需要一个脚本就可以在任何一台有网络的服务器上自动配置LNMP。

本脚本会在脚本执行目录下,建packages目录用于存放LNMP所需要的软件。大家安装完可以删除该目录。

使用方法:

1、把shell脚本的内容保存为nginx_php

2、root权限下运行:

复制代码 代码如下:

chmod u+x nginx_php; ./nginx_php init; ./nginx_php ins_mysql-server; ./nginx_php ins_mysql-client; ./nginx_php ins_php52; ./nginx_php ins_php52-ext; ./nginx_php ins_mysql

在脚本运行过程中需要输入一次y确认。

Shell脚本内容如下:

复制代码 代码如下:

#/bash
# author:coralzd powered by www.freebsdsystem.org
# written by coralzd 2011.05.05
# version 0.1.3 build 20110505
nginx_dir="/usr/local/nginx"
php52_dir="/usr/local/php52"
mysql_dir="/usr/local/mysql"

function init()
{

LANG=C
yum -y install wget gcc gcc-c++ autoconf 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 openldap openldap-devel nss_ldap openldap-clients openldap-servers

read -p "Now,will download nginxphp software...Y|y:" nginxphp

case "$nginxphp" in

Y|y)

echo -n "starting download nginx_php ..."
cat > list << "EOF" &&
nginx-1.0.0.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.52.tar.gz
pcre-8.10.tar.gz
eaccelerator-0.9.6.1.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
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
;;

*)

echo -n "exit install script"
exit 0
;;

esac

groupadd www && useradd www -s /sbin/nologin -g www
groupadd mysql && useradd mysql -s /sbin/nologin -g mysql
echo "www and mysql user && group create!"

/bin/rm -rf list

echo -e "All of installed sucussful!"
}
function is_version()

{
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()

{

cd packages

is_version
tar zxf google-perftools-1.6.tar.gz
cd google-perftools-1.6
./configure
make
make install

cd ..
tar zxf pcre-8.10.tar.gz
cd pcre-*
./configure
make
make install
cd ..
tar zxf nginx-1.0.0.tar.gz
cd nginx-1.0.0
./configure --prefix=${nginx_dir} --with-google_perftools_module --user=www --group=www --with-http_stub_status_module --with-http_flv_module --with-http_ssl_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_mysql-server()
{

cd packages/
tar zxf mysql-5.1.52.tar.gz
cd mysql-5.1.52
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
./configure "--prefix=${mysql_dir}" "--with-server-suffix=-DZWWW" "--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" "--with-plugins=partition,myisammrg" "--without-ndb-debug"

make && make install
cp support-*/mysql.server /etc/init.d/mysqld
cd /usr/local/mysql
chown -R mysql:mysql .
rm -rf sql-bench mysql-test
echo "mysql server 5.1.52 installed successfully!"
}
function ins_mysql-client()
{

cd packages/
tar zxf mysql-5.1.52.tar.gz
cd mysql-5.1.52
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.52 installed successfully!"
}
function ins_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 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/
./configure --prefix=${php52_dir} --with-config-file-path=${php52_dir}/etc --with-mysql=${mysql_dir} --with-mysqli=${mysql_dir}/bin/mysql_config --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
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_php52-ext()

{
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.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
${php52_dir}/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=${php52_dir}/bin/php-config
make
make install
cd ../

tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
${php52_dir}/bin/phpize
./configure --with-php-config=${php52_dir}/bin/php-config --with-pdo-mysql=${mysql_dir}
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!"
}

case $1 in
init)

init
;;
ins_mysql-server)

ins_mysql-server

;;
ins_mysql-client)
ins_mysql-client
;;
ins_nginx)
ins_nginx
;;
ins_php52)
ins_php52
;;
ins_php52-ext)
ins_php52-ext
;;
*)
echo "Usage:`basename $0` {init|ins_mysql-server|ins_mysql-client|ins_php52|ins_php52-ext|ins_mysql}"
;;
esac

时间: 2024-09-12 18:57:33

一个简洁的全自动安装LNMP服务器环境的Shell脚本分享_linux shell的相关文章

阿里云主机一键安装lamp、lnmp环境的shell脚本分享_linux shell

阿里云主机一键安装lamp,lnmp,自动安装脚本,由阿里云主机分享 一键安装包下载地址:点击下载 1.阿里云分享的一键安装lamp,lnmp,此安装包包含的软件及版本为: 复制代码 代码如下: nginx:1.0.15.1.2.5.1.4.4 apache:2.2.22.2.4.2 mysql:5.1.73.5.5.35.5.6.15 php:5.3.18.5.4.23.5.5.7 php扩展:memcache.Zend Engine/ OPcache ftp:(yum/apt-get安装)

Ubuntu下定时提交代码到SVN服务器的Shell脚本分享_linux shell

有两个用途,一是偷懒不用去提交代码,二是在远程服务器上使用以作定期备份. 复制代码 代码如下: sudo gedit /etc/crontab 打开后加入这行 复制代码 代码如下: 0 * * * * my_user_name    my_script_path 表示每个整点以my_user_name身份执行my_script_path.这里最好是使用当前的用户名,修改掉默认的root,否则可能以root身份会提交失败.详情请询问百度crontab的用法. 然后script的内容为: 复制代码

一个监控Squid运行进程数并自动重启的简洁Shell脚本分享_linux shell

复制代码 代码如下: #!/bin/sh while sleep 30 do SquidNum=`ps -ef|grep squid|grep -v grep|wc -l` #HttpNum=`netstat -an|grep 0.0.0.0:80|grep -v grep|wc -l` #80状态 if [ $SquidNum != 3 ] ; then /etc/rc3.duid start adddate=`date +%Y-%m-%d`" "`date +%H:%M:%S` e

Ubuntu、Linux Mint一键安装Chrome浏览器的Shell脚本分享_linux shell

把下面的脚本保存为xxx.sh,然后 sudo sh xxx.sh 复制代码 代码如下: wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/googl

一个简单的防CC攻击Shell脚本分享_linux shell

实现代码: 复制代码 代码如下: #!/bin/shcd /var/log/httpd/cat access_log|awk '{print $1}'|sort|uniq -c|sort -n -r|head -n 20 > acp /dev/null access_logcp /dev/null error_logcp /dev/null limit.shcp /dev/null c#awk '{print $2}' a|awk -F. '{print $1"."$2"

分享一个入门级可控多线程shell脚本代码_linux shell

说到shell可控多线程,网上分享的大部分是管道控制的方案.这种方案,张戈博客也曾经实战并分享过一次:<Shell+Curl网站健康状态检查脚本,抓出中国博客联盟失联站点>,感兴趣的朋友可以看看. 分享一个入门级可控多线程shell脚本方案 下面张戈博客再分享另一种更容易理解的入门级可控多线程shell脚本方案:任务切割.各个击破. 先来 1 段场景描述: 某日,在鹅厂接到了这个任务,需要在Linux服务器中,对几千个IP进行一次Ping检测,只要取得ping可达的IP就好.如果单个IP去pi

一个简单的转换输出的shell脚本代码_linux shell

一个简单的转换输出的shell脚本,从健盘输入 a,b,c 这种格式  输出如下格式:a c 复制代码 代码如下: #!/bin/bashread -p '请输入:'echo $REPLY >.tmp5count=`grep -o ',' .tmp5 |wc -l`echo $countcount_=$((count+1))i=1:>.tmp1while [ $i -le $count_ ]do   echo $i   awk -F, -v j="$i"  '{print$

linux安装php扩展脚本分享_linux shell

测试环境:ubuntu 12.04 php 5.3.x 复制代码 代码如下: #!/bin/bash#Program:# Accomplish to expand the specified function only one key#History:# 2013/11/15 pankai<530911044@qq.com> first releasetest ! -f ./ext_skel && echo "The shell script of 'ext_skel

linux服务器安全加固shell脚本代码_linux shell

复制代码 代码如下: #!/bin/sh# desc: setup linux system security# author:coralzd # powered by www.freebsdsystem.org# version 0.1.2 written by 2011.05.03#account setup passwd -l xfspasswd -l newspasswd -l nscdpasswd -l dbuspasswd -l vcsapasswd -l gamespasswd -