设为首页 收藏本站
查看: 1690|回复: 0

LAMP平台搭建脚本

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-9-22 09:16:42 | 显示全部楼层 |阅读模式
#!/bin/bash
DATE=`date +%F_%T`
#源码包编译安装搭建LAMP平台的。
#本脚本所需软件包:cmake-2.8.11.2.tar.gz   mysql-5.5.22.tar.gz
#httpd-2.2.17.tar.gz     php-5.3.28.tar.gz
#libmcrypt-2.5.7.tar.gz  phpMyAdmin-4.2.5-all-languages.tar.gz
#mcrypt-2.6.8.tar.gz     ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
#mhash-0.9.9.9.tar.bz2
#本脚本执行成功所需环境:1、创建/lamp目录,并把所需的九个软件包复制到此目录。2、搭建基本的yum环境(用系统光盘本身的yum仓库即可)。


#交互配置IP地址和yum源
service iptables stop
setenforce 0
ip=`ifconfig  eth0  |grep "inet addr"| awk '{print $2}'`
IPA=/etc/sysconfig/network-scripts/ifcfg-eth0

read -p "请问是配置ip地址吗(y|n):" A
case $A in
y)
    sed -i 's#ONBOOT=no#ONBOOT=yes#g' $IPA
    sed -i 's#BOOTPROTO=dhcp#BOOTPROTO=static#g'  $IPA
    read -p "请输入你想要配置的IP地址:" B
    echo "IPADDR=$B" >> $IPA
    read -p "请输入你想要配置的子网掩码:" C
    echo "NETMASK=$C" >> $IPA
    /etc/init.d/NetworkManager stop
    service network start
    echo "IP配置成功" >> true.txt
;;
n)
    echo "已经配置好IP地址" >> true.txt
    echo "$ip" >> true.txt
;;
esac

#配置yum源
#如果是centos,则执行这一步,去掉下面这一行的注释即可。   
#mv /etc/yum.repos.d/Centos-Base.repo  /etc/yum.repos.d/Centos-Base.repo_bak

YUM=/etc/yum.repos.d/yum.repo
funcation(){
cat > $YUM /dev/null  || echo "失败" >> error.txt
read -p "请问是配置yum源吗(y|n):" AA
case  $AA in
y)
        funcation
        echo "yum源配置成功" >> true.txt
        yum clean all &> /dev/null
        yum repolist  &> /dev/null
;;
n)
        echo "已经配置过yum源" >> true.txt
;;
esac
#read -p "请指定软件包的的位置:" ADD
#cd $ADD

if rpm -q gcc gcc-c++ perl  make automake lrzsz
    then  
          echo "已有开发环境。"  >>/aaa
    else
          echo "没有开发环境,现在安装。" >>/aaa
          yum  -y  install gcc gcc-c++ perl  make automake lrzsz
fi
#以上是检测开发环境。


cd /lamp
for tar in `ls /lamp`
    do
        case $tar in
               #当变量值是以.tar.gz结尾的时候所要执行的命令序列。
           *.tar.gz)
               tar zxf $tar -C /usr/src
           ;;
                 #当变量值是以.tar.bz2结尾的时候所要执行的命令序列。
           *.tar.bz2)
               tar jxf $tar -C /usr/src
           ;;
                 #当变量值是以.zip结尾的时候所要执行的命令序列。
           *.zip)
               unzip -d /usr/src $tar
           ;;
           *)
               echo "$tar不是压缩文件!"
           ;;
          esac
    done
echo '解压完毕!!!' >>/aaa
#以上是解压所需的源码包。



if rpm -q httpd
    then
        rpm -e httpd --nodeps &&echo "已卸载rpm安装的apache"  >>/aaa
        cd /usr/src/http*
        ./configure  --prefix=/usr/local/httpd  --enable-so  --enable-rewrite  --enable-charset-lite  --enable-cgi  &&make&&make install
    else
        cd /usr/src/http*
        ./configure  --prefix=/usr/local/httpd  --enable-so  --enable-rewrite  --enable-charset-lite  --enable-cgi  &&make&&make install   
fi

