shell脚本一键安装LNMP菜单方式安装

#!/bin/bash
#定义软件包变量
Tnginx="nginx-1.6.0.tar.gz"
nginx="nginx-1.6.0"
Tcmake="cmake-2.8.6.tar.gz"
cmake="cmake-2.8.6"
Tlibmcrypt="libmcrypt-2.5.8.tar.gz"
libmcrypt="libmcrypt-2.5.8"
Tmcrypt="mcrypt-2.6.8.tar.gz"
mcrypt="mcrypt-2.6.8"
Tmhash="mhash-0.9.9.9.tar.gz"
mhash="mhash-0.9.9.9"
Tmysql="mysql-5.5.22.tar.gz"
mysql="mysql-5.5.22"
Tphp="php-5.3.28.tar.gz"
php="php-5.3.28"
Tzen="ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz"
zen="ZendGuardLoader-php-5.3-linux-glibc23-x86_64"
dir="/usr/local"
export PATH="/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
#定义菜单函数
c(){
#根据安装目录判断软件是否已经安装
if [ -d "$dir"/nginx ]
then
a=$(echo -e "\033[32m已安装\033[0m")
else
a=$(echo -e "\033[31m未安装\033[0m")
fi
which cmake &>/dev/null
if [ $? -eq 0 ]
then
b=$(echo -e "\033[32m已安装\033[0m")
else
b=$(echo -e "\033[31m未安装\033[0m")
fi
if [ -d "$dir"/mysql ]
then
c=$(echo -e "\033[32m已安装\033[0m")
else
c=$(echo -e "\033[31m未安装\033[0m")
fi
if [ -d "$dir"/php5 ]
then
d=$(echo -e "\033[32m已安装\033[0m")
else
d=$(echo -e "\033[31m未安装\033[0m")
fi
clear
echo "


   ||+++++++++++++++Use this script+++++++++++++++++++++||
   ||===================================================||
   ||+++++++++++++++服务名+++++++++++++||+++++状态++++++||
   ||==================================||===============||
   ||++++++++++1).NGINX Install++++++++||++++$a+++++||
   ||==================================||===============||
   ||++++++++++2).CMAKE Install++++++++||++++$b+++++||
   ||==================================||===============||
   ||++++++++++3).MySQL Install++++++++||++++$c+++++||
   ||==================================||===============||
   ||++++++++++4).PHP Install++++++++++||++++$d+++++||
   ||===================================================||
   "

