基於lnmp架構搭建論壇

                                                                 基於lnmp架構搭建論壇

LNMP代表的就是:Linux系統下Nginx+MySQL+PHP這種網站服務器架構。

實驗環境:

系統環境: RHEL6 x86-64 selinux and iptables disabled

一、Mysql 安裝

1.安裝軟件包依賴性:

[root@server1 ~]# yum install -y gcc gcc-c++ ncurses-devel bison openssl-devel zlib-devel

[root@server1 ~]# yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm      用cmake[有進度條]


2.編譯安裝數據庫
[root@server1 ~]# tar zxf mysql-boost-5.7.11.tar.gz
[root@server1 ~]# cd mysql-5.7.11/

[root@server1 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \  #安裝目錄

> -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \ #數據庫存放目錄

> -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \ #Unix socket 文件路徑

> -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #安裝 innodb 存儲引擎

> -DWITH_MYISAM_STORAGE_ENGINE=1 \ #安裝 myisam 存儲引擎

> -DDEFAULT_CHARSET=utf8 \  #使用 utf8 字符

> -DDEFAULT_COLLATION=utf8_general_ci \  #校驗字符

> -DEXTRA_CHARSETS=all \  #安裝所有擴展字符集

> -DWITH_BOOST=/root/mysql-5.7.11/boost/boost_1_59_0/  


[root@server1 mysql-5.7.11]# make && make install


注意:

重新編譯時,需要清除舊的對象文件和緩存信息
make clean
rm -f CmakeCache.txt


3.完成mysql初始化 [創建所需的用戶及組]

[root@server1 mysql]# groupadd -g 27 mysql

[root@server1 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/ mysql

[root@server1 local]# usermod -s /sbin/nologin mysql
[root@server1 mysql]# chown mysql.mysql . -R

Screenshot from 2018-07-10 18-28-47.png


4.解析mysql/bin的執行腳本


[root@server1 ~]# vim .bash_profile
Screenshot from 2018-07-10 18-32-44.png


[root@server1 ~]# source .bash_profile 


Screenshot from 2018-07-10 18-36-50.png


[root@server1 mysql]# chown root . -R


Screenshot from 2018-07-10 18-36-03.png


5.修改配置文件中的數據庫存放目錄socket 文件路徑與編譯時一致


[root@server1 support-files]# vim /etc/my.cnf

Screenshot from 2018-07-10 19-26-43.png

6.拷貝執行腳本到本地執行目錄下

[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld

Screenshot from 2018-07-10 19-30-51.png


7.完成初始化 指定用戶 並創建數據庫


[root@server1 mysql]# mysqld --initialize --user=mysql

Screenshot from 2018-07-10 19-41-43.png


[root@server1 mysql]# chown mysql data -R   更改數據目錄所有人爲mysql


Screenshot from 2018-07-10 19-42-21.png


開啓數據庫 並修改密碼

[root@server1 mysql]# /etc/init.d/mysqld start

Screenshot from 2018-07-10 19-44-53.png


[root@server1 mysql]# mysql_secure_installation    #按提示完成 mysql 安全設置,生產環境推薦使用



二、Php 安裝

1.解決安裝所需依賴性

下載包

php-5.6.20.tar.bz2

安裝依賴性

[root@server1 ~]# yum install libjpeg-turbo-devel-1.2.1-1.el6.x86_64
[root@server1 php-5.6.20]# yum install -y libxml2-devel
[root@server1 php-5.6.20]# yum install -y openssl-devel
[root@server1 php-5.6.20]# yum install -y curl-devel
[root@server1 ~]# yum install -y gd-devel-2.0.35-11.el6.x86_64.rpm
[root@server1 ~]# yum install -y gmp-devel
[root@server1 ~]# yum install libmcrypt-devel-2.5.8-9.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm -y
[root@server1 ~]# yum install -y net-snmp-devel
[root@server1 ~]# yum install re2c-0.13.5-1.el6.x86_64.rpm -y

2.編譯安裝

[root@server1 ~]# tar jxf php-5.6.20.tar.bz2   解包

[root@server1 php-5.6.20]# ./configure --help  尋找幫助
--with-openssl   指定驅動 加密

--with-gd   圖

--with-zlib       php網頁壓縮(防盜鏈)

--with-pear     功能模塊的組件(安裝)

執行

[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl  --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash


輸出的信息

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+
Thank you for using PHP.


[root@server1 php-5.6.20]# make && make install


3.配置php解析文件/配置php-fpm配置文件

[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default
[root@server1 etc]# pwd
/usr/local/lnmp/php/etc

[root@server1 php-5.6.20]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini   
[root@server1 fpm]# pwd
/root/php-5.6.20/sapi/fpm
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm       啓動腳本
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm         加執行權限


4.修改php配置文件 [pid][timezone]


[root@server1 etc]# vim php-fpm.conf


[root@server1 etc]# vim php.ini

Screenshot from 2018-07-10 21-36-43.pngScreenshot from 2018-07-10 21-38-16.png

添加php配置文件中指定的用戶 並啓動php

[root@server1 etc]# useradd -u 800 -M -d /usr/local/lnmp/nginx nginx
[root@server1 etc]# /etc/init.d/php-fpm start
Screenshot from 2018-07-10 21-41-02.png


三、Nginx 安裝

1.安裝依賴性並編譯

[root@server1 ~]# tar zxf nginx-1.10.1.tar.gz
[root@server1 ~]# cd nginx-1.10.1
[root@server1 core]# pwd
/root/nginx-1.10.1/src/core
[root@server1 core]# vim nginx.h
Screenshot from 2018-07-10 21-47-58.png

#define NGINX_VER "nginx" (修改此行, 去掉後面的 “ NGINX_VERSION”,爲了安全,這樣編譯後外界無法獲取程序的版本號)

[root@server1 cc]# pwd
/root/nginx-1.10.1/auto/cc
[root@server1 cc]# vim gcc


#CFLAGS=”$CFLAGS -g” (註釋掉這行,去掉 debug 模式編譯,編譯以後程序只有幾百 k)


安裝依賴

[root@server1 nginx-1.10.1]# yum install -y pcre-devel

編譯

./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-threads --user=nginx --group=nginx

安裝

[root@server1 nginx-1.10.1]# make && make install

做軟鏈接

[root@server1 sbin]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/

[root@server1 sbin]# nginx -t      檢測語法

[root@server1 ~]# nginx     開啓
Screenshot from 2018-07-10 22-00-38.png


四、解決nginx和php的依賴關係

編輯nginx配置文件 修改tcp zip php

[root@server1 conf]# pwd
/usr/local/lnmp/nginx/conf
[root@server1 conf]# vim nginx.conf

Screenshot from 2018-07-10 22-06-44.png

Screenshot from 2018-07-10 22-07-20.png

Screenshot from 2018-07-10 22-09-16.png

[root@server1 conf]# nginx -t     檢測語法
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 conf]# nginx -s reload    重新加載


創建nginx訪問php主頁的頁面


[root@server1 html]# pwd
/usr/local/lnmp/nginx/html
[root@server1 html]# vim index.php
[root@server1 html]# cat index.php
<?php
phpinfo()
?>

設置index.php爲訪問ip時默認訪問的網頁

[root@server1 conf]# vim nginx.conf

Screenshot from 2018-07-10 22-16-26.png


[root@server1 conf]# nginx -t
[root@server1 conf]# nginx -s reload

瀏覽器訪問

Screenshot from 2018-07-10 22-17-34.png


五、解決php和mysql的依賴關係

[root@server1 etc]# pwd
/usr/local/lnmp/php/etc
[root@server1 etc]# vim php.ini

Screenshot from 2018-07-10 22-35-03.png

Screenshot from 2018-07-10 22-37-03.png

[root@server1 etc]# /etc/init.d/php-fpm reload           平滑加載


六、搭建基於lnmp的論壇


下載 Discuz_X3.2_SC_UTF8.zip

[root@server1 ~]# yum install -y unzip
[root@server1 ~]# unzip Discuz_X3.2_SC_UTF8.zip   解壓

修改解壓出的目錄名字及位置

[root@server1 ~]# mv upload/ /bbs
Screenshot from 2018-07-10 22-50-56.png


ngnx設置虛擬主機 實現基於域名訪問nginx

[root@server1 conf]# vim nginx.conf
Screenshot from 2018-07-10 23-16-53.png

[root@server1 conf]# nginx -s reload

注意:瀏覽器訪問主機做好解析,/etc/hosts


訪問:bbs.cara.org/install

Screenshot from 2018-07-10 23-18-23.png


Screenshot from 2018-07-10 23-19-09.png


根據提示 改權限

[root@server1 bbs]# chmod 777 config/ data
[root@server1 bbs]# chmod 777 config/ data -R

[root@server1 bbs]# chmod 777 uc_client/ uc_server/ -R
[root@server1 mysql]# chmod 755 data



[root@server1 ~]# /etc/init.d/mysqld restart

Screenshot from 2018-07-10 23-30-25.png


Screenshot from 2018-07-10 23-32-06.png


如下,已經完成!


Screenshot from 2018-07-10 23-35-47.png


查看數據庫:

Screenshot from 2018-07-10 23-59-16.png


七、memcache 基於php的cache


1.安裝memcache

修改環境變量

[root@server1 bin]# vim ~/.bash_profile

Screenshot from 2018-07-11 21-29-32.png

[root@server1 bin]# source ~/.bash_profile    


[root@server1 ~]# tar zxf memcache-2.2.5.tgz

Screenshot from 2018-07-11 21-33-37.png


編譯安裝memcache

[root@server1 memcache-2.2.5]# ./configure --prefix=/usr/local/lnmp/php/memcache
[root@server1 memcache-2.2.5]# make && make install

Screenshot from 2018-07-11 21-36-55.png


[root@server1 etc]# pwd
/usr/local/lnmp/php/etc
[root@server1 etc]# vim php.ini

Screenshot from 2018-07-11 21-40-06.png

[root@server1 etc]# /etc/init.d/php-fpm reload     重新加載


拷貝文件

[root@server1 memcache-2.2.5]# cp example.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-2.2.5]# cp memcache.php /usr/local/lnmp/nginx/html/


2.搭建一個memcache服務器


[root@server2 ~]# yum install -y memcached
[root@server2 ~]# /etc/init.d/memcached start      開啓服務

[root@server2 ~]# yum install -y telnet   

telnet命令用於登錄遠程主機,對遠程主機進行管理。telnet採用明文傳送報文,安全性不好;

Screenshot from 2018-07-11 21-45-44.png



[root@server1 html]# vim example.php


Screenshot from 2018-07-11 21-53-53.png

[root@server1 html]# vim memcache.php

Screenshot from 2018-07-11 21-53-40.png

(client -> nginx -> php-fpm -> php -> memcached -> mysql)

Screenshot from 2018-07-11 21-59-17.png



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