温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Centos 7搭建LNMP架构及部署Discuz论坛

发布时间:2020-09-01 14:47:56 来源:网络 阅读:537 作者:俊伟祺i 栏目:系统运维

一、LNMP架构及应用部署

众所周知,LAMP平台时目前应用最为广泛的网站服务器架构,其中的“A”对应着web服务软件的Apache HTTP Server ,随着Nginx在工作环境中的使用越来越多,LNMP(或LEMP)架构也受到越来越多的Linux运维工程师的青睐。

就像构建LAMP平台一样,构建LNMP平台也需要Linux服务器、MySQL数据库、PHP解析环境,区别主义在于Nginx与PHP的协作配置上。

准备工作

Centos 7操作系统一台;
Windows 客户端一台;
案例所需镜像及软件包请访问:https://pan.baidu.com/s/10wFG1YQaY2FTJKgMp1x0kw
提取码:rl3i

二、构建LNMP网站平台

部署前准备

①挂载Linux光盘,拷贝nginx依赖程序到/usr/src/目录
Centos 7搭建LNMP架构及部署Discuz论坛

[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# cp /mnt/nginx-1.6.0.tar.gz /usr/src/

②切换LAMP光盘,将mnt目录下所有数据拷贝到/usr/src/目录
[root@centos02 ~]# umount /mnt/

Centos 7搭建LNMP架构及部署Discuz论坛

[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# cp /mnt/* /usr/src/

③切换到操作系统光盘
[root@centos02 ~]# umount /mnt/
Centos 7搭建LNMP架构及部署Discuz论坛

[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载

1、部署Nginx静态网站

Nginx具体配置及概述请访问博客:Centos 7部署Nginx网站服务

[root@centos02 ~]# rm -rf /etc/yum.repos.d/CentOS-* 
                                  <!--清除系统自带yum源 -->
[root@centos02 ~]# yum -y install pcre-devel zlib-devel  
                             <!--安装Nginx的依赖程序-->
[root@centos02 ~]# useradd -M -s /sbin/nologin nginx  
                                                <!--创建管理Nginx的用户-->
[root@centos02 ~]# tar zxvf /usr/src/nginx-1.6.0.tar.gz -C /usr/src/
                                 <!--解压缩Nginx软件包-->
[root@centos02 ~]# cd /usr/src/nginx-1.6.0/   
[root@centos02 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module 
    <!--配置Nginx-->
[root@centos02 nginx-1.6.0]# make && make install <!--编译安装Nginx-->
[root@centos02 ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/  <!--优化Nginx执行命令-->
[root@centos02 ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
                    <!--备份主配置文件-->
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf<!--编辑主配置文件-->
  3 user  nginx;
  4 worker_processes  1;
  6 error_log  logs/error.log;
12 pid        logs/nginx.pid;
16     use epoll;
17     worker_connections  1024;
29     #access_log  logs/access.log  main;
31     sendfile        on;
35     keepalive_timeout  65;
39     server {
40         listen       80;
41         server_name  localhost;
44         charset utf-8;
48         location / {
49             root   html;
50             index  index.html index.htm;
51         }
84     }
[root@centos02 ~]# nginx   <!--启动Nginx服务-->
[root@centos02 ~]# netstat -anptu | grep nginx <!--监听Nginx服务-->
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4663/nginx: master  
[root@centos02 ~]# vim /etc/init.d/nginx <!--编写Nginx服务管理脚本-->
#!/bin/bash
#chkconfig: 35 90 30
#description:nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill 0s HUP $(cat $PIDF)
;;
*)
echo "Usage:$0 (start|stop|restart|reload)"
exit 1
esac
exit 0
[root@centos02 ~]# chmod +x /etc/init.d/nginx<!--添加脚本执行权限-->
[root@centos02 ~]# chkconfig --add nginx <!--添加系统服务-->
[root@centos02 ~]# chkconfig --level 35 nginx on <!--设置开机自动启动-->
[root@centos02 ~]# /etc/init.d/nginx stop<!--脚本停止Nginx服务-->
[root@centos02 ~]# /etc/init.d/nginx start<!--脚本启动Nginx服务-->
[root@centos02 ~]# /etc/init.d/nginx restart <!--脚本重启Nginx服务-->

至此,可以配置客户端配置与服务器同网卡、同网段的IP地址及网关,访问Nginx网站
Centos 7搭建LNMP架构及部署Discuz论坛

2、部署基于域名的虚拟主机

[root@centos02 ~]# yum -y install bind bind-chroot bind-utils  <!--安装DNS-->
[root@centos02 ~]# echo "" > /etc/named.conf     <!--清空主配置文件-->
[root@centos02 ~]# vim /etc/named.conf     <!--修改主配置文件-->
options {
        listen-on port 53 { 192.168.100.20; };
        directory "/var/named";
}
zone    "benet.com"     IN      {
        type    master;
        file    "benet.com.zone";
}
zone    "accp.com"      IN      {
        type    master;
        file    "accp.com.zone";
}
[root@centos02 ~]# named-checkconf -z /etc/named.conf
                                        <!--检查主配置文件是否配置错误-->
[root@centos02 ~]# vim /var/named/benet.com.zone 
                              <!--配置benet.com的正向解析区域-->
$TTL    86400
@       SOA     benet.com.      root.benet.com(
        2019112801
        1H
        15M
        1W
        1D
)
@       NS      centos02.benet.com.
centos02 A      192.168.100.20
www      A      192.168.100.20
[root@centos02 ~]# chmod +x /var/named/benet.com.zone
                                                <!--正向解析区域配置文件添加执行权限-->
[root@centos02 ~]# chown named:named /var/named/benet.com.zone 
                                              <!--修改属主属组-->
[root@centos02 ~]# named-checkzone benet.com /var/named/benet.com.zone  
                                     <!--检查benet.com正向解析区域配置文件是否错误-->
zone benet.com/IN: loaded serial 2019112801
OK
[root@centos02 ~]# cp /var/named/benet.com.zone /var/named/accp.com.zone 
                                    <!--复制benet.com正向解析区域到accp.com正向解析区域-->
[root@centos02 ~]# vim /var/named/accp.com.zone 
                                   <!--修改accp.com正向解析区域配置文件-->
$TTL    86400
@       SOA     accp.com.       root.accp.com(
        2019112801
        1H
        15M
        1W
        1D
)
@       NS      centos02.accp.com.
centos02 A      192.168.100.20
www      A      192.168.100.20
[root@centos02 ~]# named-checkzone accp.com /var/named/accp.com.zone 
                                <!--检查accp.com正向解析区域配置文件是否错误-->
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32<!--编辑网卡添加主DNS-->
DNS1=192.168.100.20  <!--添加DNS-->
[root@centos02 ~]# systemctl restart network     <!--重启网卡服务-->
[root@centos02 ~]# systemctl start named     <!--启动DNS服务器-->
[root@centos02 ~]# systemctl enable named    <!--设置开机自动启动-->
[root@centos02 ~]# nslookup www.benet.com     <!--解析域名测试是否正常-->
Server:     192.168.100.20
Address:    192.168.100.20#53

Name:   www.benet.com
Address: 192.168.100.20
[root@centos02 ~]# nslookup www.accp.com   <!--解析域名测试是否正常-->
Server:     192.168.100.20
Address:    192.168.100.20#53

Name:   www.accp.com
Address: 192.168.100.20
[root@centos02 ~]# mkdir -p /var/www/benetcom      <!--创建虚拟主机网站根目录-->
[root@centos02 ~]# mkdir -p /var/www/accpcom       <!--创建虚拟主机网站根目录-->
[root@centos02 ~]# echo "www.benet.com" > /var/www/benetcom/index.html    
                                     <!--创建虚拟主机的网站主页-->
[root@centos02 ~]# echo "www.accp.com" > /var/www/accpcom/index.html     
                               <!--创建虚拟主机的网站主页-->
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf <!--修改Nginx主配置文件支持虚拟主机-->
        server  {
                listen www.benet.com:80;
                server_name www.benet.com;
                charset utf-8;
                access_log      logs/www.benet.com.access.log;
                error_log       logs/www.benet.com.error.log;
                location / {
                                root /var/www/benetcom/;
                                index index.html;
                        }
                }       

        server  {
                listen www.accp.com:80;
                server_name www.accp.com;
                charset utf-8;
                access_log      logs/www.accp.com.access.log;
                error_log       logs/www.accp.com.error.log;
                location / {
                                root /var/www/accpcom/;
                                index index.html;
                        }
                }
[root@centos02 ~]# nginx -t     <!--检查Nginx是否配置错误-->
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@centos02 ~]# systemctl restart named      <!--重新启动DNS服务-->
[root@centos02 ~]# /etc/init.d/nginx restart      <!--重新启动Nginx服务-->

至此客户端添加DNS地址,访问域名即可

Centos 7搭建LNMP架构及部署Discuz论坛

Centos 7搭建LNMP架构及部署Discuz论坛

3、部署MySQL数据库

MySQL数据库具体配置及概述请访问博文:Centos安装MySQL数据库

[root@centos02 ~]# groupadd mysql    <!--创建管理组-->
[root@centos02 ~]# useradd -M -s /sbin/nologin -g mysql mysql
               <!--创建管理Mysql的用户-->
[root@centos02 ~]# yum -y install ncurses-devel <!--安装MySQL依赖程序-->
[root@centos02 ~]# tar zxvf /usr/src/cmake-2.8.6.tar.gz -C 
/usr/src/    <!--解压缩cmake软件包-->
[root@centos02 ~]# cd /usr/src/cmake-2.8.6/ 
[root@centos02 cmake-2.8.6]# ./configure && gmake && gmake install       <!--编译配置及安装gmake-->
[root@centos02 ~]# tar zxvf /usr/src/mysql-5.5.22.tar.gz -C 
/usr/src/     <!--解压缩MySQL软件包-->
[root@centos02 mysql-5.5.22]# cmake -
DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc
                             <!--配置MySQL-->
[root@centos02 mysql-5.5.22]# make && make install <!--编译安装MySQL-->
[root@centos02 mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf     
               <!--生成MySQL配置文件-->
cp:是否覆盖"/etc/my.cnf"? y   <!--输入y确定覆盖-->
[root@centos02 mysql-5.5.22]# cp support-files/mysql.server 
/etc/init.d/mysqld     <!--生成MySQL服务配置文件-->
[root@centos02 ~]# chmod +x /etc/init.d/mysqld <!--添加执行权限-->
[root@centos02 ~]# chkconfig --add mysqld <!--添加系统服务-->
[root@centos02 ~]# chkconfig --level 35 mysqld on <!--设置开机自动启动-->
[root@centos02 ~]# vim /etc/profile <!--优化MySQL程序命令-->
PATH=$PATH:/usr/local/mysql/bin/
[root@centos02 ~]# source /etc/profile   <!--执行优化-->
[root@centos02 ~]# /usr/local/mysql/scripts/mysql_install_db 
--user=mysql --basedir=/usr/local/mysql 
--datadir=/usr/local/mysql/data     <!--初始化MySQL数据库-->
[root@centos02 ~]# systemctl start mysqld <!--启动MySQL服务-->
[root@centos02 ~]# systemctl enable mysqld <!--设置开机自动启动-->
[root@centos02 ~]# mysqladmin -u root password   
                        <!--设置MySQL数据密码-->
New password:        <!--输入密码-->
Confirm new password:     <!--确定密码-->
[root@centos02 ~]# mysql -uroot -ppwd@123  
                         <!--测试是否可以正常登录数据库-->
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

4、部署PHP解析环境

1)配置php依赖程序

[root@centos02 ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel 
                    <!--安装php依赖程序-->
[root@centos02 ~]# tar zxvf /usr/src/php-5.3.28.tar.gz -C /usr/src/
                <!--解压缩php软件包-->
[root@centos02 ~]# cd /usr/src/php-5.3.28/
[root@centos02 php-5.3.28]# ./configure --prefix=/usr/local/php 
--with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql/ 
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd 
--with-zlib --with-jpeg-dir=/usr/lib --enable-mbstring 
--enable-fpm      <!--配置php-->
[root@centos02 php-5.3.28]# make && make install <!--编译安装php-->
[root@centos02 php-5.3.28]# ls -ld /usr/local/php/ <!--查看是否安装成功-->
drwxr-xr-x 10 root root 101 11月 28 20:04 /usr/local/php/

2)生成PHP配置文件优化程序执行位置

[root@centos02 php-5.3.28]# cp php.ini-production  
/usr/local/php/php.ini     <!--生成服务配置文件-->
[root@centos02 ~]# ln -s /usr/local/php/sbin/* /usr/local/sbin/ 
                <!--优化程序执行位置-->
[root@centos02 ~]# ln -s /usr/local/php/bin/* /usr/local/bin/  
                <!--优化程序执行位置-->
[root@centos02 ~]# tar zxvf /usr/src/zendguardloader-php-5.3-linux-glibc23-i386.tar.gz 
-C /usr/src/     <!--解压缩zend模块软件包-->
[root@centos02 ~]# mv /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-i386
/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/    
           <!--php加载zend模块加速访问,修改zend模块位置-->
[root@centos02 ~]# vim /usr/local/php/php.ini <!--修改php主配置文件加载zend-->
zend_extension=/usr/local/php/lib/php/ZendGuardLoader.so
zend_loader.enable=1

3)配置php-fpm支持加载动态网站

[root@centos02 ~]# cp /usr/local/php/etc/php-fpm.conf.default 
/usr/local/php/etc/php-fpm.conf <!--生成php-fpm配置文件-->
[root@centos02 ~]# vim /usr/local/php/etc/php-fpm.conf  
                  <!--修改php-fpm主配置文件-->
26 pid = run/php-fpm.pid
141 user = nginx
142 group = nginx
[root@centos02 ~]# /usr/local/sbin/php-fpm <!--启动php-fpm服务-->

[root@centos02 ~]# netstat -anptu | grep 9000 
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      127332/php-fpm: mas

4)配置nginx主配置文件支持php,配置php到www.benet.com的虚拟主机

[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf   
                      <!--修改主配置文件支持php-fpm-->
                location ~ \.php$ {
                root           /var/www/benetcom;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                include        fastcgi.conf;
                                }
[root@centos02 ~]# 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@centos02 ~]# vim /var/www/benetcom/index.php  
                  <!--编写php测试文件-->
<?php
phpinfo();
?>
[root@centos02 ~]# /etc/init.d/nginx restart <!--重新启动Nginx服务-->

至此,客户端可以访问PHP测试页
Centos 7搭建LNMP架构及部署Discuz论坛

三、基于LNMP架构搭建开源论坛

1、修改Nginx主配置文件,配置php到www.accp.com虚拟主机支持php-fpm

[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf 
104         server  {
105                 listen www.accp.com:80;
106                 server_name www.accp.com;
107                 charset utf-8;
108                 access_log      logs/www.accp.com.access.log;
109                 error_log       logs/www.accp.com.error.log;
110                 location / {
111                                 root /var/www/accpcom/;
112                                 index index.html index.php;
113                         }
114                 location ~ \.php$ {
115                 root           /var/www/accpcom;
116                 fastcgi_pass   127.0.0.1:9000;
117                 fastcgi_index  index.php;
118                 include        fastcgi.conf;
119                                 }

2、上传论坛的源代码包到服务器

Centos 7搭建LNMP架构及部署Discuz论坛
Centos 7搭建LNMP架构及部署Discuz论坛

3、配置论坛

[root@centos02 ~]# unzip Discuz_X3.2_SC_UTF8.zip  
                                                  <!--解压缩论坛-->
[root@centos02 ~]# ls 
anaconda-ks.cfg      Discuz_X3.2_SC_UTF8.zip  readme  utility
Discuz_X3.2_SC_UTF8  initial-setup-ks.cfg     upload
[root@centos02 ~]# mv ./upload/* /var/www/accpcom/<!--移动论坛到网站根目录-->
[root@centos02 ~]# chmod -R +x /var/www/accpcom/  
                                         <!--设置执行权限-->
[root@centos02 ~]# chown -R nginx:nginx /var/www/accpcom/ 
                       <!--设置网站的所有者-->
[root@centos02 ~]# mysql -uroot -ppwd@123
mysql> create database bbs;
                  <!--创建论坛的数据库-->
mysql> grant all on bbs.* to bbs@localhost identified by 'pwd@123';
              <!--授权bbs账号管理bbs数据库-->
[root@centos02 ~]# /etc/init.d/nginx restart <!--重新启动Nginx服务-->

4、客户端访问论坛网站

1)客户端浏览器输入www.accp.com/install访问,单击我同意开始安装
Centos 7搭建LNMP架构及部署Discuz论坛

2)检查安装环境
Centos 7搭建LNMP架构及部署Discuz论坛

3)选择全新安装,单击下一步
Centos 7搭建LNMP架构及部署Discuz论坛

4)设置数据库的用户及密码
Centos 7搭建LNMP架构及部署Discuz论坛

5)等待安装完成即可
Centos 7搭建LNMP架构及部署Discuz论坛

6)删除accp.com网站的默认首页
[root@centos02 ~]# rm -rf /var/www/accpcom/index.html

7)客户端访问
Centos 7搭建LNMP架构及部署Discuz论坛

8)登录后台管理网站
Centos 7搭建LNMP架构及部署Discuz论坛
Centos 7搭建LNMP架构及部署Discuz论坛

至此论坛就已经部署完成。

—————— 本文至此结束,感谢阅读 ——————

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI