本文主要是介绍技术干货:Shell脚本一键部署及运用企业级LNMP架构----------------------------小董偷懒系列,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Shell脚本一键部署及运用企业级LNMP架构
- 来了来了干货来了 ~~偷懒就对了~~
来了来了干货来了 偷懒就对了
不懂什么意思 请移步我上上一篇博客点击这里
#!/bin/bash
#
IP=20.0.0.27
PASSWORD=123456clear# 判断脚本执行者是否为root用户
if [ "`whoami`" != "root" ];thenecho "请以root用户身份执行该脚本!" exit 1
fi# 交互提示是否确认进行安装
echo "----------欢迎使用LAMP+Discuz一键安装脚本 V1.1---2020-09-04-----"
echo "软件包版本:httpd-2.4.29、mysql-5.6.26、php-5.6.11"
echo "注意事项:"
echo "1.本脚本适用于Centos7.x(其他系统未测试),请在安装前先将安装包拷贝到/opt目录下"
echo "2.本脚本适用于阿里云服务器,在安装前请修改脚本第3、4行的IP,服务器内、外网IP地址"
echo "3.在安装过程中请保证网络畅通"
echo "4.请使用source命令执行该脚本"
echo "---------------------------------------------------------------"
echo ""
while true;do
read -p "是否进行开始安装?(y/n)" a
if [ $a = y ];thenecho "开始为您安装Apache..."breakelif [ $a = n ];thenecho "用户已取消安装,退出程序..."exit 1elseecho "输入有误,请重新输入!"
fi
done# 安装LAMP服务依赖环境
yum -y install gcc gcc-c++ make pcre-devel expat-devel perl bzip2 expect ncurses-devel autoconf cmake gd libpng libpng-devel pcre pcre-devel libxml2-devel libjpeg-devel# 安装Apache
tar jxvf /opt/httpd-2.4.29.tar.bz2 -C /opt
tar zxvf /opt/apr-util-1.6.0.tar.gz -C /opt
tar zxvf /opt/apr-1.6.2.tar.gz -C /opt
mv /opt/apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv /opt/apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util
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 '2a# chkconfig:35 85 21' /etc/init.d/httpd
cd /etc/init.d/
chkconfig --add httpd
sed -i "51c Listen ${IP}:80" /usr/local/httpd/conf/httpd.conf
sed -i "52c #Listen 80" /usr/local/httpd/conf/httpd.conf
sed -i "198c ServerName www.test.com:80" /usr/local/httpd/conf/httpd.conf
ln -s /usr/local/httpd/bin/* /usr/local/bin/
setenforce 0 && systemctl stop firewalld
service httpd start# 安装MySQL
tar zxvf /opt/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
make && make install
/usr/bin/expect <<-EOF
spawn cp support-files/my-default.cnf /etc/my.cnf
expect { "?"{send "\r";}
}
expect eof
EOF
cp /opt/mysql-5.6.26/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add /etc/init.d/mysqld
chkconfig mysqld --level 35 on
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
cd /usr/local/mysql/scripts/
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
sed -i '46c basedir=/usr/local/mysql' /etc/init.d/mysqld
sed -i '47c datadir=/home/mysql' /etc/init.d/mysqld
echo "bind-address=0.0.0.0" >> /etc/my.cnf
service mysqld start
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password "$PASSWORD"
expect { ":"{send "\r";}
}
expect eof
EOF# 安装PHP
tar xjvf /opt/php-5.6.11.tar.bz2 -C /opt
cd /opt/php-5.6.11
./configure \
--prefix=/usr/local/php5 \
--with-gd \
--with-zlib \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring
make && make install
cp /opt/php-5.6.11/php.ini-development /usr/local/php5/php.ini
ln -s /usr/local/php5/bin/* /usr/local/bin/
sed -i '381aAddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf
sed -i '382aAddType application/x-httpd-php-source .phps' /usr/local/httpd/conf/httpd.conf
sed -i '255cDirectoryIndex index.php index.html' /usr/local/httpd/conf/httpd.conf
ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
service httpd stop
service httpd start
- 安装包可以私聊我
- 代码不是太严谨 但是可以看
这篇关于技术干货:Shell脚本一键部署及运用企业级LNMP架构----------------------------小董偷懒系列的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!