462 views
Linux-shell脚本

Shell安装LAMP脚本

1、基于YUM shell安装LAMP

[code]

#!/bin/bash

#2017年8月12日08:30:00

#BY ying

#YUM install LAMP

YUM=”$YUM”

STATUS_DIR=/tmp/yum_install_status.txt

HTTP_DIR=/var/www/html

#安装LAMP

$YUM httpd httpd-devel mysql mysql-server mysql-devel php php-devel php-mysql

echo $? >> $STATUS_DIR

#配置发布测试页面

echo “<?php phpinfo(); ?>” > $HTTP_DIR/index.php

echo $? >> $STATUS_DIR

[/code]

2、基于源码shell安装LAMP

[code]

#!/bin/bash

#2017年8月14日13:37:36

#Auto install LAMP for shell

#BY YING

#设置变量

YUM=”yum install -y”

TAR=”tar zxf”

NUM=”$1″

MYSQL_BASE_DIR=/usr/local/mysql

MYSQL_DATA_DIR=/data/mysql

HTTP_DIR=/usr/local/apache

PHP_DIR=/usr/local/php

STATUS=`grep “0” /root/auto_install_lamp.log |wc -l`

#安装依赖包

$YUM gcc* wget

$YUM libxml2-devel

$YUM zlib-devel pcre pcre-devel apr apr-devel

$YUM yum install -y openssl openssl-devel

$YUM pcre pcre-devel apr apr-devel

$YUM curl curl-devel

$YUM bzip2 bzip2-devel

$YUM libjpeg-turbo.x86_64 libjpeg-turbo-devel.x86_64

$YUM libpng libpng-devel

$YUM freetype freetype-devel

rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

$YUM libmcrypt-devel

#下载所需安装包

wget http://www.apache.org/dist/httpd/httpd-2.4.27.tar.gz

wget http://www.apache.org/dist/httpd/httpd-2.4.27.tar.gz

wget http://cn2.php.net/distributions/php-5.5.30.tar.gz

wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.54-linux2.6-x86_64.tar.gz

wget http://apache.fayea.com/apr/apr-1.6.2.tar.gz

wget http://apache.fayea.com/apr/apr-util-1.6.0.tar.gz

#解压

$TAR httpd-2.4.27.tar.gz

$TAR mysql-5.5.54-linux2.6-x86_64.tar.gz

$TAR php-5.5.30.tar.gz

$TAR apr-util-1.6.0.tar.gz

$TAR apr-1.6.2.tar.gz

#安装mysql

function install_mysql ()

{

useradd -s /sbin/nologin mysql -M

mv /root/mysql-5.5.54-linux2.6-x86_64 $MYSQL_BASE_DIR

mkdir -p $MYSQL_DATA_DIR

chown -R mysql.mysql $MYSQL_DATA_DIR

cd $MYSQL_BASE_DIR

#初始化mysql

./scripts/mysql_install_db –user=mysql –datadir=/data/mysql

cd $MYSQL_BASE_DIR/support-files/

rm -rf /etc/my.cnf

cp my-large.cnf /etc/my.cnf

cp mysql.server /etc/init.d/mysqld

sed -i ’46s/basedir\=/basedir=\/usr\/local\/mysql/g’ /etc/init.d/mysqld

sed -i ’47s/datadir\=/datadir=\/data\/mysql/g’ /etc/init.d/mysqld

chkconfig –add mysqld

chkconfig mysqld on

/etc/init.d/mysqld start

echo “MYSQL install`echo $?`” >> /root/auto_install_lamp.log

}

#编译安装httpd

function install_httpd ()

{

cd /root/httpd-2.4.27

cp -r /root/apr-1.6.2 /root/httpd-2.4.27/srclib/apr

cp -r /root/apr-util-1.6.0 /root/httpd-2.4.27/srclib/apr-util

$YUM install expat-devel

sleep 1

./configure –prefix=/usr/local/apache –with-included-apr –enable-so –enable-deflate=shared –enable-expires=shared –enable-rewrite=shared –with-pcre –enable-module=so

if [ $? -lt 0 ];then

make && make install

fi

sed -i ‘s/#ServerName www.example.com:80/ServerName www.xiaoying.com/g’ $HTTP_DIR/conf/httpd.conf

}

#编译安装php

function install_php ()

{

cd /root/php-5.5.30

./configure –prefix=$PHP_DIR \

–with-apxs2=$HTTP_DIR/bin/apxs –with-config-file-path=$PHP_DIR/etc –with-mysql=$MYSQL_BASE_DIR –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir \

–with-freetype-dir –with-iconv-dir –with-zlib-dir –with-bz2 –with-openssl –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-mbstring –enable-sockets –enable-exif –disable-ipv6

if [ $? -lt 0 ];then

make && make install

fi

}

#LAMP整合

function LAMP_ALL ()

{

sed -i ‘s/DirectoryIndex\ index.html/DirectoryIndex\ index.php\ index.html/g’ /usr/local/apache/conf/httpd.conf

sed -i ‘389,390s/^$/ AddType application\/x-httpd-php\ .php/g’ /usr/local/apache/conf/httpd.conf

echo “<?php phpinfo(); ?>” > /usr/local/apache/htdocs/index.php

$HTTP_DIR/bin/apachectl restart

iptables -F

if [ $STATUS -eq 3 ];then

echo “Auto install LAMP is OK!”

else

echo “Auto install LAMP is not OK,please check your script!”

fi

}

#集合

PS3=”Please enter you select install menu:”

select i in http mysql php lamp quit

do

case $i in

http)

install_httpd

;;

mysql)

install_mysql

;;

php)

install_php

;;

lamp)

LAMP_ALL

;;

quit)

exit

;;

*)

echo -e “\033[36mPlease Select Install Menu follow:\033[0m”

echo “1)编译安装Apache服务器”

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”

;;

esac

done [/code]

3、自动创建虚拟主机

[code]

#!/bin/bash

HTTP_CONF_DIR=/usr/local/apache/conf/extra/

CONF_FILE_NAME=httpd-vhosts.conf

HTTP_WEB_DIR=/www

read -p “Please name your host:” HOST

echo ”

<VirtualHost *:80>

ServerAdmin 18870218957@163.com

DocumentRoot $HTTP_WEB_DIR

ServerName $HOST

<Directory “$HTTP_WEB_DIR”>

AllowOverride All

Options Indexes FollowSymLinks

Order allow,deny

Allow from all

</Directory>

ErrorLog logs/error_log

CustomLog logs/access_log common

</VirtualHost>

” >> $HTTP_CONF_DIR/$CONF_FILE_NAME

read -p “Please name your web:” WEB

echo $WEB > $HTTP_WEB_DIR/$WEB.html

cat $HTTP_CONF_DIR/$CONF_FILE_NAME

cat $HTTP_WEB_DIR/$WEB.html

[/code]

Leave a Reply

影子专属博客 赣ICP备17013143号