脚本部署lamp

#!/bin/bash
#2017年11月9日22:00:49
#by author lee
#auto intall lamp with make
#########################
PACKAGE_DIR="/root/package"
IP_ADDR=`ifconfig | grep "Bcast:" | awk '{ print $2 }' | sed 's/^.*addr://g'`

#HTTP PATH
H_NAME=httpd-2.2.34.tar.gz
H_DIR=httpd-2.2.34
H_URL=http://mirror.bit.edu.cn/apache/httpd
H_PREFIX=/usr/local/apache2

#MYSQL PATH
M_NAME=mysql-5.5.20.tar.gz
M_DIR=mysql-5.5.20
M_URL=http://down1.chinaunix.net/distfiles
M_PREFIX=/usr/local/mysql55
M_DATA=/data/mysql

#PHP PATH
P_NAME=php-5.3.28.tar.bz2
P_DIR=php-5.3.28
P_URL=http://mirrors.sohu.com/php
P_PREFIX=/usr/local/php5

# echo "3s later to install lamp!"
# sleep 3

check_error(){
if [ $? != 0 ]
then
    echo "there is error you should check!!!"
    exit 1
fi
}
mkdir -p $PACKAGE_DIR

#########################
install_httpd(){
yum install apr apr-devel apr-util apr-util-devel -y
cd $PACKAGE_DIR
wget $H_URL/$H_NAME
tar zxvf $H_NAME
cd $H_DIR
./configure --prefix=$H_PREFIX/ --enable-rewrite --enable-so
check_error
make && make install
check_error
echo "apache install success!!!!!!!!!!!!"
}

#########################
install_mysql(){
yum  install  cmake  gcc-c++ ncurses-devel ncurses cmake bison library* libncurses5-dev g++ kdelibs5-dev make -y
groupadd mysql
useradd -r -g mysql mysql
cd $PACKAGE_DIR
wget $M_URL/$M_NAME
tar -zxvf $M_NAME
cd $M_DIR
mkdir -p $M_DATA
mkdir -p $M_PREFIX
cmake  .  -DCMAKE_INSTALL_PREFIX=$M_PREFIX/ \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=$M_DATA \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BIG_TABLES=1 \
-DWITH_DEBUG=0
check_error
make && make install
check_error
cd $M_DATA
chown -R mysql:mysql .
cd $M_PREFIX
chown -R mysql:mysql .
/bin/cp support-files/my-large.cnf /etc/my.cnf
/bin/cp support-files/mysql.server /etc/init.d/mysqld 
chmod o+x /etc/init.d/mysqld
chkconfig --add mysqld 
chkconfig --level 35 mysqld on
/usr/local/mysql55/scripts/mysql_install_db --user=mysql --datadir=$M_DATA --basedir=$M_PREFIX/
ln  -s  /usr/local/mysql55/bin/* /usr/bin/
service  mysqld  restart
check_error
echo "mysql install success!!!!!!!!!!!!"
}

#########################
install_php(){
yum install -y libxml2 libxml2-devel
cd $PACKAGE_DIR
wget $P_URL/$P_NAME
tar -xjf $P_NAME
cd $P_DIR
./configure --prefix=$P_PREFIX --with-config-file-path=$P_PREFIX/etc   --with-apxs2=$H_PREFIX/bin/apxs  --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
check_error
make && make install
check_error
echo "php install success!!!!!!!!!!!!"
sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php-source .php5' $H_PREFIX/conf/httpd.conf
sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php' $H_PREFIX/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' $H_PREFIX/conf/httpd.conf
sed -i 's/\#ServerName www.example.com/ServerName 127.0.0.1/' $H_PREFIX/conf/httpd.conf
touch $H_PREFIX/htdocs/index.php
echo "<?php
phpinfo();
?>" > $H_PREFIX/htdocs/index.php
$H_PREFIX/bin/apachectl restart
service iptables stop
setenforce 0
echo "lamp install success!!please input http://$IP_ADDR/"
}

#########################
# set_apache_php(){
# sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php-source .php5' $H_PREFIX/conf/httpd.conf
# sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php' $H_PREFIX/conf/httpd.conf
# sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' $H_PREFIX/conf/httpd.conf
# touch $H_PREFIX/htdocs/index.php
# echo "<?php
# phpinfo();
# ?>" > $H_PREFIX/htdocs/index.php
# $H_PREFIX/bin/apachectl restart
# }

#########################
# install_lamp(){
# install_httpd
# install_mysql
# install_php
# set_apache_php
# service iptables stop
# setenforce 0
# echo "lamp install success!!please input http://$IP_ADDR/"
# }
# install_lamp
#########################
echo "输入对应的数字来完成你要做的操作"
echo "1)    安装apache"
echo "2)    安装mysql"
echo "3)    安装php"
echo "0)    退出"
read -t 10 -p "please input the num you want to do:" input
time="sleep 2"
case $input in 
1)
    install_httpd
    ;;
2)
    install_mysql
    ;;
3)
    install_php
    ;;
0)
    exit 0
    ;;
*)
    echo "please input the right choice"
    ;;
esac




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值