LNMP架构以及Discuz论坛搭建

一曲冷凌霜 提交于 2019-12-28 11:21:35

LNMP架构以及Discuz论坛搭建

前言

之前,我们装过了LAMP架构,接下来,我们来体验一下LNMP架构的搭建。首先,什么是LNMP架构?LAMP架构是Linux+Apache+MySQL+PHP构成的一个架构,而LNMP是由Linux+Nginx+MySQL+PHP构成的一个架构。接下来,我们来看看怎么搭建这个LNMP架构。

实验环境

centos7主机一台

win10主机一台

实验所需要的源码包

链接:https://pan.baidu.com/s/12fH_wVyJ_OeC1AMzSDr5rg
提取码:p2ae

实验步骤

1.Nginx的搭建

1.首先,我们将防火墙及安全型增强性功能关闭,然后将软件包解压到/opt/目录下

[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  LNMP-C7  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# cd LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip    nginx-1.12.2.tar.gz  php-7.1.20.tar.bz2
mysql-boost-5.7.20.tar.gz  php-5.6.11.tar.bz2   php-7.1.20.tar.gz
ncurses-5.6.tar.gz         php-7.1.10.tar.bz2   zend-loader-php5.6-linux-x86_64_update1.tar.gz
[root@localhost LNMP-C7]# tar -zxvf nginx-1.12.2.tar.gz -C /opt/
[root@localhost LNMP-C7]# systemctl stop firewalld
[root@localhost LNMP-C7]# setenforce 0

2.我们先下载编译Nginx源码包的软件包

[root@localhost LNMP-C7]# yum -y install gcc gcc-c++ make pcre* zlib-devel
[root@localhost LNMP-C7]# rpm -q gcc
gcc-4.8.5-39.el7.x86_64
[root@localhost LNMP-C7]# rpm -q gcc-c++
gcc-c++-4.8.5-39.el7.x86_64
[root@localhost LNMP-C7]# rpm -q pcre
pcre-8.32-17.el7.x86_64
[root@localhost LNMP-C7]# rpm -q pcre-devel
pcre-devel-8.32-17.el7.x86_64
[root@localhost LNMP-C7]# rpm -q zlib-devel
zlib-devel-1.2.7-18.el7.x86_64
[root@localhost LNMP-C7]# rpm -q make 
make-3.82-24.el7.x86_64

3.创建Nginx的程序型用户,并去Nginx的目录下面

[root@localhost LNMP-C7]# cd
[root@localhost ~]# cd /opt
[root@localhost opt]# ls
nginx-1.12.2  rh
[root@localhost opt]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@localhost nginx-1.12.2]# useradd -M -s /sbin/nologin nginx

4.开始编译安装

[root@localhost nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
[root@localhost nginx-1.12.2]# make && make install

5.对nginx进行一些优化

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.12.2]# ll /usr/local/sbin/nginx 
lrwxrwxrwx. 1 root root 27 12月 23 14:51 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx
[root@localhost nginx-1.12.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.12.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.12.2]# nginx 
[root@localhost nginx-1.12.2]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5338/nginx: master 
[root@localhost nginx-1.12.2]# cd
[root@localhost ~]# vim /lib/systemd/system/nginx.service 
[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
[root@localhost ~]# systemctl daemon-reload

2.MySQL的搭建

1.将MySQL的源码包解压到/opt/目录下

[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  LNMP-C7  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# cd LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip    nginx-1.12.2.tar.gz  php-7.1.20.tar.bz2
mysql-boost-5.7.20.tar.gz  php-5.6.11.tar.bz2   php-7.1.20.tar.gz
ncurses-5.6.tar.gz         php-7.1.10.tar.bz2   zend-loader-php5.6-linux-x86_64_update1.tar.gz
[root@localhost LNMP-C7]# tar -zxvf mysql-boost-5.7.20.tar.gz -C /opt/

2.安装必要的MySQL编译的源码包

[root@localhost LNMP-C7]# yum -y install ncurses ncurses-devel bison cmake
[root@localhost LNMP-C7]# rpm -q ncurses
ncurses-5.9-14.20130511.el7_4.x86_64
[root@localhost LNMP-C7]# rpm -q ncurses-devel
ncurses-devel-5.9-14.20130511.el7_4.x86_64
[root@localhost LNMP-C7]# rpm -q cmake
cmake-2.8.12.2-2.el7.x86_64
[root@localhost LNMP-C7]# rpm -q bison
bison-3.0.4-2.el7.x86_64

3.到/opt/mysql-5.7.20/目录下面,开始进行手工编译

[root@localhost LNMP-C7]# cd
[root@localhost ~]# cd /opt
[root@localhost opt]# ls
mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh
[root@localhost opt]# cd mysql-5.7.20/
[root@localhost mysql-5.7.20]# ls
boost           config.h.cmake       extra                libmysql     mysys_ssl  scripts        testclients
BUILD           configure.cmake      include              libmysqld    packaging  sql            unittest
client          COPYING              INSTALL              libservices  plugin     sql-common     VERSION
cmake           dbug                 libbinlogevents      man          rapid      storage        vio
CMakeLists.txt  Docs                 libbinlogstandalone  mysql-test   README     strings        win
cmd-line-utils  Doxyfile-perfschema  libevent             mysys        regex      support-files  zlib
[root@localhost mysql-5.7.20]# 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_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=boost \
> -DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]# make 
[root@localhost mysql-5.7.20]# make install

4.对MySQL进行优化

[root@localhost mysql-5.7.20]# useradd -s /sbin/nologin mysql
[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost mysql-5.7.20]# vim /etc/my.cnf
[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

[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf
[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile
[root@localhost mysql-5.7.20]# source /etc/profile
[root@localhost mysql-5.7.20]# echo $PATH
/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost mysql-5.7.20]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
2019-12-23T09:05:45.185319Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-23T09:05:45.620772Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-23T09:05:45.689529Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-23T09:05:45.746927Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 678c72cc-2563-11ea-88b8-000c29937a63.
2019-12-23T09:05:45.747775Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-23T09:05:45.748460Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@localhost mysql]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl stop mysqld
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# netstat -ntap | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      21713/mysqld 
[root@localhost mysql]# mysqladmin -uroot -p password
Enter password:     //直接enter,没有密码
New password:          //我们设置密码为abc123
Confirm new password:  //再一次输入密码为abc123
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@localhost mysql]# mysql -u root -p   //登录mysql
Enter password:     //输入密码为abc123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases;    //查看数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit
Bye

3.PHP的搭建

1.将PHP的源码包解压到/opt/目录下面

[root@localhost mysql]# cd
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  LNMP-C7  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# cd LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip    nginx-1.12.2.tar.gz  php-7.1.20.tar.bz2
mysql-boost-5.7.20.tar.gz  php-5.6.11.tar.bz2   php-7.1.20.tar.gz
ncurses-5.6.tar.gz         php-7.1.10.tar.bz2   zend-loader-php5.6-linux-x86_64_update1.tar.gz
[root@localhost LNMP-C7]# tar -jxvf php-7.1.10 -C /opt/

2.安装编译PHP的源码包的必要文件

[root@localhost LNMP-C7]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
[root@localhost LNMP-C7]# rpm -q libjpeg-turbo
libjpeg-turbo-1.2.90-8.el7.x86_64
[root@localhost LNMP-C7]# rpm -q libjpeg-turbo-devel
libjpeg-turbo-devel-1.2.90-8.el7.x86_64
[root@localhost LNMP-C7]# rpm -q libpng
libpng-1.5.13-7.el7_2.x86_64
[root@localhost LNMP-C7]# rpm -q libpng-devel
libpng-devel-1.5.13-7.el7_2.x86_64
[root@localhost LNMP-C7]# rpm -q freetype
freetype-2.8-14.el7.x86_64
[root@localhost LNMP-C7]# rpm -q freetype-devel
freetype-devel-2.8-14.el7.x86_64
[root@localhost LNMP-C7]# rpm -q libxml2
libxml2-2.9.1-6.el7_2.3.x86_64
[root@localhost LNMP-C7]# rpm -q libxml2-devel
libxml2-devel-2.9.1-6.el7_2.3.x86_64
[root@localhost LNMP-C7]# rpm -q zlib
zlib-1.2.7-18.el7.x86_64
[root@localhost LNMP-C7]# rpm -q zlib-devel
zlib-devel-1.2.7-18.el7.x86_64
[root@localhost LNMP-C7]# rpm -q curl
curl-7.29.0-54.el7_7.1.x86_64
[root@localhost LNMP-C7]# rpm -q libcurl-devel
libcurl-devel-7.29.0-54.el7_7.1.x86_64
[root@localhost LNMP-C7]# rpm -q openssl
openssl-1.0.2k-19.el7.x86_64
[root@localhost LNMP-C7]# rpm -q openssl-devel
openssl-devel-1.0.2k-19.el7.x86_64

3.到/opt/php-7.1.10的目录下进行编译安装

[root@localhost LNMP-C7]# cd
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  LNMP-C7  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# cd /opt
[root@localhost opt]# ls
mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh
[root@localhost opt]# cd php-7.1.10/
[root@localhost php-7.1.10]# ls
acinclude.m4      header           php.ini-development               README.WIN32-BUILD-SYSTEM
aclocal.m4        INSTALL          php.ini-production                run-tests.php
appveyor          install-sh       README.EXT_SKEL                   sapi
build             LICENSE          README.GIT-RULES                  scripts
buildconf         ltmain.sh        README.input_filter               server-tests-config.php
buildconf.bat     main             README.MAILINGLIST_RULES          server-tests.php
CODING_STANDARDS  makedist         README.md                         snapshot
config.guess      Makefile.frag    README.namespaces                 stamp-h.in
config.sub        Makefile.gcov    README.NEW-OUTPUT-API             stub.c
configure         Makefile.global  README.PARAMETER_PARSING_API      tests
configure.in      makerpm          README.REDIST.BINS                travis
CONTRIBUTING.md   missing          README.RELEASE_PROCESS            TSRM
CREDITS           mkinstalldirs    README.SELF-CONTAINED-EXTENSIONS  UPGRADING
ext               netware          README.STREAMS                    UPGRADING.INTERNALS
EXTENSIONS        NEWS             README.SUBMITTING_PATCH           vcsclean
footer            pear             README.TESTING                    win32
generated_lists   php7.spec.in     README.TESTING2                   Zend
genfiles          php.gif          README.UNIX-BUILD-SYSTEM
[root@localhost php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype=dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@localhost php-7.1.10]# make
[root@localhost php-7.1.10]# make install

4.对PHP进行优化

[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini
date.timezone = Asia/ShangHai
mysqli.default_socket = /usr/local/mysql/mysql.sock
[root@localhost php-7.1.10]# /usr/local/php/bin/php -m 
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
[root@localhost php-7.1.10]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# cd /usr/local/php/etc/
[root@localhost etc]# vim php-fpm.conf
pid = run/php-fpm.pid
[root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost etc]# netstat -ntap|grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      25489/php-fpm: mast 
[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@localhost etc]# ps aux | grep -c "php-fpm"
4
[root@localhost etc]# vim /usr/local/nginx/conf/nginx.conf
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }
[root@localhost etc]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

实验测试

在win10主机里面输入服务器的ip地址

在这里插入图片描述

在这里插入图片描述

创建论坛

1.在mysql中创建bbsuser的用户密码为admin123

[root@localhost etc]# mysql -u root -p
Enter password:   //输入密码“abc123”
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> create database bbs;  //创建bbs数据库
Query OK, 1 row affected (0.00 sec)

mysql> show databases;    //查看数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123'; //创建用户和密码
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> grant all on bbs.* to 'bbsuser'@'localhost' identified by 'admin123'; //创建用户和密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;   //刷新当前的数据库
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

2.将论坛的压缩包解压到/opt/目录下面

[root@localhost etc]# cd
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  LNMP-C7  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# cd LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip    nginx-1.12.2.tar.gz  php-7.1.20.tar.bz2
mysql-boost-5.7.20.tar.gz  php-5.6.11.tar.bz2   php-7.1.20.tar.gz
ncurses-5.6.tar.gz         php-7.1.10.tar.bz2   zend-loader-php5.6-linux-x86_64_update1.tar.gz
[root@localhost LNMP-C7]# unzip Discuz_X3.4_SC_UTF8.zip -d /opt/

3.对论坛文件进行修改

[root@localhost LNMP-C7]# cd /opt/dir_SC_UTF8/
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/
[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/
[root@localhost bbs]# chown -R root:nginx ./config/
[root@localhost bbs]# chown -R root:nginx ./data/
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# chown -R root:nginx ./uc_server/
[root@localhost bbs]# chmod -R 777 ./config/
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/

4.在win10主机里面安装论坛

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

当点击下一步时,论坛就已经在安装了,然后我们就在地址栏里面输入192.168.73.172/bbs/index.php即可访问我们的论坛了

在这里插入图片描述

至此,实验已经大功告成了,我们可以后续对这个论坛进行优化等。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!