基於LNMP的discuz論壇的實現

基於LNMP的discuz論壇的實現

LNMP介紹:
LNMP的組成
 LNMP是指一組通常一起使用來運行動態網站或者服務器的自由軟件名稱首字母縮寫。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。
 [ LNMP簡介]
 - LNMP代表的就是:Linux系統下Nginx+MySQL+PHP這種網站服務器架構。
 - Linux是一類Unix計算機操作系統的統稱,是目前最流行的免費操作系統。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
 - Nginx是一個高性能的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP代理服務器。
 - Mysql是一個小型關係型數據庫管理系統。
 - PHP是一種在服務器端執行的嵌入HTML文檔的腳本語言。
這四種軟件均爲免費開源軟件,組合到一起,成爲一個免費、高效、擴展性強的網站服務系統。 
 [特點 ]
 - Nginx是一個小巧而高效的Linux下的Web服務器軟件,是由 Igor Sysoev 爲俄羅斯訪問量第二的 Rambler 站點開發的,已經在一些俄羅斯的大型網站上運行多年,相當的穩定。
 - Nginx性能穩定、功能豐富、運維簡單、處理靜態文件速度快且消耗系統資源極少。
[ 優點]
 - 作爲 Web 服務器:相比 Apache,Nginx 使用更少的資源,支持更多的併發連接,體現更高的效率。
 - 作爲負載均衡服務器:Nginx 既可以在內部直接支持Rails和PHP,也可以支持作爲 HTTP代理服務器對外進行服務。Nginx 用C編寫,不論是系統資源開銷還是CPU使用效率都比Perlbal要好的多。
 - 作爲郵件代理服務器:Nginx同時也是一個非常優秀的郵件代理服務器(最早開發這個產品的目的之一也是作爲郵件代理服務器),Last/fm 描述了成功並且美妙的使用經驗。
 - Nginx 安裝非常的簡單,配置文件非常簡潔(還能夠支持perl語法)。Nginx支持平滑加載新的配置,還能夠在不間斷服務的情況下進行軟件版本的升級。
  • 下面開始LNMP的安裝和部署

主機分配

服務 IP
LNMP 192.168.20.30
 1  rz
    2  yum -y install bison cmake ncurses-devel openssl-devel  perl-Data-Dumper
    3  tar -zxf mysql-5.6.46.tar.gz 
    4  cd mysql-5.6.46/
    5  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
    6  make -j8 && make install
  • 參數釋義:
