LAMP平臺搭建腳本
阿新 • • 發佈:2017-09-21
lamp腳本
#!/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
本文出自 “安然一笑” 博客,請務必保留此出處http://liyuanjie.blog.51cto.com/12877605/1967407
LAMP平臺搭建腳本