LNMP架构之搭建Discuz论坛

LNMP架构之搭建Discuz论坛

1、编译安装 Nginx

关闭防火墙

powershell 复制代码
systemctl stop firewalld  //关闭防火墙
setenforce 0

安装依赖环境

powershell 复制代码
yum -y install pcre-devel zlib-devel gcc gcc-c++ make

创建用户

powershell 复制代码
useradd -M -s /sbin/nologin nginx
//创建一个不能登录且不创建家目录的用户
powershell 复制代码
mkdir /data  
//在根目录下创建一个data目录
wget https://nginx.org/download/nginx-1.24.0.tar.gz
//去官网下载安装包
powershell 复制代码
tar xf nginx-1.24.0.tar.gz  //解压安装包

配置编译环境,选择编译模块

powershell 复制代码
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module

安装

powershell 复制代码
make -j2 && make install //编译为可执行文件并拷贝到系统中
powershell 复制代码
chown -R nginx.nginx /usr/local/nginx
//添加属主和属组

创建软连接,使其可以补全

powershell 复制代码
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

添加到系统服务(systemd启动)

powershell 复制代码
vim /lib/systemd/system/nginx.service
//进入配置文件 
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target

重新加载并启动程序

powershell 复制代码
systemctl daemon-reload 
systemctl start nginx
systemctl status nginx.service

浏览器查看

2、编译安装MySQL服务

将mysql安装包拖入到data目录下

解压安装包

powershell 复制代码
tar xf mysql-boost-5.7.20.tar.gz

安装依赖包

powershell 复制代码
yum install -y ncurses-devel autoconf cmake

配置编译环境和模块

powershell 复制代码
cd /data/mysql-5.7.20/
//进入到解压后的mysql文件

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
//配置编译选项

安装

powershell 复制代码
make -j2 && make install

创建用户并添加属主和属组

powershell 复制代码
useradd -s /sbin/nologin  mysql
chown -R mysql:mysql /usr/local/mysql/


编写配置文件

powershell 复制代码
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
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

给配置文件设置属主和属组,设置权限

powershell 复制代码
chown mysql:mysql /etc/my.cnf

设置路径环境变量加入到PATH中

powershell 复制代码
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile 
//加入PATH中,使其可以补全

echo 'export PATH' >> /etc/profile 
//声明这个变量为全局变量

数据库初始化

powershell 复制代码
cd /usr/local/mysql/

bin/mysqld \ 
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

添加mysqld系统服务

powershell 复制代码
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
//system启动

systemctl daemon-reload          //刷新识别     
systemctl start mysqld.service   //开启服务
ss -natp | grep 3306             //查看端口

创建mysql登录用户

powershell 复制代码
mysqladmin -u root -p password "abc123"

登录mysql

powershell 复制代码
mysql -u root -p

退出

powershell 复制代码
quit; //分号不能少

3、编译安装php

安装依赖环境

powershell 复制代码
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

解压文件

powershell 复制代码
cd /data   //切换到data目录下
tar xf php-7.1.10.tar.bz2 //解压文件

编译配置环境安装模块

powershell 复制代码
#编译环境检测 功能模块添加
./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

详解

./configure

--prefix=/usr/local/php7 \ 指定将 PHP 程序的安装路径

--with-mysql-sock=/usr/local/mysql/mysql.sock \ 指定mysql 数据库连接文件的存储路径

--with-config-file-path=/usr/local/php7 设置 PHP 的配置文件 php.ini 将要存放的位置

--with-mysqli \ 添加 MySQL 扩展支持 #mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定

--with-zlib \ 支持zlib功能,提供数据压缩

--with-curl \ 开启curl扩展功能,实现HTTP的Get下载和Post请求的方法

--with-gd \ 激活gd 库的支持

--with-jpeg-dir \ 激活jpeg 的支持

--with-png-dir \ 激活png 的支持

--with-freetype-dir

--with-openssl

--enable-mbstring \ 启用多字节字符串功能,以便支持中文等代码

--enable-xml \ 开启扩展性标记语言模块

--enable-session \ 会话

--enable-ftp \ 文本传输协议

--enable-pdo \ 函数库

--enable-tokenizer \ 令牌解释器

--enable-zip ZIP压缩格式

编译及安装

powershell 复制代码
make -j2 && make install

创建软连接

powershell 复制代码
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/

调整PHP配置文件

powershell 复制代码
cp /data/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini #模板
vim /usr/local/php/lib/php.ini #修改主配置文件


调整进程服务配置文件

powershell 复制代码
cd /usr/local/php/etc/
cp  php-fpm.conf.default php-fpm.conf
vim php-fpm.conf

调整扩展配置文件

powershell 复制代码
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf

启动php-fpm

powershell 复制代码
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini

netstat -anpt | grep 9000
powershell 复制代码
cd /opt/php-7.1.10/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service

systemctl restart php-fpm.service

配置 Nginx 支持 PHP 解析

powershell 复制代码
vim /usr/local/nginx/conf/nginx.conf
powershell 复制代码
systemctl restart nginx.service

验证PHP 测试页

powershell 复制代码
//创建网页文件
vim /usr/local/nginx/html/index.php

<?php
phpinfo();
?>

//重启nginx服务
systemctl restart nginx

//在网页测试
http://192.168.190.200/index.php



4、安装论坛

以 root 用户身份登录到 MySQL 数据库,进行配置

powershell 复制代码
mysql -u root -p 
//以 root 用户身份登录到 MySQL 数据库
powershell 复制代码
mysql> CREATE DATABASE bbs;  //创建一个数据库

mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';  //把bbs数据库里面所有表的权限授予给bbsuser,并设置密码

mysql>flush privileges; //刷新数据库

解压Discuz源码包并配置

powershell 复制代码
unzip Discuz_X3.4_SC_UTF8.zip //解压

cd /opt/dir_SC_UTF8/

//拷贝文件到数据
cp -r upload/ /usr/local/nginx/html/bbs/


powershell 复制代码
//改权限 改属组属主
cd /usr/local/nginx/html/bbs/

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/

浏览器访问

powershell 复制代码
http://192.168.190.200/bbs/install/index.php
相关推荐
hai405875 分钟前
Spring Boot中的响应与分层解耦架构
spring boot·后端·架构
伯牙碎琴3 小时前
十一、SOA(SOA的具体设计模式)
架构
Karoku06611 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
Lill_bin13 小时前
深入理解ElasticSearch集群:架构、高可用性与数据一致性
大数据·分布式·elasticsearch·搜索引擎·zookeeper·架构·全文检索
zyhJhon13 小时前
软考架构-面向服务的架构风格
架构
nbsaas-boot14 小时前
微服务之间的安全通信
安全·微服务·架构
数据运营新视界17 小时前
你知道企业架构中核心的4大架构联系和不同吗?
大数据·架构
Xinan_____18 小时前
Linux——高流量 高并发(访问场景) 高可用(架构要求)
linux·运维·架构
杨诚实18 小时前
20240912软考架构-------软考161-165答案解析
数据库·架构
achirandliu20 小时前
汽车电子电气架构从12V提升至48V,带来那些好处? 包括那些改变?
架构·汽车·汽车电子电气架构·从12v升到48v