read -p "请选择安装的服务 [1-4]" m
}
#定义安装nginx函数
install_nginx(){
yum install -y pcre-devel
if [ -d "$dir"/nginx ]
then
echo "Nginx已安装"
exit 0
else
id nginx &>/dev/null
if [ $? -ne 0 ]
then
useradd -M -s /sbin/nologin nginx
fi
if [ ! -f "$Tnginx" ]
then
echo "没有$Tnginx"
exit 1
else
tar xf "$Tnginx" -C "$dir"
cd "$dir"/"$nginx"/
./configure --prefix="$dir"/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module && make && make install
ln -s "$dir"/nginx/sbin/nginx "$dir"/sbin/
sed -i ‘9cpid logs/nginx.pid;‘ /usr/local/nginx/conf/nginx.conf
fi
fi
cd /root/
}
#定义CMAKE 安装函数
install_cmake(){
which cmake &>/dev/null
if [ $? -eq 0 ]
then
echo "CMAKE已安装"
exit 0
else
if [ ! -f "$Tcmake" ]
then
echo "没有$Tcmake"
exit 1
else
tar xf "$Tcmake"
cd "$cmake"
./configure && gmake && gmake install
fi
fi
cd /root/
}
#定义MySQL 安装函数
install_mysql(){
which cmake &>/dev/null
if [ $? -ne 0 ]
then
echo "请先安装CMAKE"
exit 0
fi
if [ -d "$dir"/mysql ]
then
echo "MySQL已安装"
exit 0
else
if [ ! -f "$Tmysql" ]
then
echo "没有$Tmysql"
exit 1
else
tar xf "$Tmysql" -C "$dir"
cd "$dir"/"$mysql"
"$dir"/bin/cmake -DCMAKE_INSTALL_PREFIX="$dir"/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all && make && make install
cp ./support-files/my-medium.cnf /etc/my.cnf
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
cp -f "$dir"/mysql/bin/ "$dir"/bin/
id mysql
if [ $? -ne 0 ]
then
useradd -M -s /sbin/nologin mysql
fi
chown -R mysql.mysql "$dir"/mysql
"$dir"/mysql/scripts/mysql_install_db --datadir="$dir"/mysql/data --basedir="$dir"/mysql --user=mysql
/etc/init.d/mysqld start
fi
fi
cd /root/
}
#定义PHP安装函数
install_php(){
if [ -d "$dir"/php5 ]
then
echo "PHP5 已安装"
exit 0
fi
if [ ! -d "$dir"/nginx -a "$dir"/mysql ]
then
echo "请先安装 Nginx,CMAKE,MySQL"
exit 1
else
rpm -qa gd libxml2-devel libjpeg-devel libpng-devel &>/dev/null
if [ $? -ne 0 ]
then
yum install -y gd libxml2-devel libjpeg-devel libpng-devel
fi
if [ ! -f $Tphp ]
then
echo "没有$Tphp "
else
tar xf "$Tphp" -C "$dir"
cd "$dir"/"$php"
./configure --prefix="$dir"/php5 --with-gd --with-zlib --with-mysql="$dir"/mysql --with-config-file-path="$dir"/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install
cp ./php.ini-development "$dir"/php5/php.ini
ln -s $dir/php5/bin/
$dir/bin/
ln -s $dir/php5/sbin/* $dir/sbin/
fi
fi
cd /root/
if [ ! -f "$Tzen" ]
then
echo "没有$Tzen"
exit 1
else
tar xf "$Tzen"
cd "$zen"/php-5.3.x/
cp ./ZendGuardLoader.so "$dir"/php5/lib/php/
sed -i ‘$azend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so‘ /usr/local/php5/php.ini
sed -i ‘$azend_loader.enable=1‘ /usr/local/php5/php.ini
fi
cd "$dir"/php5/etc
cp ./php-fpm.conf.default php-fpm.conf
sed -i ‘25cpid = run/php-fpm.pid‘ /usr/local/php5/etc/php-fpm.conf
sed -i ‘140cuser = nginx‘ /usr/local/php5/etc/php-fpm.conf
sed -i ‘141cgroup = nginx‘ /usr/local/php5/etc/php-fpm.conf
sed -i ‘222cpm.start_servers = 20‘ /usr/local/php5/etc/php-fpm.conf
sed -i ‘227cpm.min_spare_servers = 5‘ /usr/local/php5/etc/php-fpm.conf
sed -i ‘232cpm.max_spare_servers = 35‘ /usr/local/php5/etc/php-fpm.conf
sed -i ‘217cpm.max_children = 50‘ /usr/local/php5/etc/php-fpm.conf
/usr/local/sbin/php-fpm
sed -i ‘65c location ~ \.php$ {‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘66c root html;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘67c fastcgi_pass 127.0.0.1:9000;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘68c fastcgi_index index.php;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘69c include fastcgi.conf;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘70c }‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘71d‘ /usr/local/nginx/conf/nginx.conf
#添加PHP测试页面
echo "
<?php
phpinfo();
?>" >/usr/local/nginx/html/index.php
/usr/local/nginx/sbin/nginx
cd /root/
}
#挂载光盘
mount /dev/sr0 /media/cdrom/
#调用菜单函数
c
#判断变量是否为数字
expr "$m" + 1 &>/dev/null
if [ $? -eq 0 ] && [ ! -z $m ]
then
#当变量符合要求时,根据数字调用对应的函数
if [ $m -eq 1 ]
then
install_nginx
if [ $? -eq 0 ]
then
c
if [ $m -eq 2 ]
then
install_cmake
if [ $? -eq 0 ]
then
c
if [ $m -eq 3 ]
then
install_mysql
if [ $? -eq 0 ]
then
c
if [ $m -eq 4 ]
then
install_php
if [ $$ -eq 0 ]
then
echo -e "\033[32mLNMP install OK\033[0m"
exit 0
else
echo -e "\033[31mLNMP install false\033[0m"
exit 1
fi
fi
else
echo -e "\033[31mMySQL install false\033[0m"
exit 1
fi
fi
else
echo -e "\033[31mCMAKE install false\033[0m"
exit 1
fi
fi
else
echo -e "\033[31mNginx install false\033[0m"
exit 1
fi
fi
if [ $m -eq 2 ]
then
install_cmake
if [ $? -eq 0 ]
then
c
if [ $m -eq 1 ]
then
install_nginx
if [ $? -eq 0 ]
then
c
if [ $m -eq 3 ]
then
install_mysql
if [ $? -eq 0 ]
then
c
if [ $m -eq 4 ]
then
install_php
if [ $$ -eq 0 ]
then
echo -e "\033[32mLNMP install OK\033[0m"
exit 0
else
echo -e "\033[31mLNMP install false\033[0m"
exit 1
fi
fi
else
echo -e "\033[31mMySQL install false\033[0m"
exit 1
fi
fi
else
echo -e "\033[31mNginx install false\033[0m"
exit 1
fi
fi
else
echo -e "\033[31mCMAKE install false\033[0m"
exit 1
fi
fi
if [ $m -eq 3 ]
then
install_mysql
if [ $? -eq 0 ]
then
c
if [ $m -eq 4 ]
then
install_php
if [ $? -eq 0 ]
then
echo -e "\033[32mLNMP install OK\033[0m"
exit 0
else
echo -e "\033[31mLNMP install false\033[0m"
exit 1
fi
fi
else
echo -e "\033[31mMySQL install false\033[0m"
exit 1
fi
fi
if [ $m -eq 4 ]
then
install_php
if [ $? -eq 0 ]
then
echo -e "\033[32mLNMP install OK\033[0m"
exit 0
else
echo -e "\033[31mLNMP install false\033[0m"
exit 1
fi
fi
#当变量值不在规定的范围内会显示提示
if [ $m -ne 1 -o $m -ne 2 -o $m -ne 3 -o $m -ne 4 ]
then
echo -e "\033[31m请输入规定范围数字[1-4],不要输入其他数值或字符。\033[0m"
fi
else
echo -e "\033[31m请输入规定范围数字[1-4],不要输入其他数值或字符。\033[0m"
fi

原文地址:http://blog.51cto.com/qingfeng00/2091393

时间: 2024-10-02 04:46:25

shell脚本一键安装LNMP菜单方式安装的相关文章

用shell脚本一键搭建LNMP环境实战

为了配合上一篇文字,这里先给大家整理一键如何部署LNMP环境; 其实在生产环境中中小企业也是很喜欢用这样的软件包,因为毕竟源码包安装步骤那么多谁也不能一步一步的在哪敲出来,在生产线上你说一台lnmp服务器挂了,你就在哪一步一步的敲有,如果你一遍过了,老板还是对你印象不好,如果你不过,你就惨了.在机房,有很多的服务商都使用这种软件包,至于那些就先不说了,我们来看看这个软件包里都是什么. 下载下来的完整包名是:lnmp1.2-full.tar.gz,我解压打开看看: 在conf文件里放的都是配置文件

Centos 6.4上面用Shell脚本一键安装mysql 5.6.15

Centos 6.4上面用Shell脚本一键安装mysql 5.6.15  #!/bin/bash if [ `uname -m` == "x86_64" ];then machine=x86_64 else machine=i686 fi mysqlBasedir=/storage/server/mysql mysqlDatadir=${mysqlBasedir}/data/ mysqlLogdir=/storage/log/mysql mysqlUser=mysql mysqlGr

shell脚本一键在线安装redis数据库(使用函数实现)

shell脚本一键在线安装redis数据库(使用函数实现) 前面的文章给出了有关手工编译安装redis的流程,并且在模拟搭建redis集群时给出了在线安装redis的过程,于是就想着自己写好在线安装的redis脚本,本文主要使用shell函数来实现并且验证在线安装的过程,执行无误后就想着分享出来. PS:系统环境为Centos7.4 脚本如下: #!/bin/bash function checkroot(){ if [ $UID -ne 0 ] then echo "|------------

Shell脚本一键部署MongoDB

Shell脚本一键部署MongoDB 基本实施思路: 安装MongoDB→创建多实例(创建数量可根据需求自定义)→开启所有实例并展示端口 #!/bin/bash #自动安装MongoDB # #检查MongoDB是否已安装 local="/etc/yum.repos.d/MongoDB.repo" rpm -q mongodb-org &> /dev/null if [ $? -ne 0 ];then #配置本地YUM源 ls /etc/yum.repos.d/ | gr

shell脚本执行的几种方式

执行shell脚本有以下几种方式 1.相对路径方式,需先cd到脚本路径下 [[email protected] tmp]# cd /tmp [[email protected] tmp]# ./ceshi.sh 脚本执行成功 2.绝对路径方式 [[email protected] tmp]# /tmp/ceshi.sh 脚本执行成功 3.bash命令调用 [[email protected] /]# bash /tmp/ceshi.sh 脚本执行成功 4.. (空格)  相对或绝对方式 [[em

Shell脚本一键安装LNMP环境

https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则,稳定性,静态文件处理,内存消耗等方面表现了很强的优势.因此公司线上和测试环境的WEB服务大多数采用的是LNMP环境,经常要进行LNMP环境的搭建,下面是用SHELL脚本写的一键安装LNMP环境的脚本.1)系统环境介绍Centos 5.8 64位 (已测试)Nginx: nginx-1.4.1.ta

【高效率】shell脚本一键安装Tomcat服务

脚本环境 1.linux centos 7或redhat 62.光盘镜像文件已挂载3.系统在可连接外网的环境中4.先下载jdk和tomcat软件包百度云链接提取码:89be 实验步骤 1.上传软件包到Linux系统中2.编写脚本vim tomcat.sh #!/bin/bash#this is tomcat shell #先关闭防火墙,增强性systemctl stop firewalldsetenforce 0num1=`env | grep USER | grep root | wc -l

shell脚本一键安装MySQL5.5

执行脚本之前必须下载MySQL5.5二进制压缩安装包.我是事先下载好了的.下边执行shell脚本. #!/bin/bash #auth:taoyake /bin/mkdir -p /taokey/tools cd /taokey/tools/ tar -zxf mysql-5.5.32-linux2.6-x86_64.tar.gz  sleep 3 cp -R mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql sleep 3 cd /usr/local/

自定义shell脚本快速搭建LNMP环境(Ubuntu16.04 LTS / PHP7.0)

循环shell脚本模拟 apt install app, 把需要的app写在apps.txt即可. 一.lnmp_install.sh (需要有可执行权限) #!/bin/bash #Program function : Lnmp基础环境搭建,基于PHP7.0/MySQL5.7,并安装自定义软件 for app in $(cat apps.txt) do comment=${app:0:1} if [ -n ${app} ] then if [[ ${comment} == "#" ]