码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2018-03-26 23:39:00      阅读:360      评论:0      收藏:0      [点我收藏+]

标签: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

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

标签:shell脚本一键安装LNMP

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!