Linux云计算架构-使用LNMP架构部署Discuz论坛

Linux云计算架构-使用LNMP架构部署Discuz论坛

1. 配置LNMP环境

①下载aliyun的yum源,下载地址https://developer.aliyun.com/mirror/

# 移除原来的yum源
[root@server ~]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# ll
总用量 12
-rw-r--r--. 1 root root 2523 6月  16 2018 Centos-7.repo
-rw-r--r--. 1 root root  664 5月  11 2018 epel-7.repo
-rw-r--r--. 1 root root   71 10月 20 13:58 local.repo
[root@server yum.repos.d]# mv ./* /opt/
[root@server yum.repos.d]# ll
总用量 0

# 下载aliyun最新的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@server yum.repos.d]# ll
总用量 8
-rw-r--r--. 1 root root 2523 6月  16 2018 CentOS-Base.repo
-rw-r--r--. 1 root root  664 5月  11 2018 epel.repo

# 清空原来的缓存,生成新的缓存。
[root@server yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base epel extras updates
Cleaning up list of fastest mirrors
Other repos take up 50 M of disk space (use --verbose for details)
[root@server yum.repos.d]# yum makecache

②部署LNMP环境:

# yum快速部署LNMP环境
[root@server ~]# yum install nginx mariadb mariadb-server php php-mysql php-fpm php-gd php-mysql php-mbstring php-xml php-mcrypt php-imap php-odbc php-pear php -xmlrpc -y

# 启动php-fpm
[root@server ~]# systemctl start php-fpm.service
[root@server ~]# systemctl enable php-fpm.service

# 启动mysql数据库,并创建数据库discuz和用户discuz
[root@server install]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on discuz.* to discuz@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
# 测试下能否使用discuz用户登录数据库,如果不行,估计后面安装的时候会报错。
[root@server ~]# mysql -udiscuz -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 


# 修改nginx的配置文件,以支持php
[root@server ~]# cd /etc/nginx/
[root@server nginx]# cp nginx.conf nginx.conf.bak 
[root@server nginx]# vim /etc/nginx/nginx.conf
    server {
    
    
        listen       80;
        server_name  localhost;
        
        location / {
    
    
            root         /usr/share/nginx/html;
            index index.html index.htm index.php;   # 指定首页文件,从左往右匹配,用空格隔开。
        }
        location ~ \.php$ {
    
       # 配置支持php
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
                include        fastcgi_params;
        }

        error_page 404 /404.html;
        location = /404.html {
    
    
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    
    
        }
    }

# 启动并设置开机自启动
[root@server nginx]# systemctl start nginx.service 
[root@server nginx]# systemctl enable nginx.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /

# 编写一个简单的php首页文件,用来测试是否支持php
[root@server nginx]# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/index.php

# 开放防火墙的80端口号
[root@server nginx]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@server nginx]# firewall-cmd --reload
success

访问IP地址192.168.80.128自动跳转:http://192.168.80.128/index.php,如下:
在这里插入图片描述

2. 安装Discuz_X3.4

下载地址https://gitee.com/3dming/DiscuzL/attach_files
在这里插入图片描述
①上传discuz论坛的安装包,并配置nginx网站数据目录。

# 上传并解压Discuz安装包
[root@server ~]# cd /usr/local/src/
[root@server src]# rz
[root@server src]# ll Discuz_X3.4_SC_UTF8【20200818】.zip 
-rw-r--r--. 1 root root 12144234 11月 10 22:13 Discuz_X3.4_SC_UTF8【20200818】.zip
[root@server src]# unzip Discuz_X3.4_SC_UTF8【20200818】.zip -d discuz
[root@server src]# ll
总用量 11860
drwxr-xr-x. 5 root root       85 11月 10 22:15 discuz
-rw-r--r--. 1 root root 12144234 11月 10 22:13 Discuz_X3.4_SC_UTF8【20200818】.zip


# 移除nginx网站数据目录下的首页文件
[root@server ~]# cd /usr/share/nginx/html/
[root@server html]# ll
总用量 16
-rw-r--r--. 1 root root 3650 6月   8 00:28 404.html
-rw-r--r--. 1 root root 3693 6月   8 00:28 50x.html
lrwxrwxrwx. 1 root root   20 11月 10 21:37 en-US -> ../../doc/HTML/en-US
drwxr-xr-x. 2 root root   27 11月 10 21:37 icons
lrwxrwxrwx. 1 root root   18 11月 10 21:37 img -> ../../doc/HTML/img
lrwxrwxrwx. 1 root root   25 11月 10 21:37 index.html -> ../../doc/HTML/index.html
-rw-r--r--. 1 root root   20 11月 10 21:44 index.php
-rw-r--r--. 1 root root  368 6月   8 00:28 nginx-logo.png
lrwxrwxrwx. 1 root root   14 11月 10 21:37 poweredby.png -> nginx-logo.png
[root@server html]# mv ./{index.html,50x.html,index.php} /opt


