Centos 7搭建LNMP架構及部署Discuz論壇

一、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論壇

至此論壇就已經部署完成。

—————— 本文至此結束,感謝閱讀 ——————

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章