安裝順序:apache→mysql→PHP
實(shí)驗(yàn)所需軟件包:鏈接:https://pan.baidu.com/s/1tKAjqn50NnR7F3JmzyHF1w 提取碼:1xpr
#!/bin/bash
#一鍵自動(dòng)構(gòu)建LAMP架構(gòu)(請(qǐng)使用source執(zhí)行或者使用.命令執(zhí)行)
#數(shù)據(jù)庫默認(rèn)密碼為123123
#遠(yuǎn)程掛載
df -hT | grep -o "cifs"
if [ $? -ne 0 ];then
echo "Start mount"
yum install expect -y
read -p "請(qǐng)輸入提供硬盤主機(jī)IP:" gongip
/usr/bin/expect <<-EOF
spawn mount.cifs //$gongip/LAMP-C7 /mnt/
expect {
"Password*"
{send "\r"}
}
expect eof
EOF
fi
#安裝apache服務(wù)
cd /mnt/
tar zxf apr-1.6.2.tar.gz -C /opt
tar zxf apr-util-1.6.0.tar.gz -C /opt/
tar jxf httpd-2.4.29.tar.bz2 -C /opt/
cd /opt/
mv apr-1.6.2/ httpd-2.4.29/srclib/apr
mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
yum -y install gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl
cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
sed -i -e '2a# chkconfig: 35 85 21\n# description: Apache is a World Wide Web server' /etc/init.d/httpd
chkconfig --add httpd
sed -i -e '197d' -e '196aServerName www.kgc.com:80' /usr/local/httpd/conf/httpd.conf
ip=`ifconfig ens33 | awk 'NR==2{print $2}'`
sed -i -e '52s/^/#/' -e '51d' -e "50aListen $ip:80" /usr/local/httpd/conf/httpd.conf
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
systemctl stop firewalld.service
setenforce 0
service httpd start
netstat -ntuap | grep httpd
if [ $? -eq 0 ];then
echo Apache服務(wù)啟動(dòng)
else
echo 啟動(dòng)失敗
exit 1
fi
#安裝mysql服務(wù)
echo "================================="
echo "安裝mysql數(shù)據(jù)庫,請(qǐng)稍后。。。"
sleep 3
yum install -y ncurses-devel autoconf cmake
cd /mnt/
tar zxf mysql-5.6.26.tar.gz -C /opt/
cd /opt/mysql-5.6.26
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DSYSCONFIDIR=/etc \
-DMYSQL_DATADIR=/home/mysql/ \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
echo "進(jìn)行編譯安裝,要很久,請(qǐng)稍后。。。"
make && make install
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add /etc/init.d/mysqld
chkconfig --level 235 mysqld on
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
echo $PATH | grep -o "mysql"
if [ $? -eq 0 ];then
echo "添加成功"
else
echo "失敗"
exit 1
fi
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
sed -i -e '47d' -e '46d' -e '45abasedir=/usr/local/mysql\ndatadir=/home/mysql' /etc/init.d/mysqld
service mysqld start
netstat -ntuap | grep mysqld
if [ $? -eq 0 ];then
echo Mysql數(shù)據(jù)庫啟動(dòng)
else
echo 啟動(dòng)失敗
exit 1
fi
#read -p "請(qǐng)輸入數(shù)據(jù)庫密碼(自定義):" mima
/usr/bin/expect < /usr/local/httpd/htdocs/index.php <<-EOF
EOF
service httpd stop
service httpd start
rm -rf /opt/*
umount /mnt
#請(qǐng)使用source+腳本啟動(dòng)
source /etc/profile
echo $PATH | grep -o "mysql"
while [ $? -ne 0 ];do
while [ "a" = "a" ]
do
echo "錯(cuò)誤!!"
sleep 2
done
done
echo "LAMP架構(gòu)完成。腳本執(zhí)行結(jié)束~~~~"
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。