LAMP+Discuz 论坛一键安装部署

一、安装准备

1. 准备安装包

httpd 包:apr-1.6.2.tar.gz,apr-util-1.6.0.tar.gz,httpd-2.4.29.tar.bz2
mysql 包:mysql-5.7.17.tar.gz,boost_1_59_0.tar.gz
PHP包:php-7.1.10.tar.bz2
Dscuz 包:Discuz_X3.4_SC_UTF8.zip

软件包在百度网盘中自提,提取码:8888

2. 安装前准备

[root@localhost ~]#cd /
[root@localhost /]#mkdir data
[root@localhost /]#ls
data   ......

#把安装包上传到创建好的目录中
[root@localhost /data]#ls
apr-1.6.2.tar.gz  apr-util-1.6.0.tar.gz  boost_1_59_0.tar.gz  Discuz_X3.4_SC_UTF8.zip  httpd-2.4.29.tar.bz2  mysql-5.7.17.tar.gz  php-7.1.10.tar.bz2

二、运行脚本

[root@localhost /]#chmod +x lamp.sh 
[root@localhost /]#sh lamp.sh 
  • 然后就静静等待脚本的运行,可能时间比较久~

  • 结束会显示如下效果
    在这里插入图片描述

  • 然后登录论坛进行配置即可完成操作
    在这里插入图片描述

三、脚本

#!/bin/bash

###安装前准备
yum -y install wget bzip2
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
ntpdate ntp1.aliyun.com
IP=`ifconfig ens33 | grep netmask | tr -s ' ' @ | cut -d@ -f3`

###安装 apache
tar xf /data/apr-1.6.2.tar.gz -C /opt
tar xf /data/apr-util-1.6.0.tar.gz -C /opt 
tar xf /data/httpd-2.4.29.tar.bz2 -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
yum -y install gcc gcc-c++ make pcre 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
cd /opt/httpd-2.4.29/
make -j 4 && make install
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/

sed -i "52s/Listen 80/Listen $IP:80/" /usr/local/httpd/conf/httpd.conf
sed -i "197s/#ServerName www.example.com:80/ServerName www.example.com:80/" /usr/local/httpd/conf/httpd.conf

cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart=/usr/local/bin/apachectl $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload && systemctl start httpd.service && systemctl enable httpd.service


###安装 mysql
tar zxvf /data/mysql-5.7.17.tar.gz -C /opt
tar zxvf /data/boost_1_59_0.tar.gz -C /usr/local
mv /usr/local/boost_1_59_0 /usr/local/boost
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
useradd -s /sbin/nologin mysql
cd /opt/mysql-5.7.17/

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  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1

cd /opt/mysql-5.7.17/
make -j 4 && make install
echo > /etc/my.cnf

cat > /etc/my.cnf<<EOF
[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
auto-rehash

[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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
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
EOF

chown -R mysql.mysql /usr/local/mysql/
chown mysql.mysql /etc/my.cnf
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

cd /usr/local/mysql/bin/
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload && systemctl start mysqld && systemctl enable mysqld


###安装 PHP
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

tar jxvf /data/php-7.1.10.tar.bz2 -C /opt/
cd /opt/php-7.1.10/

./configure \
--prefix=/usr/local/php7 \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-config-file-path=/usr/local/php7 \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

cd /opt/php-7.1.10/
make -j 4 && make install

cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini

sed -i "939s/\;date.timezone =/date.timezone = Asia\/Shanghai/" /usr/local/php7/php.ini
sed -i "1170s/mysqli.default_socket =/mysqli.default_socket = \/usr\/local\/mysql\/mysql.sock/" /usr/local/php7/php.ini

ln -s /usr/local/php7/bin/* /usr/local/bin/

sed -i "s/    DirectoryIndex index.html/    DirectoryIndex index.html index.php/g" /usr/local/httpd/conf/httpd.conf
sed -i "392a AddType application/x-httpd-php .php \n AddType application/x-httpd-php-source .phps" /usr/local/httpd/conf/httpd.conf

rm -rf /usr/local/httpd/htdocs/index.html

cat > /usr/local/httpd/htdocs/index.php<<EOF
<?php
phpinfo();
?>
EOF

systemctl restart httpd.service


### 安装 Discuz
echo "CREATE DATABASE bbs;" | mysql
echo "GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';" | mysql
echo "flush privileges;" | mysql
unzip /data/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cp -r /opt/dis/dir_SC_UTF8/upload/ /usr/local/httpd/htdocs/bbs
chown -R daemon /usr/local/httpd/htdocs/bbs/config
chown -R daemon /usr/local/httpd/htdocs/bbs/data
chown -R daemon /usr/local/httpd/htdocs/bbs/uc_client
chown -R daemon /usr/local/httpd/htdocs/bbs/uc_server/data

#服务状态判断
sleep 3
echo -e "\033[33mLAMP 组件状态\033[0m"

pgrep "httpd" &> /dev/null
if [ $? -eq 0 ];then
        echo -e "\033[32mhttpd服务运行正常\033[0m"
else
        echo -e "\033[31mhttpd服务运行异常,请检查\033[0m"
fi

pgrep "mysqld" &> /dev/null
if [ $? -eq 0 ];then
        echo -e "\033[32mmysqld服务运行正常\033[0m"
else
        echo -e "\033[31mmysqld服务运行异常,请检查\033[0m"
fi

#提示信息
echo " "
sleep 2
echo -e "\033[33m如果各组件运行正常,请登录Discuz论坛,账号登录信息:\033[0m"
echo -e "\033[32m访问地址 http://<你的IP>/bbs/admin.php\033[0m"
echo -e "\033[32m数据库服务器 localhost\033[0m"
echo -e "\033[32m数据库名称 bbs\033[0m"
echo -e "\033[32m数据库用户名 bbsuser\033[0m"
echo -e "\033[32m数据库密码 admin123\033[0m"
echo -e "\033[32m管理员账号 admin\033[0m"
echo -e "\033[32m管理员密码 admin123\033[0m"
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

头发莫的了呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值