if [ -d /usr/local/httpd ];then
    echo "Apache已经编译安装完毕!接下来优化配置Apache。" >>/aaa
    cd /usr/local/httpd  
    ln -s /usr/local/httpd/bin/* /usr/local/bin
    \\cp /usr/local/httpd/bin/apachectl  /etc/init.d/httpd
    sed -i '1a#chkconfig: 35 25 15 \\#description:zhis is apache'  /etc/init.d/httpd
    chkconfig --add httpd &&chkconfig httpd on
    sed -i '$aAddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf
    sed -i '$aadddefaultcharset UTF-8'  /usr/local/httpd/conf/httpd.conf
fi
#以上是安装及优化Apache。


/etc/init.d/httpd start

if  netstat -lntup|grep 80
    then
        echo "APACHE已经成功启动!!!"  >>/aaa
fi
#以上是启动Apache。

if cd /usr/src/cmak*
    then
        ./configure &&make&&make install
fi
#以上是安装cmake工具。


if rpm -q mysql mysql-server
    then
        echo "rpm包的mysql已安装,下一步卸载。" >>/aaa
        rpm -e mysql mysql-server  --nodeps &&echo "rpm安装的mysql已卸载完毕!" >>/aaa
fi

if rpm -q ncurses-devel
    then
        echo "mysql的依赖软件包已安装"  >>/aaa
    else
        yum install ncurses-devel -y
fi

sql=/usr/src/mysql*
sq=/usr/local/mysql

if  cd $sql
    then
        cmake -DCMAKE_INSTALL_PREFIX=$sq  -DSYSCONFDIR=/etc  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all  &&make&&make install
    else
        echo "没有mysql源码文件"  >>/aaa
fi
#以上是安装mysql。


userdel -r mysql
useradd -M -s /sbin/nologin mysql
if [ -d $sq ];then
    chown -R mysql:mysql $sq
    \\cp $sq/support-files/my-medium.cnf  /etc/my.cnf
    \\cp $sq/support-files/mysql.server  /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    ln -s /usr/local/mysql/bin/*  /usr/local/bin/
fi


/usr/local/mysql/scripts/mysql_install_db   --user=mysql  --basedir=/usr/local/mysql/  --datadir=/usr/local/mysql/data/  >/mysql.txt

if grep OK /mysql.txt
    then
        echo "初始化数据库成功!!!"  >>/aaa
        /etc/init.d/mysqld start && echo "mysql启动成功!!!"  >>/aaa
    else
        echo "初始化数据库失败!!!"  >>/aaa
fi


if rpm -q zlib-devel&&rpm -q libxml2-devel
    then
        echo "php依赖软件已安装!" >>/aaa
    else
        yum install zlib-devel libxml2-devel perl -y
fi


if  cd /usr/src/libmcrypt*
    then
        ./configure&&make&&make install &&echo "libmcrypt已经安装好" >>/aaa
fi

if cd /usr/src/mhash*
    then
        ./configure&&make&&make install &&echo "mhash已经安装好"
fi

if cd /usr/src/mcrypt*
    then
        echo "/usr/local/lib"  >>/etc/ld.so.conf && ldconfig
        ./configure&&make&&make install
    else
        echo "加密工具源码包不存在"  >>/aaa
fi


php1=/usr/src/php-*
if cd $php1
    then
        ./configure  --prefix=/usr/local/php5  --with-mcrypt  --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql   --with-config-file-path=/usr/local/php5  --enable-mbstring &&make&&make install
    else
        echo "php源码包不存在!!!"  >>/aaa
fi

if [ -d /usr/local/php5 ];then
    echo "php已经安装完毕"  >>/aaa
    \\cp /usr/src/php-*/php.ini-development /usr/local/php5/php.ini
    sed -i '1,$s/short_open_tag = Off/short_open_tag = On/g' /usr/local/php5/php.ini
    /etc/init.d/httpd stop
    /etc/init.d/httpd start
else
    echo "php没安装成功!!!"  >>/aaa
fi

if cd /usr/src/ZendGuard*
    then   
        \\cp /usr/src/ZendGuard*/php-*/ZendGuard* /usr/local/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
        echo 'php优化成功!' >>/aaa
fi

if cd /usr/src/phpMyAdmin-*
    then
        mv /usr/src/phpMyAdmin-* /usr/local/httpd/htdocs/phpMyAdmin && mv /usr/local/httpd/htdocs/phpMyAdmin/config.sam*  /usr/local/httpd/htdocs/phpMyAdmin/config.inc.php
        echo "phpMyAdmin部署成功"
    else
        echo "部署phpMyAdmin失败"  >>/aaa
fi

echo "LAMP环境搭建完成,接下来进行测试:"  >>/aaa


echo ">/usr/local/httpd/htdocs/index.php
echo "phpinfo();"  >>/usr/local/httpd/htdocs/index.php
echo "?>"  >>/usr/local/httpd/htdocs/index.php

/etc/init.d/httpd  stop;/etc/init.d/httpd start

if rpm -q firefox
    then
        echo "火狐已经安装" >>/aaa
        firefox http://127.0.0.1/index.php
        firefox http://127.0.0.1/phpMyAdmin/index.php
    else
        yum install firefox -y
        firefox http://127.0.0.1/index.php
        firefox http://127.0.0.1/phpMyAdmin/index.php
fi



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-404897-1-1.html 上篇帖子: CentOS 6上编译安装AMP详解 下篇帖子: LNMP架构添加memcached
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表