概述
在前一篇博客中,我们手动编译安装了整个架构和应用,今天带来了一键部署的脚本,脚本代码如下:
#!/bin/bash
echo "自动关闭防火墙"
systemctl stop firewalld
systemctl disable firewalld &> /dev/null
setenforce 0
warn(){
cat <<EOF
===========================================
|作者:IT.cat |
|时间:2022/8/24 |
===========================================
|软件:nginx-1.15.9 mysql-5.7.20 |
| php-7.1.10 Discuz_X3.4_SC_UTF8 |
===========================================
| 安装前需要准备好安装包(放到/opt下) |
| 这是一个基于nginx、php、mysql架构的服务 |
| 准备好我们就开始安装了 |
| 整个过程会比较漫长,请耐心等待 |
===========================================
EOF
}
#################安装nginx###############
nginx(){
echo "正在安装nginx依赖软件中....耐心等待...."
yum install -y gcc gcc-c++ make pcre pcre-devel expat-devel perl zlib zlib-devel &> /dev/null #安装依赖编译环境
echo "安装完成"
useradd -M -s /sbin/nologin nginx #创建一个nginx用户,方便管理
cd /opt
tar zxvf nginx-1.15.9.tar.gz
cd nginx-1.15.9
echo "正在编译安装"
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module &> /dev/null
make && make install &> /dev/null
echo "编译安装完成"
############创建软链接方便启动##########
cp /usr/local/nginx/sbin/nginx /usr/local/sbin/
############将nginx变为系统服务#################
touch /lib/systemd/system/nginx.service
echo "
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
" > /lib/systemd/system/nginx.service
##########开启服务############
systemctl daemon-reload
systemctl start nginx
echo "nginx安装完成-并启动"
}
#############安装mysql##################
mysql(){
cd /opt
echo "正在安装mysql需要的依赖软件.....耐心等待......"
yum -y install ncurses ncurses-devel bison cmake
yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++
echo "安装完成"
useradd -s /sbin/nologin mysql
##############解压数据库的包##########
tar zxvf mysql-boost-5.7.20.tar.gz &> /dev/null
#########编译安装mysql################
cd mysql-5.7.20
echo "正在编译安装mysql....耐心等待...."
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DSYSCONFDIR=/etc
-DSYSTEMD_PID_DIR=/usr/local/mysql
-DDEFAULT_CHARSET=utf8
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DMYSQL_DATADIR=/usr/local/mysql/data
-DWITH_BOOST=boost
-DWITH_SYSTEMD=1
make -j3 && make install
echo "安装完成"
##############对数据库权限进行调整################
chown -R mysql:mysql /usr/local/mysql
#############调整配置文件####################
echo "
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
" > /etc/my.cnf
chown mysql:mysql /etc/my.cnf #更改一下mysql配置文件属性
##########设置环境变量#################
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
##########对数据库进行初始化##########
cd /usr/local/mysql
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &> /dev/null
systemctl restart mysqld
################免交互修改密码################
yum -y install expect &> /dev/null
source /etc/profile
########初始化密码为123456###############
echo "数据库密码初始化为:123456"
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password
expect {
"Enter password"
{send "r";exp_continue}
"New password"
{send "123456r";exp_continue}
"Confirm new password"
{send "123456r"}
}
expect eof
EOF
echo "MySQL安装完成"
}
php(){
################安装依赖软件####################
echo "正在安装依赖软件.....耐心等待......"
################解压编译安装php####################
cd /opt
tar -jxvf php-7.1.10.tar.bz2
cd php-7.1.10/
make -j3 && make install &> /dev/null
##############扩展配置文件##################
cp php.ini-development /usr/local/php/lib/php.ini
sed -i "1170c mysqli.default_socket = /usr/local/mysql/mysql.sock" /usr/local/php/lib/php.ini
sed -i "939c date.timezone = Asia/Shanghai" /usr/local/php/lib/php.ini
################优化FPM模块################
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
sed -i "17c pid = run/php-fpm.pid" /usr/local/php/etc/php-fpm.conf
################启动php服务###############
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
}
change(){
#####################编辑配置文件#####################
sed -i '45c index index.html index.htm index.php;' /usr/local/nginx/conf/nginx.conf
systemctl restart nginx
######################免交互##################
/usr/bin/expect &>/dev/null <<EOF
spawn mysql -uroot -p123456
expect "mysql>" {send "CREATE DATABASE bbs;r"}
expect "mysql>" {send "GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';r"}
expect "mysql>" {send "GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';r"}
expect "mysql>" {send "flush privileges;r"}
expect "mysql>" { send "quit;r"}
expect eof
EOF
echo "数据库用户bbsuser权限更改成功"
}
discuz(){
cd /opt
unzip Discuz_X3.4_SC_UTF8.zip -d /tmp &> /dev/null
cd /tmp/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs/
cd /usr/local/nginx/html/bbs/
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
cd /usr/local/nginx/html/bbs/
mv install/ install.lock
chmod 600 install.lock/
echo "论坛应用部署完成"
}
#############调用函数运行#####################
warn
nginx
export mysql
mysql
php
change
discuz
执行完成后我们只需访问:http://[主机IP]/install/index.php
点击跳转后
出现以下界面即配置成功了。
最后
以上就是紧张皮卡丘为你收集整理的shell脚本一键部署LNMP架构的DISCUZ!社区论坛应用的全部内容,希望文章能够帮你解决shell脚本一键部署LNMP架构的DISCUZ!社区论坛应用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复