项目实践--搭建论坛
1. 项目架构
- 使用LNMP环境+Discuz论坛源程序
- LNMP=Linux+Nginx+mariadb+PHP
1.1 Nginx
最初于2004年10月4日由俄罗斯知名门户站点开发的
Nginx是一款轻量级的网站服务软件,因其稳定性和丰富的功能而深受信赖
特点:
- 低消耗系统资源
- 占用内存少
- 并发能力强
是目前主流网站使用的的http服务程序
1.2 Mariadb
- 是一款数据库软件
- 由开源社区维护,MySQL的分支,几乎完全兼容MySQL
- 两者性能基本一致,操作十分相同
1.3 PHP
- 超文本预处理器(PHP)是一种通用的开源脚本语言
- 开源,免费,快捷,跨平台强,效率高等特性
- 是目前Web开发领域最常用的语言之一
- Discuz默认使用PHP编写
1.4 Discuz
- 是一套通用的社区论坛软件系统
- 是全球成熟度,覆盖率最大的论坛软件系统之一
- 2010年8月23日被腾讯收购
- 网址:www.discuz.vip/
2. 项目准备
2.1 安装RHEL8.5系统并配置Xshell及Xftp
下载
先下载vmware workstation pro软件,下载地址:www.vmware.com/products/wo...
下载完成后,退出所有的安全软件,并安装该软件。安装完成后需要激活,激活完成后打开该软件。
创建虚拟机实例
第一步:文件菜单->新建虚拟机->典型->下一步
第二步:稍后安装操作系统
第三步:选择操作系统类型,若找不到类型名,可以以内核(kernel)版本号为准
第四步:命名虚拟机
第五步:设置磁盘空间,默认20G,动态空间申请,设置为单个文件
第六步:自定义硬件,设置硬件参数
第七步:设置自定义硬件
- 内存:推荐2GB
- 处理器:1颗、2核心
- 新CD/DVD:适应ISO映像文件,点击浏览按钮,选择之前下载好的RHEL9.3.iso镜像文件
- 网络适配器:选择NAT模式
- 显示器:去掉"加速3D图形"的对钩
- 最终:
选择关闭、完成
RHEL9.3操作系统的安装部署
使用鼠标点击黑色界面进入RHEL8.5系统,通过ctrl+alt可以释放鼠标焦点回到Windows
通过键盘方向键选择第一项Install Red Hat Enterprise Linux9.3选项进行安装系统
选择语言:中文或英文
安装信息摘要设置
- 安装目的地:显示安装位置,一般为硬盘,并进行分区:
- /boot:系统启动分区,容量400m
- /boot/efi:容量500m
- swap:交换分区,4g
- /:根分区,期望容量省略,表示将剩余空间全部分配
- 方法:点击下图的加号,设置挂载点及期望容量(重复多次),点击完成,点击接收更改
- KDUMP:内核崩溃转储保护机制,学习时关闭,生产中打开
- root账户密码设置:注意第二对钩必须打上
- 创建用户:创建一个普通账户,设置密码
直接点击Begin Installation(开始安装)
安装成功后点击Reboot(重启)
根据提示进行设置,并设置普通用户的用户名及密码
以下为安装示例图:
安装远程连接linux的软件
- 安装xshell:打开链接www.xshell.com/zh/free-for...
配置xshell进行远程登录
- RHEL8.5终端中查看本机IP:ip address
- xshell中选择文件菜单->新建->打开设置向导
- 名称:自定
- 主机:RHEL8.5的IP地址
- 点击连接输入root(记住用户名打钩)及密码(记住密码打钩)
2.2 配置系统+优化操作
2.2.1 关闭SELinux及安全软件
bash
# 临时关闭SELinux
[root@localhost ~]# setenforce 0
# 在配置文件中修改SELinux的状态,使其永久关闭
[root@Cyber4K ~]# vim /etc/selinux/config
# 关闭防火墙
root@localhost ~]# systemctl stop firewalld
# 取消开机启动
[root@localhost ~]# systemctl disable firewalld
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
2.2.2 修改主机名
bash
# 修改主机名
[root@localhost ~]# hostnamectl set-hostname Cyber4K
# 重启使新主机名生效
[root@localhost ~]# reboot
# 如下
[root@Cyber4K ~]#
2.2.3 配置yum源
使用xftp上传CentOS-8-Stream.repo的yum配置文件到/etc/yum.repos.d(需要yum配置文件私我呦)
bash
# 删除红帽自带repo,为了删除彻底删除整个目录
[root@Cyber4K ~]# rm -rf /etc/yum.repos.d/
# 并重新创建一个新目录
[root@Cyber4K ~]# mkdir /etc/yum.repos.d
# 利用xftp上传,将CentOS-8-Stream.repo放入/etc/yum.repos.d/
# 删除原先缓存
[root@Cyber4K ~]# yum clean all
# 制作新的缓存
[root@Cyber4K ~]# yum makecache
2.2.4 测试网络连通性
bash
# 测试网络连通性
[root@Cyber4K ~]# ping -c2 www.qq.com
PING ins-r23tsuuf.ias.tencent-cloud.net (101.91.22.57) 56(84) 比特的数据。
64 比特,来自 101.91.22.57 (101.91.22.57): icmp_seq=1 ttl=128 时间=37.1 毫秒
64 比特,来自 101.91.22.57 (101.91.22.57): icmp_seq=2 ttl=128 时间=37.8 毫秒
--- ins-r23tsuuf.ias.tencent-cloud.net ping 统计 ---
已发送 2 个包, 已接收 2 个包, 0% packet loss, time 1012ms
rtt min/avg/max/mdev = 37.101/37.446/37.791/0.345 ms
2.2.5 制作快照
为你的虚拟机创建快照。
3. 下载所需软件
3.1 下载LNMP一键安装包
- 网址:lnmp.org/download.ht...
- 使用xftp将安装包上传到RHEL9.3系统的根目录中
3.2 下载Discuz安装包
- 使用windows迅雷下载Discuz!x3.5安装包
- 地址:gitee.com/Discuz/Disc...
- 在windows系统解压缩后备用
4. 部署项目
4.1 部署LNMP环境
- 解压缩
bash
root@Cyber4K /]# ls
afs boot etc lib lnmp2.1-full.tar mnt proc run srv tmp var
bin dev home lib64 media opt root sbin sys usr
[root@Cyber4K /]# tar -xvf lnmp2.1-full.tar
- 安装(以下为示例及讲解,由于我的提前部署完毕,与下面命令不同)
- 进入漫长等待!!!
bash
[root@server /]# cd lnmp1.9-full/
[root@server lnmp1.9-full]# ./install.sh # 执行安装脚本
+------------------------------------------------------------------------+
| LNMP V1.9 for RHEL Linux Server, Written by Licess |
+------------------------------------------------------------------------+
| A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux |
+------------------------------------------------------------------------+
| For more information please visit https://lnmp.org |
+------------------------------------------------------------------------+
You have 11 options for your DataBase install.
1: Install MySQL 5.1.73
2: Install MySQL 5.5.62 (Default)
3: Install MySQL 5.6.51
4: Install MySQL 5.7.38
5: Install MySQL 8.0.30
6: Install MariaDB 5.5.68
7: Install MariaDB 10.3.35
8: Install MariaDB 10.4.25
9: Install MariaDB 10.5.16
10: Install MariaDB 10.6.8
0: DO NOT Install MySQL/MariaDB
Enter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 0): # 数据库安装版本:回车默认
===========================
Please setup root password of MySQL.
Please enter: 123456 # 设置数据库的密码
===========================
Do you want to enable or disable the InnoDB Storage Engine?
Default enable,Enter your choice [Y/n]: y # 是否启用mysql innodb引擎,输入y
You will enable the InnoDB Storage Engine
===========================
You have 9 options for your PHP install.
1: Install PHP 5.2.17
2: Install PHP 5.3.29
3: Install PHP 5.4.45
4: Install PHP 5.5.38
5: Install PHP 5.6.40 (Default)
6: Install PHP 7.0.33
7: Install PHP 7.1.33
8: Install PHP 7.2.34
9: Install PHP 7.3.33
10: Install PHP 7.4.30
11: Install PHP 8.0.20
12: Install PHP 8.1.7
Enter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12): # 选择php版本,默认回车
===========================
You have 3 options for your Memory Allocator install.
1: Don't install Memory Allocator. (Default)
2: Install Jemalloc
3: Install TCMalloc
Enter your choice (1, 2 or 3): # 选择是否安装内存优化,不安装,回车
Press any key to install...or Press Ctrl+c to cancel # 按任意键开始安装
# 等待......
Checking ...
Nginx: OK
MySQL: OK
PHP: OK
PHP-FPM: OK
Clean Web Server src directory...
+------------------------------------------------------------------------+
| LNMP V1.9 for RHEL Linux Server, Written by Licess |
+------------------------------------------------------------------------+
| For more information please visit https://lnmp.org |
+------------------------------------------------------------------------+
| lnmp status manage: lnmp {start|stop|reload|restart|kill|status} |
+------------------------------------------------------------------------+
| phpMyAdmin: http://IP/phpmyadmin/ |
| phpinfo: http://IP/phpinfo.php |
| Prober: http://IP/p.php |
+------------------------------------------------------------------------+
| Add VirtualHost: lnmp vhost add |
+------------------------------------------------------------------------+
| Default directory: /home/wwwroot/default |
+------------------------------------------------------------------------+
| MySQL/MariaDB root password: 123456 |
+------------------------------------------------------------------------+
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
nginx (pid 350414) is running...
php-fpm is runing!
SUCCESS! MySQL running (351009)
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6011 0.0.0.0:*
LISTEN 0 50 0.0.0.0:3306 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 128 [::1]:6010 [::]:*
LISTEN 0 128 [::1]:6011 [::]:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
Install lnmp takes 24 minutes.
Install lnmp V1.9 completed! enjoy it.
# 成功
- 安装成功后:
4.2 设置论坛安装文件
- 使用xftp将目录中的upload目录上传到nginx的启动目录/home/wwwroot/default内
- 如图:
设置nginx
bash
[root@Cyber4K ~]# cd /home/wwwroot/default/
[root@Cyber4K default]# ls
index.html lnmp.gif ocp.php phpinfo.php phpmyadmin p.php upload
[root@Cyber4K default]# chmod -Rf 777 upload
[root@Cyber4K default]# chown www:www -R /home/wwwroot/default/upload/
[root@Cyber4K default]# vim /usr/local/nginx/conf/nginx.conf
[root@Cyber4K default]# cd /usr/local/nginx/sbin/
[root@Cyber4K sbin]# ./nginx -s reload
[root@Cyber4K sbin]#
虚拟机Linux不关机,可以一直使用IP地址进行访问。
自此论坛搭建完成,想进行商业化,可以进行域名的备案,在此不做研究。