shell腳本一鍵安裝LNMP菜單方式安裝
#定義軟件包變量
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"
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"
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 ]
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菜單方式安裝