--DCMAKE_INSTALL_PREFIX  安裝路徑
-DSYSCONFDIR 指定mysql配置文件目錄
-DDEFAULT_CHARSET 設置mysql默認字符集
-DDEFAULT_COLLATION 默認編碼格式
-DWITH_EXTRA_CHARSETS 指定mysql可用的其他字符集
    7  ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib
    8  ln -s /usr/local/mysql/bin/* /usr/local/bin/
    9  useradd -M -s /sbin/nologin mysql
   10  chown -R mysql:mysql /usr/local/mysql/
   11   cd support-files/
   12  cp my-default.cnf /etc/my.cnf
   13   cp mysql.server /etc/init.d/mysqld
   14  vim /etc/init.d/mysqld 
    46 basedir=/usr/local/mysql ##MySQL安裝路徑
    47 datadir=/usr/local/mysql/data ## 數據存放目錄
   15   chmod +x /etc/init.d/mysqld 
  • 初始化數據庫
16、/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

Installing MySQL system tables...2020-05-31 16:20:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-31 16:20:24 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-05-31 16:20:24 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.46) starting as process 21647 ...
2020-05-31 16:20:24 21647 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-05-31 16:20:24 21647 [Note] InnoDB: The InnoDB memory heap is disabled
2020-05-31 16:20:24 21647 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-05-31 16:20:24 21647 [Note] InnoDB: Memory barrier is not used
2020-05-31 16:20:24 21647 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-05-31 16:20:24 21647 [Note] InnoDB: Using CPU crc32 instructions
2020-05-31 16:20:24 21647 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-05-31 16:20:24 21647 [Note] InnoDB: Completed initialization of buffer pool
2020-05-31 16:20:24 21647 [Note] InnoDB: Highest supported file format is Barracuda.
2020-05-31 16:20:24 21647 [Note] InnoDB: 128 rollback segment(s) are active.
2020-05-31 16:20:24 21647 [Note] InnoDB: Waiting for purge to start
2020-05-31 16:20:24 21647 [Note] InnoDB: 5.6.46 started; log sequence number 1626027
2020-05-31 16:20:24 21647 [Note] RSA private key file not found: /usr/local/mysql/data//private_key.pem. Some authentication plugins will not work.
2020-05-31 16:20:24 21647 [Note] RSA public key file not found: /usr/local/mysql/data//public_key.pem. Some authentication plugins will not work.
2020-05-31 16:20:24 21647 [Note] Binlog end
2020-05-31 16:20:24 21647 [Note] InnoDB: FTS optimize thread exiting.
2020-05-31 16:20:24 21647 [Note] InnoDB: Starting shutdown...
2020-05-31 16:20:25 21647 [Note] InnoDB: Shutdown completed; log sequence number 1626037
OK

Filling help tables...2020-05-31 16:20:25 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-31 16:20:25 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-05-31 16:20:25 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.46) starting as process 21670 ...
2020-05-31 16:20:25 21670 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-05-31 16:20:25 21670 [Note] InnoDB: The InnoDB memory heap is disabled
2020-05-31 16:20:25 21670 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-05-31 16:20:25 21670 [Note] InnoDB: Memory barrier is not used
2020-05-31 16:20:25 21670 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-05-31 16:20:25 21670 [Note] InnoDB: Using CPU crc32 instructions
2020-05-31 16:20:25 21670 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-05-31 16:20:25 21670 [Note] InnoDB: Completed initialization of buffer pool
2020-05-31 16:20:25 21670 [Note] InnoDB: Highest supported file format is Barracuda.
2020-05-31 16:20:25 21670 [Note] InnoDB: 128 rollback segment(s) are active.
2020-05-31 16:20:25 21670 [Note] InnoDB: Waiting for purge to start
2020-05-31 16:20:25 21670 [Note] InnoDB: 5.6.46 started; log sequence number 1626037
2020-05-31 16:20:25 21670 [Note] RSA private key file not found: /usr/local/mysql/data//private_key.pem. Some authentication plugins will not work.
2020-05-31 16:20:25 21670 [Note] RSA public key file not found: /usr/local/mysql/data//public_key.pem. Some authentication plugins will not work.
2020-05-31 16:20:25 21670 [Note] Binlog end
2020-05-31 16:20:25 21670 [Note] InnoDB: FTS optimize thread exiting.
2020-05-31 16:20:25 21670 [Note] InnoDB: Starting shutdown...
2020-05-31 16:20:27 21670 [Note] InnoDB: Shutdown completed; log sequence number 1626047
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h lpj3 password 'new-password'

Alternatively you can run:

  /usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

  • 啓動並設置MySQL登錄密碼
[root@lpj3 support-files]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/lpj3.err'.
 SUCCESS! 
[root@lpj3 support-files]# netstat -anput | grep LISTEN | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      21832/mysqld        
[root@lpj3 support-files]#  mysqladmin -uroot password 123456
Warning: Using a password on the command line interface can be insecure.
[root@lpj3 support-files]#  mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.46 Source distribution

Copyright (c) 2000, 2019, 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> 
查看是否啓動
[root@lpj3 ~]# netstat -anput | grep LISTEN |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      21832/mysqld   

2、源碼安裝nginx

[root@lpj3 ~]# yum -y install gcc gcc-c++ openssl-devel zlib-devel pcre-devel
[root@lpj3 ~]# tar -zxf nginx-1.11.5.tar.gz 
[root@lpj3 ~]# cd nginx-1.11.5/
[root@lpj3 nginx-1.11.5]#  ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module 
[root@lpj3 nginx-1.11.5]#  ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin/
[root@lpj3 nginx-1.11.5]# nginx -v
 nginx version: nginx/1.11.5


  • 3 PHP的源碼安裝
./configure --prefix=/usr/local/php --with-gd --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-config-file-path=/usr/local/php --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib
[root@lpj3 php-7.2.0]# tar -zxf php-7.2.0.tar.gz 
[root@lpj3 php-7.2.0]# cd php-7.2.0/
[root@lpj3 php-7.2.0]# ./configure --prefix=/usr/local/php --with-gd --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-config-file-path=/usr/local/php --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib
[root@lpj3 php-7.2.0]# make -j8 && make install
    Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM defconfig:     /usr/local/php/etc/
Installing PHP FPM man page:      /usr/local/php/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/php/fpm/
Installing phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/root/nginx-1.11.5/php-7.2.0/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
[root@lpj3 php-7.2.0]# cp php.ini-development /usr/local/php/php.ini
[root@lpj3 php-7.2.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@lpj3 php-7.2.0]#chmod +x /etc/init.d/php-fpm
[root@lpj3 php-7.2.0]#cd /usr/local/php/etc
[root@lpj3 php-7.2.0]#cp php-fpm.conf.default php-fpm.conf
[root@lpj3 php-7.2.0]#cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@lpj3 php-7.2.0]#ln -s /usr/local/php/bin/* /usr/local/bin/
[root@lpj3 php-7.2.0]#ln -s /usr/local/php/sbin/* /usr/local/sbin/


4.1、修改php-fpm.conf配置

vim php-fpm.conf
 17 pid = run/php-fpm.pid #取消pid註釋
 69  process.max = 128 #取消註釋 fork出的子進程的最多數量
 100 events.mechanism = epoll #使用epoll模型  取消註釋
 編輯PHP測試頁面
 [root@lpj3 ~]# vim /usr/local/nginx/html/test1.php 
<?php
phpinfo();
?>
[root@lpj3 ~]# vim /usr/local/nginx/html/test2.php 
<?php
$con = new mysqli('192.168.20.128','root','123456');
if(!$con)
  die("connect error:".mysqli_connect_error());
else
  echo "connet mysql server ok!\n";
?>
啓動服務
[root@lpj3 ~]# /etc/init.d/php-fpm start
Starting php-fpm  done
查看是否啓動
[root@lpj3 ~]# netstat -anput | grep LISTEN |grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      60351/php-fpm: mast 

4.2、修改nginx配置文件

在原有localtion下面加如下內容  #index.php
 43         location / {
 44             root   html;
 45             index index.php index.html index.htm;
 46         }
 65-71行取消註釋  
 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 70             include        fastcgi_params;
 71         }
71行更改 fastcgi_params;爲 fastcgi.conf
 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 70             include        fastcgi.conf;
 71         }

 檢測nginx配置文件
 [root@lpj3 etc]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] getpwnam("nginx") failed  #原因是沒有創建nginx程序用戶導致
進行創建nginx程序用戶即可
[root@lpj3 etc]# useradd -s /sbin/nologin -M nginx

 [root@lpj3 etc]# 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@lpj3 etc]# nginx
查看是否啓動
[root@lpj3 ~]# netstat -anput | grep LISTEN |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      60151/nginx: master 

驗證
驗證http://192.168.20.30/test2.php
http://192.168.20.30/test1.php
即可
在這裏插入圖片描述
在這裏插入圖片描述
5、隱藏之前的測試頁面

把之前做的測試頁面進行隱藏
[root@lpj3 ~]# cd /usr/local/nginx/html/
[root@lpj3 html]# ls
50x.html  index.html  test1.php  test2.php
[root@lpj3 html]# mkdir backup
[root@lpj3 html]# mv *.* backup/
[root@lpj3 html]# ls
backup
6、部署DISCUZ
[root@lpj3 ~]# unzip ComsenzDiscuz-DiscuzX-master.zip 
[root@lpj3 ~]#  cp -r DiscuzX/upload/* /usr/local/nginx/html/
[root@lpj3 ~]# chmod -R 777 /usr/local/nginx/html/

訪問192.168.20.30進行安裝
在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述![在這裏插入圖片描述](https://img-blog.csdnimg.cn/20200531181836387.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA3NDUzMg==,size_16,color_FFFFFF,t_70

  • 安裝Discuz的異常處理
    在這裏插入圖片描述
如上圖 如果提醒已安裝 可以刪除安裝鎖 重新安裝
[root@localhost ~]# rm -rf /usr/local/httpd/htdocs/data/install.lock
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章