基于LNMP架构的个人博客系统部署

一、项目概述

本项目旨在通过两台服务器(Server-Web和Server-NFS-DNS)搭建一个基于LNMP(Linux、Nginx、MySQL、PHP)架构的个人博客系统。通过域名访问自建网站,同时实现资源文件的共享和DNS解析功能。

二、服务器配置

服务器信息

主机名 IP地址 系统 主要服务
Server-Web 192.168.65.131 Linux Web服务(Nginx、PHP)
Server-NFS-DNS 192.168.65.132 Linux NFS共享、DNS服务

三、基础配置

1. 配置静态IP地址

Server-Web(192.168.65.131)
复制代码
nmcli c modify ens160 ipv4.method manual ipv4.addresses '192.168.65.131/24' ipv4.gateway '192.168.65.2' ipv4.dns '114.114.114.114'
nmcli c reload
nmcli c up ens160
Server-NFS-DNS(192.168.65.132)
复制代码
nmcli c modify ens160 ipv4.method manual ipv4.addresses '192.168.65.132/24' ipv4.gateway '192.168.65.2' ipv4.dns '114.114.114.114'
nmcli c reload
nmcli c up ens160

2. 修改主机名及 /etc/hosts 映射

Server-Web(192.168.65.131)
复制代码
hostnamectl set-hostname Server-Web
echo "127.0.0.1 Server-Web" >> /etc/hosts
echo "192.168.65.131 Server-Web" >> /etc/hosts
echo "192.168.65.132 Server-NFS-DNS" >> /etc/hosts
Server-NFS-DNS(192.168.65.132)
复制代码
hostnamectl set-hostname Server-NFS-DNS
echo "127.0.0.1 Server-NFS-DNS" >> /etc/hosts
echo "192.168.65.131 Server-Web" >> /etc/hosts
echo "192.168.65.132 Server-NFS-DNS" >> /etc/hosts

3. 开启防火墙并配置

在两台服务器上执行以下命令:

复制代码
systemctl start firewalld
systemctl enable firewalld

4.永久关闭selinux

为了确保SELinux在重启后仍然保持关闭状态,需要修改SELinux的配置文件:

复制代码
vim /etc/selinux/config

将文件中的以下内容:

复制代码
SELINUX=enforcing

修改为:

复制代码
SELINUX=disabled

保存并退出文件后,重启服务器以应用更改:

复制代码
reboot

重启后查看selinux状态:

5. 时间同步

在两台服务器上执行以下命令:

复制代码
vim /etc/chrony.conf
# 修改为:
server ntp.aliyun.com iburst
systemctl restart chronyd
chronyc sources -v
timedatectl status

6. 配置免密SSH登录

Server-Web(192.168.65.131)
复制代码
ssh-keygen -t rsa
ssh-copy-id 192.168.65.132
ssh 192.168.65.132
exit
Server-NFS-DNS(192.168.65.132)
复制代码
ssh-keygen -t rsa
ssh-copy-id 192.168.65.131
ssh 192.168.65.131
exit

四、服务搭建

1. Server-Web端安装LNMP环境

在Server-Web(192.168.65.131)上执行以下命令:

复制代码
yum install nginx mariadb-server php* -y

2. Server-NFS-DNS端上传并解压WordPress

在Server-NFS-DNS(192.168.65.132)上执行以下命令:
复制代码
cd /
unzip latest-zh_CN.zip
cd  wordpress
ls 

3. Server-NFS-DNS端设置NFS共享

在Server-NFS-DNS(192.168.65.132)上执行以下命令:

复制代码
yum install rpcbind nfs-utils -y
vim /etc/exports
# 添加以下内容:
/wordpress 192.168.65.131(rw,sync,all_squash)
chmod -Rf 777 /wordpress
firewall-cmd --permanent --zone public --add-service=mountd
firewall-cmd --permanent --zone public --add-service=rpc-bind
firewall-cmd --permanent --zone public --add-service=nfs
firewall-cmd --reload
systemctl start rpcbind
systemctl start nfs-server

4. Server-Web端挂载NFS共享目录

在Server-Web(192.168.65.131)上执行以下命令:

