||+++++++++++++++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