千家信息网

如何实现全自动安装LNMP服务器环境的Shell脚本

发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,这篇文章主要介绍"如何实现全自动安装LNMP服务器环境的Shell脚本",在日常操作中,相信很多人在如何实现全自动安装LNMP服务器环境的Shell脚本问题上存在疑惑,小编查阅了各式资料,整理出简单好
千家信息网最后更新 2025年02月03日如何实现全自动安装LNMP服务器环境的Shell脚本

这篇文章主要介绍"如何实现全自动安装LNMP服务器环境的Shell脚本",在日常操作中,相信很多人在如何实现全自动安装LNMP服务器环境的Shell脚本问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"如何实现全自动安装LNMP服务器环境的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

到此,关于"如何实现全自动安装LNMP服务器环境的Shell脚本"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

脚本 服务器 服务 全自动 环境 学习 目录 代码 内容 方法 更多 帮助 运行 唯美 实用 接下来 使用方法 文章 权限 理论 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 上海光学作图软件开发公司 软件开发人员是不是程序员 webex服务器晚上有信号吗 江西高校党建软件开发公司 怎么连接逍遥魔兽数据库 数据库平均成绩统计计算 惠普380服务器管理 聊城商城软件开发服务公司 建筑服务器有什么好处 网络安全周教育主题班会 张家界计算机网络技术 校园网络安全工作保障情况 软件开发和支持公司简介 活字格服务器换机器 管理我的世界服务器 考勤管理信息系统数据库实验设计 计算机网络技术语言 安全ftp服务器操作记录 excei如何做简单的数据库 四川三维人口gis系统软件开发 上海光学作图软件开发公司 魔兽世界tbc狮心服务器公会 软件开发项目科研经费 软件开发实施规范 网络安全工程师35岁好找工作吗 网络技术部年度计划 广东软件开发需要什么 深圳市人人时代网络技术 和平精英脚本服务器 通信工程概预算定额数据库
0