實現CentOS 7 編譯安裝基於 fastcgi 模式的多虛擬主機的wordpress和discuz的LAMP架構 [toc] 準備環境: 兩台主機: 一臺主機:httpd+php(fastcgi模式) 一臺主機:mariadb 伺服器 準備軟體版本: 主機名修改用以區分 資料庫伺服器 實現資料庫 ...
目錄
實現CentOS 7 編譯安裝基於 fastcgi 模式的多虛擬主機的wordpress和discuz的LAMP架構
準備環境:
兩台主機:
一臺主機:httpd+php(fastcgi模式)
一臺主機:mariadb 伺服器
準備軟體版本:
mariadb-10.2.27-linux-x86_64.tar.gz 通用二進位格式
apr-1.7.0.tar.bz2
apr-util-1.6.1.tar.bz2
httpd-2.4.41.tar.gz
php-7.4.0.tar.xz
wordpress-5.3-zh_CN.tar.gz
Discuz_X3.4_SC_UTF8【20190917】.zip
主機名修改用以區分
# 作為httpd和php伺服器使用
[root@centos7 ~]$hostname websrv
[root@centos7 ~]$exit
[root@websrv ~]$
# 作為資料庫使用
[root@centos7 ~]$hostname mysql
[root@centos7 ~]$exit
[root@mysql ~]$
資料庫伺服器
實現資料庫二進位安裝(並加上LAMP需要的配置)
- 準備好二進位mariadb安裝包
[root@centos7 data]$ll
total 449668
-rw-r--r-- 1 root root 460459738 Sep 12 09:08 mariadb-10.2.27-linux-x86_64.tar.gz
- 解壓安裝包
[root@centos7 data]$tar xvf mariadb-10.2.27-linux-x86_64.tar.gz
[root@centos7 data]$ll
total 449668
drwxrwxr-x 12 yang yang 282 Sep 10 02:02 mariadb-10.2.27-linux-x86_64
-rw-r--r-- 1 root root 460459738 Sep 12 09:08 mariadb-10.2.27-linux-x86_64.tar.gz
- 把解壓後的資料庫目錄移動到usr/local下統一管理
[root@centos7 data]$mv mariadb-10.2.27-linux-x86_64 /usr/local/ # 移動
[root@centos7 local]$ln -s /usr/local/mariadb-10.2.27-linux-x86_64/ /usr/local/mysql # 創建軟連接
[root@centos7 local]$ll /usr/local/mysql
lrwxrwxrwx 1 root root 40 Dec 15 14:44 /usr/local/mysql -> /usr/local/mariadb-10.2.27-linux-x86_64/
- 創建服務用戶,並修改mysql目錄下的許可權。
[root@centos7 data]$useradd -s /sbin/nologin -d /data/mysql -r -u 306 mysql # 創建服務用戶
[root@centos7 local]$chown -R root.root mysql/* # 修改為root
[root@centos7 local]$ll mysql/
total 176
drwxrwxr-x 2 root root 4096 Aug 14 02:55 bin
-rw-r--r-- 1 root root 17987 Sep 8 21:25 COPYING
-rw-r--r-- 1 root root 2354 Sep 8 21:25 CREDITS
drwxrwxr-x 3 root root 18 Sep 10 02:02 data
-rw-r--r-- 1 root root 8245 Sep 8 21:25 EXCEPTIONS-CLIENT
drwxrwxr-x 3 root root 19 Sep 10 02:02 include
-rw-r--r-- 1 root root 8694 Sep 8 21:25 INSTALL-BINARY
drwxrwxr-x 5 root root 335 Aug 14 02:55 lib
drwxrwxr-x 4 root root 30 Sep 10 02:02 man
drwxrwxr-x 11 root root 4096 Sep 10 02:02 mysql-test
-rw-r--r-- 1 root root 2843 Sep 8 21:25 README.md
-rw-r--r-- 1 root root 19477 Sep 8 21:25 README-wsrep
drwxrwxr-x 2 root root 30 Sep 10 02:02 scripts
drwxrwxr-x 32 root root 4096 Sep 10 02:02 share
drwxrwxr-x 4 root root 4096 Sep 10 02:02 sql-bench
drwxrwxr-x 3 root root 275 Sep 10 02:02 support-files
-rw-r--r-- 1 root root 86263 Sep 8 21:25 THIRDPARTY
- 創建資料庫
[root@centos7 mysql]$/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
# 創建資料庫時缺少包(libaio)
[root@centos7 mysql]$yum install libaio -y # 下載依賴包
[root@centos7 mysql]$/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysql --user=mysql # 創建資料庫(/data下沒有這個目錄會自動創建)
[root@centos7 mysql]$ll /data/
total 449668
-rw-r--r-- 1 root root 460459738 Sep 12 09:08 mariadb-10.2.27-linux-x86_64.tar.gz
drwx------ 5 mysql root 181 Dec 15 14:55 mysql # 資料庫創建成功
[root@centos7 mysql]$ll /data/mysql/ # 查看用戶和所屬組
total 110620
-rw-rw---- 1 mysql mysql 16384 Dec 15 14:55 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 Dec 15 14:55 aria_log_control
-rw-rw---- 1 mysql mysql 938 Dec 15 14:55 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 Dec 15 14:55 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Dec 15 14:55 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Dec 15 14:55 ib_logfile1
drwx------ 2 mysql mysql 4096 Dec 15 14:55 mysql
drwx------ 2 mysql mysql 20 Dec 15 14:55 performance_schema
drwx------ 2 mysql mysql 20 Dec 15 14:55 test
- 準備配置文件(指明資料庫路徑)
[root@centos7 ~]$cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf -b # 找到解壓目錄下的配置文件替換掉/etc下的配置文件並備份
cp: overwrite ‘/etc/my.cnf’? y
# 原系統/etc下就有一個my.cnf的配置文件但是需要改配置
[root@centos7 mysql]$vim /etc/my.cnf
[mysqld]
datadir=/data/mysql # 加上這一行就夠了 (需要啟用二進位日誌啊之類的根據需要啟動)
如果上一步cp沒做直接用的自帶的文件,註意sock路經。(服務可能起不來是因為啟動過一次之後系統建立了一個sock路徑但是用的是系統自帶的配置文件建立的路徑。你在拷貝配置文件過去後一定要確保沒有啟動過服務。如果啟動過請重啟電腦或刪掉舊的配置文件建立的sock文件再啟動服務)
- 製作啟動服務(類似於centos6的啟動腳本)
[root@centos7 mysql]$cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # 拷貝目錄下的server啟動腳本到
[root@centos7 mysql]$chkconfig --list # 查看註冊了哪些服務
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@centos7 mysql]$chkconfig --add mysqld # 添加服務
[root@centos7 mysql]$chkconfig --list # 再次查看
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off # 添加上了
- 添加PATH變數
[root@centos7 ~]$echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[root@centos7 ~]$. /etc/profile.d/mysql.sh
- 創建部署軟體需要的資料庫和用戶並授權
# 創建資料庫
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| discuz |
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
6 rows in set (0.00 sec)
# 創建用戶並授權
MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.39.%' identified by 'taotaobao';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on discuz.* to discuz@'192.168.39.%' identified by 'taotaobao';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host,password from mysql.user; # 查看創建的賬戶
+-----------+--------------+-------------------------------------------+
| user | host | password |
+-----------+--------------+-------------------------------------------+
| root | localhost | |
| root | centos7 | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | centos7 | |
| wordpress | 192.168.39.% | *114893F4494D9D1D5AE2BCCACDD663C08715DA05 |
| discuz | 192.168.39.% | *114893F4494D9D1D5AE2BCCACDD663C08715DA05 |
+-----------+--------------+-------------------------------------------+
8 rows in set (0.00 sec)
資料庫需要的基本配置完畢
websrv伺服器端
- websrv端需要的包
[root@centos7 ~]$ll
total 43984
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
-rw-r--r-- 1 root root 11800498 Dec 12 14:57 Discuz_X3.4_SC_UTF8【20191201】.zip
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
-rw-r--r-- 1 root root 10232208 Dec 14 08:30 php-7.4.0.tar.xz
-rw-r--r-- 1 root root 12423575 Dec 12 14:18 wordpress-5.3-zh_CN.tar.gz
編譯安裝httpd
- 解壓httpd和apr包
[root@centos7 data]$ll
total 10324
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
[root@centos7 data]$tar xvf apr-1.7.0.tar.bz2 # 最小化安裝缺少包
tar (child): cannot run bzip2: No such file or directory
tar (child): trying lbzip2
tar (child): lbzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
[root@centos7 data]$yum install bzip2 # 下載解壓需要的包
# 解壓
[root@centos7 data]$tar xvf apr-1.7.0.tar.bz2
[root@centos7 data]$tar xvf apr-util-1.6.1.tar.bz2
[root@centos7 data]$tar xvf httpd-2.4.41.tar.gz
[root@centos7 data]$ll
total 10336
drwxr-xr-x 27 1001 1001 4096 Apr 2 2019 apr-1.7.0
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
drwxr-xr-x 20 1001 1001 4096 Oct 18 2017 apr-util-1.6.1
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
drwxr-sr-x 11 root 40 4096 Aug 9 21:36 httpd-2.4.41
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
- 合併三個目錄一起編譯
[root@centos7 data]$mv apr-1.7.0 httpd-2.4.41/srclib/apr
[root@centos7 data]$mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util
- 下載相關依賴包
[root@centos7 data]$yum install gcc pcre-devel openssl-devel expat-devel -y
- 進入目錄下進行編譯安裝
[root@centos7 data]$cd httpd-2.4.41/ # 進入目錄
[root@centos7 httpd-2.4.41]$./configure \
> --prefix=/app/httpd24 \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-included-apr \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
[root@centos7 httpd-2.4.41]$make -j 4 && make install # 製作安裝
- 準備PATH變數
[root@centos7 httpd-2.4.41]$echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh # 添加變數
[root@centos7 httpd-2.4.41]$. /etc/profile.d/lamp.sh # 載入變數
[root@centos7 httpd-2.4.41]$echo $PATH # 查看變數
/app/httpd24/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
- 創建apache賬戶
# 工作中最好指明UID,UID要統一.
[root@centos7 httpd-2.4.41]$useradd -s /sbin/nologin -r -u 88 apache
- 修改httpd配置文件
[root@centos7 httpd-2.4.41]$vim /app/httpd24/conf/httpd.conf
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User apache # 預設為daemon監管改為apache
Group apache # 同上
</IfModule>
# 網站主頁面定義為/data/(隨自己需求)
DocumentRoot "/data/"
<Directory "/data/">
- 啟動服務
[root@centos7 httpd-2.4.41]$apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:feac:5484%eth0. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
[root@centos7 httpd-2.4.41]$ss -ntlup
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 *:22 *:* users:(("sshd",pid=6461,fd=3))
tcp LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=6581,fd=13))
tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=49496,fd=4),("httpd",pid=49495,fd=4),("httpd",pid=49494,fd=4),("httpd",pid=49493,fd=4),("httpd",pid=49492,fd=4),("httpd",pid=49491,fd=4))
tcp LISTEN 0 128 :::22 :::* users:(("sshd",pid=6461,fd=4))
tcp LISTEN 0 100 ::1:25 :::* users:(("master",pid=6581,fd=14))
- 修改ServerName配置不在提示
[root@centos7 httpd-2.4.41]$vim /app/httpd24/conf/httpd.conf
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80 # 這一行取消註釋,名字是什麼都可以。
[root@centos7 httpd-2.4.41]$apachectl restart # 不在提示
[root@centos7 httpd-2.4.41]$
- 修改為event模式
[root@centos7 httpd-2.4.41]$vim /app/httpd24/conf/httpd.conf
# 預設centos7為prefork模式,所以需要修改
LoadModule mpm_event_module modules/mod_mpm_event.so # 取消註釋啟用
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so # 加上註釋禁用
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
[root@centos7 httpd-2.4.41]$apachectl restart
- 可以根據需求調節這些配置對應生產調到生產中最大值
[root@centos7 httpd-2.4.41]$vim /app/httpd24/conf/extra/httpd-mpm.conf
# event MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestWorkers: maximum number of worker threads
# MaxConnectionsPerChild: maximum number of connections a server process serves
# before terminating
<IfModule mpm_event_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
現在httpd服務已經可以訪問了!
web界面測試訪問(it works! 是預設顯示)
編譯安裝fastcgi 方式的 php7.3
- php7.3和php7.4依賴包稍有差別
#安裝相關包,依賴EPEL源
#php 7.3 相關包
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel
#php 7.4 相關包
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel
oniguruma-devel
- 安裝依賴包
[root@centos7 data]$yum install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel
- 解壓php編譯安裝包
[root@centos7 data]$tar xvf php-7.4.0.tar.xz
[root@centos7 data]$ll
total 20328
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
drwxr-sr-x 12 root 40 4096 Dec 15 16:14 httpd-2.4.41
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
drwxrwxr-x 16 root root 4096 Nov 27 04:13 php-7.4.0 # 解壓完的目錄
-rw-r--r-- 1 root root 10232208 Dec 14 08:30 php-7.4.0.tar.xz
- 進入php目錄下進行編譯
# 7.4編譯方式
[root@centos7 data]$cd php-7.4.0/
[root@centos7 data]$./configure \
--prefix=/app/php74 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@centos7 data]$make -j 4 && make install
[root@centos7 php-7.4.0]$/app/php74/bin/php --version # 查看版本號
PHP 7.4.0 (cli) (built: Dec 15 2019 17:15:08) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies # 這行是引擎版本
# 7.3編譯方式
./configure --prefix=/app/php73 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
- 準備PATH變數
# 修改之前準備好的變數
[root@centos7 php-7.4.0]$vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin:/app/php/bin/:$PATH
[root@centos7 php-7.4.0]$. /etc/profile.d/lamp.sh
- 準備php配置文件
[root@centos7 php-7.4.0]$cp php.ini-production /etc/php.ini
- 準本fastcgi(fpm)主配置文件(改名=啟用)
[root@centos7 php-7.4.0]$cd /app/php74/etc/
[root@centos7 etc]$cp php-fpm.conf.default php-fpm.conf
[root@centos7 etc]$ll
total 16
-rw-r--r-- 1 root root 5357 Dec 15 17:28 php-fpm.conf
-rw-r--r-- 1 root root 5357 Dec 15 17:15 php-fpm.conf.default
drwxr-xr-x 2 root root 30 Dec 15 17:15 php-fpm.d
- 子配置文件fpm改名
[root@centos7 etc]$cd php-fpm.d/
[root@centos7 php-fpm.d]$ll
total 20
-rw-r--r-- 1 root root 19602 Dec 15 17:15 www.conf.default
[root@centos7 php-fpm.d]$cp www.conf.default www.conf
- 修改fpm子配置文件
[root@centos7 php-fpm.d]$vim www.conf
# 修改為apache,以apache的身份來創建fastcgi的進程
user = apache
group = apache
# 開啟狀態頁
; Default Value: not set
pm.status_path = /status
# 開啟ping測試
; Default Value: not set
ping.path = /ping
- 準備啟動腳本
# 查找一下啟動腳本
[root@centos7 php74]$updatedb
[root@centos7 php74]$locate php-fpm
/app/php74/etc/php-fpm.conf
/app/php74/etc/php-fpm.conf.default
/app/php74/etc/php-fpm.d
/app/php74/etc/php-fpm.d/www.conf
/app/php74/etc/php-fpm.d/www.conf.default
/app/php74/php/man/man8/php-fpm.8
/app/php74/sbin/php-fpm
/data/php-7.4.0/sapi/fpm/init.d.php-fpm
/data/php-7.4.0/sapi/fpm/init.d.php-fpm.in
/data/php-7.4.0/sapi/fpm/php-fpm
/data/php-7.4.0/sapi/fpm/php-fpm.8
/data/php-7.4.0/sapi/fpm/php-fpm.8.in
/data/php-7.4.0/sapi/fpm/php-fpm.conf
/data/php-7.4.0/sapi/fpm/php-fpm.conf.in
/data/php-7.4.0/sapi/fpm/php-fpm.service
/data/php-7.4.0/sapi/fpm/php-fpm.service.in
# 拷貝過去作為啟動文件
[root@centos7 php74]$cp /data/php-7.4.0/sapi/fpm/php-fpm.service /usr/lib/system
d/system
# 重新載入服務
[root@centos7 php74]$systemctl daemon-reload
- 修改配置httpd 支持php-fpm
# 啟用代理
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so # 啟用
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so # 啟用
# 添加index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
# 添加這三行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
# 多虛擬主機和status啟用
<virtualhost *:80>
servername wordpress.atotaobao.org
documentroot /data/wordpress
<directory /data/wordpress>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1
CustomLog "logs/access_wordpress_log" common
</virtualhost>
<virtualhost *:80>
servername discuz.taotaobao.org
documentroot /data/discuz
<directory /data/discuz/>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
CustomLog "logs/access_discuz_log" common
</virtualhost>
- 創建部署軟體需要的目錄並建立一個測試php文件測試使用
[root@centos7 php74]$mkdir /data/wordpress
[root@centos7 php74]$mkdir /data/discuz
[root@centos7 php74]$vim /data/discuz/test.php
<?php
phpinfo();
?>
[root@centos7 php74]$cp /data/discuz/test.php /data/wordpress/
- windows更改host文件
- 添加這一行對應虛擬主機的功能變數名稱和虛擬機ip
- web界面測試
- web狀態頁測試
- web界面ping測試
- 準備opcache加速
- 查找opcache.so模塊路徑
[root@centos7 wordpress]$locate opcache.so
/app/php74/lib/php/extensions/no-debug-zts-20190902/opcache.so # 這個是opcache加速模塊
/data/php-7.4.0/ext/opcache/.libs/opcache.so
/data/php-7.4.0/modules/opcache.so
# 這三個文件是一樣的只是在不同目錄里作用不同
[root@centos7 wordpress]$ll /app/php74/lib/php/extensions/no-debug-zts-20190902/opcache.so
-rwxr-xr-x 1 root root 2491984 Dec 15 17:15 /app/php74/lib/php/extensions/no-debug-zts-20190902/opcache.so
[root@centos7 wordpress]$ll /data/php-7.4.0/ext/opcache/.libs/opcache.so
-rwxr-xr-x 1 root root 2491984 Dec 15 17:15 /data/php-7.4.0/ext/opcache/.libs/opcache.so
[root@centos7 wordpress]$ll /data/php-7.4.0/modules/opcache.so
-rwxr-xr-x 1 root root 2491984 Dec 15 17:15 /data/php-7.4.0/modules/opcache.so
- 準備加速插件文件(用來加速php處理動態資源)
[root@centos7 wordpress]$mkdir /etc/php.d/
[root@centos7 wordpress]$vim /etc/php.d/opcache.ini
[opcache]
zend_extension=opcache.so
#zend_extension=/app/php74/lib/php/extensions/no-debug-zts-20190902/opcache.so
opcache.enable=1 # 1 啟用 0 關閉
# 路徑以寫全也可以只寫模塊名都可以找到。
[root@centos7 wordpress]$systemctl restart php-fpm.service # 重啟服務
部署wordpress和discuz
- 解壓wordpress
[root@centos7 wordpress]$rm -rf /data/wordpress/ # wordpress 不用準備目錄裡面的所有文件都需要
[root@centos7 data]$ll
total 32464
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
drwxr-xr-x 2 root root 22 Dec 15 18:23 discuz
drwxr-sr-x 12 root 40 4096 Dec 15 16:14 httpd-2.4.41
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
drwxrwxr-x 19 root root 4096 Dec 15 17:11 php-7.4.0
-rw-r--r-- 1 root root 10232208 Dec 14 08:30 php-7.4.0.tar.xz
-rw-r--r-- 1 root root 12423575 Dec 12 14:18 wordpress-5.3-zh_CN.tar.gz
[root@centos7 data]$tar xvf wordpress-5.3-zh_CN.tar.gz # 解壓
[root@centos7 data]$ll
total 32468
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
drwxr-xr-x 2 root root 22 Dec 15 18:23 discuz
drwxr-sr-x 12 root 40 4096 Dec 15 16:14 httpd-2.4.41
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
drwxrwxr-x 19 root root 4096 Dec 15 17:11 php-7.4.0
-rw-r--r-- 1 root root 10232208 Dec 14 08:30 php-7.4.0.tar.xz
drwxr-xr-x 5 1006 1006 4096 Nov 14 09:00 wordpress
-rw-r--r-- 1 root root 12423575 Dec 12 14:18 wordpress-5.3-zh_CN.tar.gz
- 解壓discuz
[root@centos7 data]$unzip wordpress-5.3-zh_CN.tar.gz # 解壓沒有這個解壓軟體
-bash: unzip: command not found
[root@centos7 data]$yum install unzip # 下載解壓軟體
[root@centos7 ~]$unzip Discuz_X3.4_SC_UTF8【20191201】.zip -d /opt # 指定目錄安裝因為有的東西不能放在網站主頁目錄下
[root@centos7 ~]$rm -f /data/discuz/test.php # 刪除之前的測試文件
[root@centos7 ~]$mv /opt/upload/* /data/discuz/ # 把upload下的所有文件移動到discuz目錄下
- 修改許可權
[root@centos7 ~]$cd /data/
[root@centos7 data]$chown -R apache.apache discuz/ wordpress
web界面測試wordpress
web界面測試discuz
測試性能
- 找一臺虛擬機當客戶端,現在客戶端添加主機頭解析。
[root@centos ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.39.7 wordpress.taotaobao.org discuz.taotaobao.org # 添加這一行就行了
- 使用ab命令測試
# 如果沒有這個命令下載這個包
[root@centos ~]# yum install httpd-tools
[root@centos ~]# ab -c 10 -n 100 http://wordpress.taotaobao.org/ # 測試
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking wordpress.taotaobao.org (be patient)...^[[A..done
Server Software: Apache/2.4.41
Server Hostname: wordpress.taotaobao.org
Server Port: 80
Document Path: /
Document Length: 27338 bytes
# 第一次測試
Concurrency Level: 10
Time taken for tests: 1.936 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2759700 bytes
HTML transferred: 2733800 bytes
Requests per second: 51.66 [#/sec] (mean) # 主要看這行多測試幾遍取平均值
Time per request: 193.561 [ms] (mean)
Time per request: 19.356 [ms] (mean, across all concurrent requests)
Transfer rate: 1392.34 [Kbytes/sec] received
# 第二次測試
Concurrency Level: 10
Time taken for tests: 1.117 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2759700 bytes
HTML transferred: 2733800 bytes
Requests per second: 89.51 [#/sec] (mean)
Time per request: 111.724 [ms] (mean)
Time per request: 11.172 [ms] (mean, across all concurrent requests)
Transfer rate: 2412.21 [Kbytes/sec] received
# 第三次測試
Concurrency Level: 10
Time taken for tests: 0.840 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2759700 bytes
HTML transferred: 2733800 bytes
Requests per second: 119.09 [#/sec] (mean)
Time per request: 83.967 [ms] (mean)
Time per request: 8.397 [ms] (mean, across all concurrent requests)
Transfer rate: 3209.61 [Kbytes/sec] received
- 關閉opcache加速,測試。
# websrv服務端修改
[root@centos7 ~]$vim /etc/php.d/opcache.ini
opcache.enable=0 # 這一項修改為0
[root@centos7 ~]$systemctl restart php-fpm.service # 重啟服務或重新載入
# 測試第一次
Concurrency Level: 10
Time taken for tests: 3.421 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2759700 bytes
HTML transferred: 2733800 bytes
Requests per second: 29.23 [#/sec] (mean)
Time per request: 342.077 [ms] (mean)
Time per request: 34.208 [ms] (mean, across all concurrent requests)
Transfer rate: 787.84 [Kbytes/sec] received
# 測試第二次
Concurrency Level: 10
Time taken for tests: 2.786 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2759700 bytes
HTML transferred: 2733800 bytes
Requests per second: 35.89 [#/sec] (mean)
Time per request: 278.639 [ms] (mean)
Time per request: 27.864 [ms] (mean, across all concurrent requests)
Transfer rate: 967.21 [Kbytes/sec] received
# 測試第三次
Concurrency Level: 10
Time taken for tests: 2.806 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2759700 bytes
HTML transferred: 2733800 bytes
Requests per second: 35.64 [#/sec] (mean)
Time per request: 280.607 [ms] (mean)
Time per request: 28.061 [ms] (mean, across all concurrent requests)
Transfer rate: 960.43 [Kbytes/sec] received
結論:加速與不加速性能可能相差三倍