自动化运维必看!Shell脚本实现LAMP自动部署!

[root@a shell]# cat auto.sh 
#!/bin/bash 
#auto install LAMP  
#by wugk 2014-11 
#Httpd define path variable 
H_FILES=httpd-2.4.37.tar.bz2 
H_FILES_DIR=httpd-2.4.37 
H_URL=http://mirrors.sohu.com/apache/
H_PREFIX=/usr/local/apache2/ 
#MySQL define path variable 
M_FILES=mysql-5.5.62.tar.gz 
M_FILES_DIR=mysql-5.5.62 
M_URL=http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.5/
M_PREFIX=/usr/local/mysql/ 
#PHP define path variable 
P_FILES=php-7.1.22.tar.bz2 
P_FILES_DIR=php-7.1.22
P_URL=http://mirrors.sohu.com/php/ 
P_PREFIX=/usr/local/php7/ 
echo -e '\033[32m-----------------------------\033[0m' 
echo 
if [ -z "$1" ];then 
echo -e "\033[36mPlease Select Install Menu follow:\033[0m" 
echo -e "\033[32m1) 编译安装 Apache服务器\033[1m" 
echo "2) 编译安装 MySQL服务器 " 
echo "3) 编译安装 PHP服务器" 
echo "4) 配置 index.php 并启动 LAMP服务" 
echo -e "\033[31mUsage: { /bin/sh $0 1|2|3|4|help}\033[0m" 
exit 
fi 
if [[ "$1" -eq "help" ]];then 
        echo -e "\033[36mPlease Select Install Menu 
follow:\033[0m" 
        echo -e "\033[32m1) 编译安装 Apache服务器 \033[1m" 
        echo "2) 编译安装 MySQL服务器 " 
        echo "3) 编译安装 PHP服务器" 
        echo "4) 配置 index.php 并启动 LAMP服务" 
        echo -e "\033[31mUsage: { /bin/sh $0 
1|2|3|4|help}\033[0m" 
        exit 
fi 
###################################### 
#Install httpd web server  
if [[ "$1" -eq "1" ]];then 
	 yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp cur l curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd get text gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom _err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libto ol* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl ope nssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm n asm* wget zlib-devel
	wget -c $H_URL/$H_FILES &&  tar -jxvf $H_FILES && cd $H_FILES_DIR &&./configure --prefix=$H_PREFIX  
	if [ $? -eq 0 ];then 
		make && make install 
		echo -e "\033[32mThe $H_FILES_DIR Server Install Success !\033[0m" 
	else 
		echo -e "\033[32mThe $H_FILES_DIR Make or Make install ERROR,Please Check....." 
		exit 0 
	fi 
fi 
#Install Mysql DB server  
if [[ "$1" -eq "2" ]];then 
        wget -c $M_URL/$M_FILES &&  tar -xzvf $M_FILES && cd $M_FILES_DIR &&yum install cmake -y ;
	cmake \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DWITH_INNOBASE_STORAGE_engine=1 \
 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DMYSQL_DATADIR=/data/mysqldb \
 -DMYSQL_TCP_PORT=3306 \
 -DENABLE_DOWNLOADS=1	
	make && make install 
	/bin/cp support-files/my-small.cnf /etc/my.conf 
	/bin/cp support-files/mysql.server /etc/init.d/mysqld 
	chmod +x /etc/init.d/mysqld 
	chkconfig --add mysqld 
	chkconfig mysqld on 
        if [ $? -eq 0 ];then 
                make && make install 
                echo -e "\033[32mThe $M_FILES_DIR Server Install Success !\033[0m" 
        else 
                echo -e "\033[32mThe $M_FILES_DIR Make or Make install ERROR,Please Check......" 
                exit 0 
        fi 
fi 
#Install PHP server  
if [[ "$1" -eq "3" ]];then 
        wget -c $P_URL/$P_FILES &&  tar -jxvf $P_FILES && cd $P_FILES_DIR &&./configure --prefix=$P_PREFIX 
--with-config-file-path=$P_PREFIX/etc --with-mysql=$M_PREFIX --with-apxs2=$H_PREFIX/bin/apxs 
        if [ $? -eq 0 ];then 
                make ZEND_EXTRA_LIBS='-liconv' && make install 
                echo -e "\033[32mThe $P_FILES_DIR Server Install Success !\033[0m" 
        else 
                echo -e "\033[32mThe $P_FILES_DIR Make or Make install ERROR,Please Check......" 
                exit 0 
        fi 
fi 
#################################### 
if [[ "$1" -eq "4" ]];then
	sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' $H_PREFIX/conf/httpd.conf  
	$H_PREFIX/bin/apachectl restart 
	echo "AddType     application/x-httpd-php .php" >>$H_PREFIX/conf/httpd.conf 
	IP=`ifconfig eth1|grep "Bcast"|awk '{print $2}'|cut -d: -f2` 
	echo "You can access http://$IP/" 
cat >$H_PREFIX/htdocs/index.php <<EOF 
<?php 
phpinfo(); 
?> 
EOF 
fi
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 创作都市 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读