#!/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
转载于:https://blog.51cto.com/liyuanjie/1967407