# 复制discuz论坛的页面到nginx的网站数据目录下
[root@server ~]# cd /usr/local/src/discuz/upload/
[root@server upload]# cp -r ./* /usr/share/nginx/html/
[root@server upload]# cd /usr/share/nginx/html/
[root@server html]# ll
总用量 76
-rw-r--r--.  1 root root 3650 6月   8 00:28 404.html
-rw-r--r--.  1 root root 2738 11月 11 14:19 admin.php
drwxr-xr-x.  9 root root  135 11月 11 14:19 api
-rw-r--r--.  1 root root  727 11月 11 14:19 api.php
drwxr-xr-x.  2 root root   23 11月 11 14:19 archiver
drwxr-xr-x.  2 root root   90 11月 11 14:19 config
-rw-r--r--.  1 root root 1017 11月 11 14:19 connect.php
-rw-r--r--.  1 root root  106 11月 11 14:19 crossdomain.xml
drwxr-xr-x. 12 root root  202 11月 11 14:19 data
lrwxrwxrwx.  1 root root   20 11月 11 14:03 en-US -> ../../doc/HTML/en-US
-rw-r--r--.  1 root root 5558 11月 11 14:19 favicon.ico
-rw-r--r--.  1 root root 2245 11月 11 14:19 forum.php
-rw-r--r--.  1 root root  821 11月 11 14:19 group.php
-rw-r--r--.  1 root root 1280 11月 11 14:19 home.php
drwxr-xr-x.  2 root root   27 11月 11 14:03 icons
lrwxrwxrwx.  1 root root   18 11月 11 14:03 img -> ../../doc/HTML/img
-rw-r--r--.  1 root root 6472 11月 11 14:19 index.php
drwxr-xr-x.  5 root root   64 11月 11 14:19 install
drwxr-xr-x.  2 root root   23 11月 11 14:19 m
-rw-r--r--.  1 root root 1025 11月 11 14:19 member.php
-rw-r--r--.  1 root root 2435 11月 11 14:19 misc.php
-rw-r--r--.  1 root root  368 6月   8 00:28 nginx-logo.png
-rw-r--r--.  1 root root 1788 11月 11 14:19 plugin.php
-rw-r--r--.  1 root root  977 11月 11 14:19 portal.php
lrwxrwxrwx.  1 root root   14 11月 11 14:03 poweredby.png -> nginx-logo.png
-rw-r--r--.  1 root root  582 11月 11 14:19 robots.txt
-rw-r--r--.  1 root root 1155 11月 11 14:19 search.php
drwxr-xr-x. 10 root root  168 11月 11 14:19 source
drwxr-xr-x.  7 root root   86 11月 11 14:19 static
drwxr-xr-x.  3 root root   38 11月 11 14:19 template
drwxr-xr-x.  7 root root  106 11月 11 14:19 uc_client
drwxr-xr-x. 13 root root  241 11月 11 14:19 uc_server


# 为网页数据设置权限,并设置selinux,否则会出现网站数据目录不可读。
[root@server ~]# chown -R nginx:nginx /usr/share/nginx/html/
[root@server ~]# chmod -R 777 /usr/share/nginx/html/
[root@server ~]# setenforce 0
[root@server ~]# getenforce 
Permissive

②安装discuz论坛:
输入网址http://192.168.80.128/install/
在这里插入图片描述
点击“我同意”:
在这里插入图片描述
全部都是正确,然后点击“下一步”:
在这里插入图片描述
输入之前创建的discuz数据库信息:
在这里插入图片描述
点击”下一步“,开始安装,安装好如下:
在这里插入图片描述
③登录discuz论坛:
输入网址http://192.168.80.128/
在这里插入图片描述
输入管理员admin的账号密码:
在这里插入图片描述
可以看到,已经登录成功了。
在这里插入图片描述
拓展:Discuz论坛主要是由php页面构成,如需做负载均衡,可以考虑使用apache做后端服务器。若程序主要由jsp页面构成,可以考虑使用tomcat做后端服务器。有兴趣的同学可以构建下nginx+apache架构实现负载均衡。

猜你喜欢

转载自blog.csdn.net/weixin_36522099/article/details/109464934