复制代码
yum install rpcbind nfs-utils -y
showmount -e 192.168.65.132
mkdir /wp
mount -t nfs 192.168.65.132:/wordpress /wp
cd /wp
ls

5. Server-Web端配置Nginx

在Server-Web(192.168.65.131)上执行以下命令:

复制代码
firewall-cmd --permanent --zone public --add-service=http
firewall-cmd --reload
vim /etc/nginx/nginx.conf
# 修改root路径为:
root /wp;
systemctl restart nginx

6. Server-Web端配置WordPress

在Server-Web(192.168.65.131)上执行以下命令:

复制代码
cd /wp
cp wp-config-sample.php wp-config.php
vim wp-config.php
# 修改数据库配置:
define('DB_NAME', 'wordpress');
define('DB_USER', 'test1');
define('DB_PASSWORD', '123456');

7. Server-Web端启动数据库并创建用户

在Server-Web(192.168.65.131)上执行以下命令:

复制代码
systemctl start mariadb
mysql
# 在MySQL中执行以下命令:
create database wordpress;
create user 'test1'@'localhost' identified by '123456';
grant all on wordpress.* to 'test1'@'localhost';
exit

8. Server-Web端重启服务并通过ip访问测试

在Server-Web(192.168.65.131)上执行以下命令:

复制代码
systemctl restart mariadb
systemctl restart nginx

9. Server-NFS-DNS端配置DNS

在Server-NFS-DNS(192.168.65.132)上执行以下命令:

复制代码
yum install bind -y
firewall-cmd --permanent --zone public --add-service=dns
firewall-cmd --reload
systemctl start named
vim /etc/named.conf
# 修改listen-on和allow-query为any
listen-on port 53 { any; };
allow-query { any; };

修改区域配置文件
复制代码
vim /etc/named.rfc1912.zones
# 添加以下内容:
zone "hahaha.com" IN {
    type master;
    file "hahaha.com.zone";
    allow-update { none; };
};
新建区域数据文件
复制代码
cd /var/named
cp -a named.localhost hahaha.com.zone
vim hahaha.com.zone
# 添加以下内容:
$TTL 1D
@       IN SOA  hahaha.com. admin.hahaha.com. (
                0       ; serial
                1D      ; refresh
                1H      ; retry
                1W      ; expire
                3H )    ; minimum
        NS      ns.hahaha.com.
ns      IN      A       192.168.65.131
www     IN      A       192.168.65.131
bbs     IN      A       192.168.65.131
启动DNS服务
复制代码
systemctl restart named

五、测试

在Server-Web端中,将DNS服务器地址设置为192.168.65.132,然后通过浏览器访问 bbs.hahaha.com,完成WordPress的初始配置。

相关推荐
我是koten1 小时前
【运维杂谈】K8s遇到Terminating的名称空间删除不了怎么办?(解决方案亲测有效)
linux·运维·服务器·云原生·kubernetes·k8s·名称空间
Erishen8 小时前
Lume A2A 实战:让 Lume 应用接入分布式 Agent 协作网络
架构·开源·agent
斯维赤8 小时前
限流、熔断、降级,你真的分得清吗?
java·后端·架构
微步AICRM9 小时前
一物一码验真的并发链路设计:码段管理、四级关联与异常判定
后端·架构
国科安芯11 小时前
人在回路中的总线:商业空间站环境控制与生命保障系统CANFD网络的可靠性与功能安全
网络·嵌入式硬件·安全·架构·php·抗辐射
一条Go11 小时前
告警指纹:一次故障为什么只产生一条 FIRING 记录
后端·架构·github
王中阳Go11 小时前
你把重试加到 2 次那天,200 条里成功还是 181 条,你回看过吗?
人工智能·后端·架构
Zan11 小时前
Tauri 2 实战:为什么一个可靠的桌面应用,应该由 Rust Host 管理生命周期?
前端·架构·rust
神鹰手哥_起飞版11 小时前
我是怎么管理 Coding Agent 的:把任务交出去,也把结果验回来
人工智能·架构·产品经理
爱吃奥利奥_wen11 小时前
SQL Server 基础语法详解:从建库建表到约束与增删改查
服务器·数据库·oracle