一、安裝Nginx
1.1 Nginx介紹
- 是一款高效能,輕量級的web服務軟體
- 穩定性高
- 系統資源消耗低
- 對HTTP併發連線的處理能力高(活到現在的原因)
單台伺服器可支援30000~50000個併發請求
1.2 準備工作
- 準備安裝包 nginx-1.12.2.tar.gz
- 安裝工具和環境包
[root@localhost bbs]
[root@localhost bbs]
yum -y install \
pcre-devel \
zlib-devel \
gcc \
gcc-c++ \
pcre \
make
1.3 原始碼編譯及安裝
[root@localhost ~]
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
[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]
1.4 優化執行路徑
[root@localhost ~]
1.5 製作管理指令碼
[root@localhost ~]
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 -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28961/nginx: master
二、部署Mysql數據庫
2.1 準備工作
- 準備好mysql壓縮包 mysql-boost-5.7.20.tar
- 準備環境和工具包
[root@localhost ~]
[root@localhost ~]
2.2 Mysql原始碼編譯及安裝
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
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]
3.3 調整安裝路徑檔案的許可權
[root@localhost ~]
3.4 調整組態檔
[root@localhost mysql-5.7.20]
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysq/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
3.5 設定環境變數
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
3.6 初始化數據庫
[root@localhost ~]
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
3.7 開啓數據庫
[root@localhost ~]
[root@localhost ~]
[root@localhost mysql]
tcp6 0 0 :::3306 :::* LISTEN 47949/mysqld
3.8 爲數據庫設定管理員密碼
[root@localhost mysql]
Enter password:
New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
三、 安裝PHP
3.1 準備工作
- 準備PHP 安裝包 php-7.1.10.tar
- 準備環境及工具
[root@localhost ~]
3.2 編譯安裝
[root@localhost ~]
[root@localhost ~]
[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]
3.3 修改組態檔
[root@localhost php-7.1.10]
[root@localhost php-7.1.10]
mysqli.default_socket=/usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
3.4 設定及優化FPM 模組
[root@localhost php-7.1.10]
[root@localhost etc]
[root@localhost etc]
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
pid = run/php-fpm.pid
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 18694/php-fpm: mast
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
4
3.5 讓nginx支援PHP 功能
[root@localhost php-fpm.d]
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 html]
[root@localhost html]
[root@localhost html]
<?php
phpinfo();
?>
[root@localhost html]
[root@localhost html]
[root@localhost html]
3.6 測試
- 登錄http://IP地址/index.php
四、測試數據庫能否連線
4.1 在數據庫中建立數據庫使用者
[root@localhost ~]
Enter password:
mysql> CREATE DATABASE bbs;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 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)
4.2 修改頁面檔案測試
[root@localhost mysql]
<?php
$link=mysqli_connect('192.168.233.100','bbsuser','admin123');
if($link) echo"<h1>Success!!</h1>";
else echo "Fail!!"
?>
- 連線成功
五、安裝論壇
5.1 準備工作
- 準備 Discuz_X3.4_SC_UTF8.zip 壓縮包
5.2 修改組態檔
[root@localhost ~]
[root@localhost ~]
[[root@localhost dir_SC_UTF8]
[root@localhost dir_SC_UTF8]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
5.3 安裝論壇
- 進入 http://192.168.233.200/bbs/install/index.php
- 點選我同意 ,發現環境全部符合要求
- 選擇全部安裝
- 建立 連線數據庫
- 安裝成功