使用Shell脚本一键部署基础LAMP架构-创新互联-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

使用Shell脚本一键部署基础LAMP架构-创新互联

使用Shell脚本一键部署基础LAMP架构

安装顺序:apache→mysql→PHP
实验所需软件包:链接:https://pan.baidu.com/s/1tKAjqn50NnR7F3JmzyHF1w 提取码:1xpr

成都服务器托管,创新互联提供包括服务器租用、成都服务器托管、带宽租用、云主机、机柜租用、主机租用托管、CDN网站加速、域名与空间等业务的一体化完整服务。电话咨询:13518219792
#!/bin/bash
#一键自动构建LAMP架构(请使用source执行或者使用.命令执行)
#数据库默认密码为123123

#远程挂载
df -hT | grep -o "cifs"
if [ $? -ne 0 ];then
echo "Start mount"
yum install expect -y
read -p "请输入提供硬盘主机IP:" gongip
/usr/bin/expect <<-EOF
spawn mount.cifs //$gongip/LAMP-C7 /mnt/
expect {
    "Password*"
    {send "\r"}
}
expect eof
EOF
fi

#安装apache服务
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服务启动
else 
    echo 启动失败
    exit 1
fi

#安装mysql服务
echo "================================="
echo "安装mysql数据库,请稍后。。。"
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 "进行编译安装,要很久,请稍后。。。"
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数据库启动
else
        echo 启动失败
    exit 1 
fi

#read -p "请输入数据库密码(自定义):" mima
/usr/bin/expect < /usr/local/httpd/htdocs/index.php <<-EOF

EOF

service httpd stop
service httpd start

rm -rf /opt/*
umount /mnt

#请使用source+脚本启动
source /etc/profile
echo $PATH | grep -o "mysql"
while [ $? -ne 0 ];do
  while [ "a" = "a" ]
    do
    echo "错误!!"
    sleep 2
    done
done
echo "LAMP架构完成。脚本执行结束~~~~"

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:使用Shell脚本一键部署基础LAMP架构-创新互联
分享链接:http://kswsj.cn/article/dpicgj.html

其他资讯