基于LNMP架构的Discuz论坛搭建
软件包:链接:https://pan.baidu.com/s/1smqzl0usPj6rqsFUQCUAnA
提取码:tbvt
一键部署请看下篇文章:https://blog.51cto.com/14557673/2461483
Nginx
特点:稳定性、轻量级、高并发、低资源
优势:擅长处理静态网站(图片文字视频等文件)访问资源、Apache擅长动态(例如:账号注册的交互)
LNMP平台就是Linux、Ngnix、 MySQL、 PHP的组合架构,需要Linux服务器、MySQL数据库、PHP解析环境
LNMP平台中PHP中fpm模块负责进行动态资源的处理
PHP解析环境的安装
配置网页动静分离,解析PHP,有两种方法可以选择
●使用PHP的FPM模块
●将访问PHP页面的Web请求转交给Apache服务器去处理
较新版本的PHP已经自带FPM模块,用来对PHP解析实例进行管理、优化解析效率
●FastCGI将Http Server和动态脚本语言分离开,从而实现跨平台
●Nginx专门处理静态请求,转发动态请求;PHP_FPM专门解析PHP动态请求
单服务器的LNMP架构通常使用FPM的方式来解析PHP
下面是手工编译搭建LNMP架构和搭建discuz论坛过程:
[root@localhost ~]# ls tar/LNMP-C7/
Discuz_X3.4_SC_UTF8.zip php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz php-7.1.20.tar.bz2
ncurses-5.6.tar.gz php-7.1.20.tar.gz
nginx-1.12.2.tar.gz zend-loader-php5.6-linux-x86_64_update1.tar.gz
php-5.6.11.tar.bz2
================Nginx手工编译安装======================
1.安装相关环境包
yum install -y gcc gcc-c++ pcre* zlib-devel make
2.解压缩
tar zxf nginx-1.12.2.tar.gz -C /opt/
cd /opt/nginx-1.12.2/
3.指定用户,不创建家目录
useradd -M -s /sbin/nologin nginx
4.配置
./configure \
--prefix=/usr/local/nginx \ //指定目录
--user=nginx \ //创建用户与组
--group=nginx \
--with-http_stub_status_module //监控模块
5.编译安装
make && make install
6.创建软链接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
7.方便由service进行服务控制
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx //描述信息
After=network.target //描述服务类别
[Service]
Type=forking //后台运行形式
PIDFile=/usr/local/nginx/logs/nginx.pid //pid文件位置
ExecStart=/usr/local/nginx/sbin/nginx //启动服务
ExecReload=/usr/bin/kill -s HUP $MAINPID //根据pid重载配置
ExecStop=/usr/bin/kill -s QUIT $MAINPID //根据pid终止进程
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
netstat -ntap | grep 80
systemctl stop firewalld.service
setenforce 0
进行宿主机网页测试看是否成功
================mysql手工编译安装==============
mysql服务
1.环境安装
yum install -y ncurses ncurses-devel bison cmake
//ncurses字符终端包 bison函数库 cmake——用于编译
2.创建用户
useradd -s /sbin/nologin mysql
3.解压缩
cd ~/tar/LNMP-C7/
tar zxf mysql-boost-5.7.20.tar.gz -C /opt/
4.配置参数
cd /opt/mysql-5.7.20/
cmake \
-DCMKAE_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
5.编译安装
make
make install
6.设置属主和属组
cd /usr/local/
chown -R mysql.mysql mysql/
7.调整配置文件
vim /etc/my.cnf
[client] //客户端
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql] //客户端
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld] //服务器
user = mysql //用户
basedir = /usr/local/mysql //设置mysql的安装目录
datadir = /usr/local/mysql/data //设置mysql数据库的数据的存放目录
port = 3306 //设置3306端口
character_set_server=utf8 //中文字符集
pid-file = /usr/local/mysql/mysqld.pid //pid文件路径
socket = /usr/local/mysql/mysql.sock //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 //支持模块
chown mysql.mysql /etc/my.cnf
8.设置环境变量(脚本中可以设置为软链接)
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
9.初始化数据库
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /lib/systemd/system/
//将MySQL服务配置文件复制到/usr/lib/systemd/system/下便于使用systemctl管理
10.启动服务
systemctl start mysqld.service
11.设置密码为123456
mysqladmin -uroot -p password
输入(123456)
=============php手工编译安装====================
php:
cd ~/tar/LNMP-C7/
1.环境安装
yum install -y \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
2.解压缩
tar jxf php-7.1.10.tar.bz2 -C /opt/
cd /opt/php-7.1.10/
3.配置参数
./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
4.编译与安装
make && make install
5.php有三个配置文件 php.ini 核心配置文件 php-fpm.conf 进程服务配置文件 www.conf 扩展配置文件
cp php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
1170:mysqli.default_socket = /usr/local/mysql/mysql.sock
939:date.timezone = Asia/Shanghai
6.配置及优化FPM模块
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
17:pid = run/php-fpm.pid
cd php-fpm.d/
cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
ln -s /usr/local/php/bin/* /usr/local/bin/
7.让Nginx支持PHP功能
vim /usr/local/nginx/conf/nginx.conf
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;
}
systemctl restart nginx.service
cd /usr/local/nginx/html/
mv index.html index.php
vim index.php
cat index.php
phpinfo();
?>
===============创建数据库mydb=================
mysql -uroot -p
create database mydb;
grant all on mydb. to 'mydbuser'@'%' identified by '123123';
grant all on mydb. to 'mydbuser'@'localhost' identified by '123123';
flush privileges;
quit
============discuz论坛搭建与LANM类似============
discuz论坛
cd ~/tar/LNMP-C7/
unzip Discuz_X3.4_SC_UTF8.zip -d /opt/
cd /opt/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/mydb
cd /usr/local/nginx/html/mydb/
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
=================验证搭建是否成功=================
http://192.168.68.149/mydb/install/index.php
安装路径
http://192.168.68.149/mydb/index.php
论坛页面
http://192.168.68.149/mydb/admin.php
管理登录界面
http://192.168.68.149/mydb/admin.php?
管理员页面
最终的结果如下所示: