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
}
install_nginx(){
yum install -y pcre-devel
if [ -d "$dir"/nginx ]
then
echo "Nginx已安裝"
exit 0
else
useradd -M -s /sbin/nologin nginx
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
"$dir"/sbin/nginx
fi
fi
cd /root/
}
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/
}
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/
}
install_php(){
[ ! -d "$dir"/nginx -o ! -d "$dir"/mysql ] && echo "請先安裝 Nginx,CMAKE,MySQL" && exit 1
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
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
echo "
<?php
phpinfo();
?>" >/usr/local/nginx/html/index.php
kill -1 $(cat /usr/local/nginx/logs/nginx.pid)
}
read0(){
expr $m + 1 &>/dev/null
[ $? -ne 0 ] && echo "請輸入純數字,不要輸入其他字符" && exit 1
[ $m -eq 1 ] && install_nginx
[ $m -eq 2 ] && install_cmake
[ $m -eq 3 ] && install_mysql
[ $m -eq 4 ] && install_php
[ $m -ne 1 -o $m -ne 2 -o $m -ne 3 -o $m -ne 4 ] && echo "不要輸入超過範圍的數值" && exit 1
}
read1(){
expr $m + 1 &>/dev/null
[ $? -ne 0 ] && echo "請輸入純數字,不要輸入其他字符" && exit 1
[ $m -eq 1 ] && install_nginx && c && read0 && c && read0 && c && read0
[ $m -eq 2 ] && install_cmake && c && read0 && c && read0 && c && read0
[ $m -eq 3 ] && install_mysql && c && read0
[ $m -eq 4 ] && install_php
[ $m -ne 1 -o $m -ne 2 -o $m -ne 3 -o $m -ne 4 ] && echo "不要輸入超過範圍的數值" && exit 1
}

mount /dev/sr0 /media/cdrom/
c
read1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章