标签:lamp 脚本
今天对昨天的脚本优化了下,该脚本功能是可以按选项进行安装,虽然不如一键安装脚本方便,但加入了选项变量,在别的场景还是会时常用到的。同时隐去了输出过程,更方便查看安装进程。(因环境不同,仅供参考)
同样,先上效果图:
脚本内容:
#!/bin/bash
#Auto LAMP Install
#by liupengfang ----2015-07-24-----
if [ -z "$1" ];then
echo -e "\033[35m--欢迎使用LAMP自动安装脚本--\033[0m"
echo -e ‘\033[32m----------------------------\033[0m‘
echo -e "\033[35m-----请按照选项进行安装-----\033[0m"
echo -e "\033[32m1)编译安装Apache服务器\033[0m"
echo -e "\033[32m2)编译安装MySQL服务器\033[0m"
echo -e "\033[32m3)编译安装PHP服务器\033[0m"
echo -e "\033[32m4)Apache+PHP整合\033[0m"
echo -e "\033[32m5)Mysql服务配置\033[0m"
echo -e "\033[31m请输入: { /bin/sh $0 1|2|3|4|5}\033[0m"
exit
fi
if [[ "$1" -eq "1" ]];then
echo -e "\033[35m--Apache安装--\033[0m"
echo -e "\033[35m开始解压……\033[0m"
tar vxf httpd-2.2.29.tar.bz2 &>/dev/null
echo -e "\033[35m文件解压完成!开始预编译……\033[0m"
cd /lamp/httpd-2.2.29
else
echo -e "\033[35m预编译失败!\033[0m"
exit 0
fi
echo -e "\033[35mApache正在安装……\033[0m"
make &>/dev/null && make install &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35mApache安装成功!\033[0m"
else
echo -e "\033[35mApache安装失败!\033[0m"
exit 0
fi
fi
if [[ "$1" -eq "2" ]];then
echo -e "\033[35m--Mysql安装--\033[0m"
echo -e "\033[35m开始解压……\033[0m"
cd /lamp/ ; tar vxf mysql-5.1.63.tar.gz &>/dev/null
echo -e "\033[35m解压完成!开始预编译……\033[0m"
else
echo -e "\033[35m预编译失败!\033[0m"
exit 0
fi
echo -e "\033[35m开始安装Mysql……\033[0m"
make &>/dev/null && make install &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35mMysql安装成功!\033[0m"
else
echo -e "\033[35mMysql安装失败!\033[0m"
exit 0
fi
fi
if [[ "$1" -eq "3" ]];then
echo -e "\033[35m--PHP安装--\033[0m"
yum install libxml2 libxml2-devel -y &>/dev/null
echo -e "\033[35m开始解压……\033[0m"
cd /lamp/ ; tar vxf php-5.3.29.tar.bz2 &>/dev/null
echo -e "\033[35m解压完成!开始预编译……\033[0m"
cd /lamp/php-5.3.29
else
echo -e "\033[35m预编译失败!\033[0m"
exit 0
fi
echo -e "\033[35m开始安装PHP……\033[0m"
make &>/dev/null && make install &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35mPHP安装成功!\033[0m"
else
echo -e "\033[35mPHP安装失败!\033[0m"
exit 0
fi
fi
if [[ "$1" -eq "4" ]];then
echo -e "\033[35m----Apache+PHP整合中……-----\033[0m"
ADDTYPE=/usr/local/apache2/conf/httpd.conf
sed -i ‘s/AddType application\/x-gzip .gz .tgz/& \n AddType applicati
on\/x-httpd-php .php/‘ $ADDTYPE
sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.php index.html/
‘ $ADDTYPE
echo -e "\033[35m----编写PHP测试页面……-----\033[0m"
sleep 2
cd /usr/local/apache2/htdocs/
echo ‘<?php‘ >> index.php
echo ‘phpinfo();‘ >> index.php
echo ‘?>‘ >> index.php
echo -e "\033[35m----请访问PHP测试页面index.php-----\033[0m"
fi
if [[ "$1" -eq "5" ]];then
echo -e "\033[35m----Mysql配置-----\033[0m"
sleep 2
useradd mysql
rm -rf /etc/my.cnf
cp /lamp/mysql-5.1.63/support-files/my-medium.cnf /etc/my.cnf
cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql
MY_CNF=/etc/my.cnf
sed -i ‘s/myisam_sort_buffer_size = 8M/& \ndatadir = \/usr\/local\/mysql
\/data\//‘ $MY_CNF
echo -e "\033[35mMysql初始化中……\033[0m"
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/
mysql/data/ &>/dev/null
echo -e "\033[35m关闭防火墙……\033[0m"
service iptables stop &>/dev/null
echo -e "\033[35m关闭selinux……\033[0m"
setenforce 0 &>/dev/null
/usr/local/apache2/bin/apachectl start &>/dev/null
service mysqld start &>/dev/null
echo -e "\033[35m----Mysql配置完成-----\033[0m"
fi
if [[ "$1" -gt "5" ]];then
echo -e "\033[35m请输入正确选项!\033[0m"
fi
本文出自 “IT网络” 博客,请务必保留此出处http://liupengfang1015.blog.51cto.com/6627801/1677784
标签:lamp 脚本
原文地址:http://liupengfang1015.blog.51cto.com/6627801/1677784