222第一阶段考核-实验-模拟题

第一阶段考核-实验-模拟题

考核背景

在内容消费与创作需求爆发的当下,博客平台已成为个人知识分享、品牌内容沉淀与垂直领域社群构建的核心载体。随着全球博客创作者规模预计 2025 年突破 5 亿人,个人博主与中小型内容团队亟需通过轻量化博客平台打破流量获取的渠道限制与技术开发的门槛壁垒。

LNMP(Linux+Nginx+MySQL+PHP)架构凭借其开源免费、稳定高效的特性,成为构建轻量化博客平台的理想技术方案。该技术组合不仅能有效降低 70% 以上的初期部署成本,其完善的生态系统还支持快速集成文章编辑、评论互动、内容检索等核心功能,完美契合日均万级访问量的博客运营需求。

考核内容

  1. 博客平台部署
  2. 博客平台维护

实验环境

实验拓扑

![c7b5e644e816be2780562622b7d21c81](./第一阶段考核-实验-模拟题.assets/c7b5e644e816be2780562622b7d21c81-1776994830458-1.png)

主机清单

主机名 IP 地址 角色
ha1.linux.com 10.1.8.41 负载均衡器和高可用服务器-1
ha2.linux.com 10.1.8.42 负载均衡器和高可用服务器-2
proxy1.linux.com 10.1.8.43 代理服务器-1
proxy2.linux.com 10.1.8.44 代理服务器-2
company1.linux.com 10.1.8.45 公司站点服务器-1
company2.linux.com 10.1.8.46 公司站点服务器-2
blog1.linux.com 10.1.8.47 博客站点服务器-1
blog2.linux.com 10.1.8.48 博客站点服务器-2
db1.linux.com 10.1.8.49 数据库服务器-1
db2.linux.com 10.1.8.50 数据库服务器-2
storage.linux.com 10.1.8.51 存储服务器(NFS、iSCSI、yum仓库)
backup.linux.com 10.1.8.52 备份服务器(备份博客和数据库数据)
network.linux.com 10.1.8.53 网络服务器(DHCP、DNS)
client.linux.com 10.1.8.54 测试客户端
虚拟主机 IP 地址 角色
yum.linux.com 10.1.8.51 yum 仓库
dns.linux.com 10.1.8.53 DNS 服务器
www.linux.com 10.1.8.100 站点服务器
db.linux.com 10.1.8.200 数据库服务器

/etc/hosts

bash 复制代码
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

################# web cluster #################
10.1.8.41 ha1.linux.com ha1
10.1.8.42 ha2.linux.com ha2
10.1.8.43 proxy1.linux.com proxy1
10.1.8.44 proxy2.linux.com proxy2
10.1.8.45 company1.linux.com company1
10.1.8.46 company2.linux.com company2
10.1.8.47 blog1.linux.com blog1
10.1.8.48 blog2.linux.com blog2
10.1.8.49 db1.linux.com db1
10.1.8.40 db2.linux.com db2
10.1.8.41 storage.linux.com storage
10.1.8.41 yum.linux.com yum
10.1.8.42 backup.linux.com backup
10.1.8.43 network.linux.com network
10.1.8.43 dns.linux.com dns
10.1.8.44 client.linux.com client
10.1.8.100 www.linux.com www
10.1.8.200 db.linux.com db

环境准备

按以下要求准备以上主机:

  1. 所有节点配置:

    • 最小化安装 CentOS 7。

    • 关闭 SELinux 和防火墙。

    • 确保时间准确。

    • 删除系统自带的所有 yum 仓库(保留epel仓库)。

    • 网关设置为 10.1.8.2 ,DNS设置为 10.1.8.53network.linux.com 节点 DNS 设置为 223.5.5.5

    • 命令提示符设置为 PS1='\[\\u@\\\[\\e\[32m\\]\\h\\\[\\e\[0m\\] \\W \\t]\\$ '

      在 /etc/bashrc最后添加一行

      bash 复制代码
      PS1='\[\\u@\\\[\\e\[32m\\]\\h\\\[\\e\[0m\\] \\W \\t]\\$ '
  2. storage.linux.com 节点额外配置 5 块、容量 20G 的 SATA 硬盘。

  3. 按以上要求配置主机名和IP地址。参考脚本:

    bash 复制代码
    #!/bin/bash
    
    # 以 root 身份运行
    [ $UID -ne 0 ] && echo 'Please run as root.' && exit 1 
    
    # 指定接口名称
    interface=ens33
    
    # 指定域名称
    domain=linux.com
    
    # 脚本使用说明
    usage (){
      echo "Usage: $0 21-34"
      exit 1
    }
    
    # 设置 IP 地址
    function set_ip () {
      if [ $1 -eq 33 ];then
        dns=223.5.5.5
      else
        dns=10.1.8.53
      fi
    
      if [ $# -eq 0 ]; then
        usage   
      else
        nmcli connection modify ${interface} connection.autoconnect on ipv4.method manual ipv4.addresses 10.1.8.$1/24 ipv4.gateway 10.1.8.2 ipv4.dns $dns 
        nmcli connection up ${interface} &>/dev/null
      fi
    }
    
    
    # 设置主机名
    function set_hostname () {
      # 获取主机名
      case $1 in
        41|42)
          HOSTNAME=ha$[ $1 - 40 ].$domain
          ;;
        43|44)
          HOSTNAME=proxy$[ $1 - 42 ].$domain
          ;;
        45|46)
          HOSTNAME=company$[ $1 - 44 ].$domain
          ;;
        47|48)
          HOSTNAME=blog$[ $1 - 46 ].$domain
          ;;
        49|50)
          HOSTNAME=db$[ $1 - 48 ].$domain
          ;;
        51)
          HOSTNAME=storage.$domain
          ;;
        52)
          HOSTNAME=backup.$domain
          ;;
        53)
          HOSTNAME=network.$domain
          ;;
        54)
          HOSTNAME=client.$domain
          ;;
        *)
          usage
          ;;
      esac
      # 设置主机名
      hostnamectl set-hostname $HOSTNAME
    }
    
    # 定义 main 函数调用功能函数
    function main() {
      # 设置主机名
      set_hostname $1
      
      # 设置 IP
      set_ip $1
    
      # 显示修改结果
      bash -c 'clear;hostname;echo;ip -br a;echo'
    
      # 关机打快照
      while true
      do
        echo -ne "Press the \033[1;31mEnter\033[0;39m key, and the system will shut down in 5 seconds.";read
        echo -e "Press \033[1;35mCTRL+C\033[0;39m to cancel the shutdown."
        for i in {5..1}
        do
          echo "The system will shut down in $i seconds."
          sleep 1
        done
        echo "Shutdown system Now." && init 0
      done 
    }
    
    # 执行 main 函数
    main $*

    考核要求

  4. 本次考试允许可以借助一切外部资源,但禁止与人(包括AI)讨论。

  5. 考试截止时间 17:30。

  6. 题目实现的过程和结果以命令行代码方式写入 markdown 文件中,网站验证结果需截图

  7. 先将 markdown 格式答卷字体调整为14号,再导出为pdf。

    文件名格式: 第一阶段考核-实验-姓名.pdf

  8. 考试过程需全程全屏录屏,文件名为:第一阶段考核-实验-姓名.mp4

  9. 将考试结果 pdf 文档和 mp4 视频上传到QQ群目录 《第一阶段考核-实验-答卷》。

    考核内容

    配置-存储服务器(25)

    配置节点storage.linux.com

  10. 配置本地仓库。(4)

    • 挂载 CentOS 7 光盘到 /usr/local/nginx/html/dvd 目录,并设置光盘开机自动挂载。
    bash 复制代码
    [root@storage ~ 15:00:23]# mkdir -p /usr/local/nginx/html/dvd
    [root@storage ~ 15:05:56]# cd /usr/local/nginx/html/dvd/
    [root@storage dvd 15:06:30]# pwd
    /usr/local/nginx/html/dvd
    [root@storage dvd 15:06:49]# mount /dev/sr0 /usr/local/nginx/html/dvd/
    mount: /dev/sr0 is write-protected, mounting read-only
    [root@storage dvd 15:07:29]# cd
    [root@storage ~ 15:07:52]# vim /etc/fstab 
    # 添加
    # /dev/sr0 /usr/local/nginx/html/dvd iso9660 defaults 0 0
    [root@storage ~ 15:12:32]# mount -a
    mount: /dev/sr0 is write-protected, mounting read-only
    
    - 配置仓库来源于 /usr/local/nginx/html/dvd 目录。
    [root@storage yum.repos.d 15:29:53]# cat iso.repo 
    [iso]
    name=local is
    baseurl=file:///usr/local/nginx/html/dvd
    enable=1
    gpgcheck=0

2.通过 nginx 提供 yum 仓库 。(6)

  • 通过源码部署 nginx 到 /usr/local/nginx。

nginx-1.24.0.tar.gz 源码找老师获取。

bash 复制代码
[root@storage ~ 15:34:02]# ls
anaconda-ks.cfg  jiaoben.sh  jiaoben.sh~  # nginx-1.24.0.tar.gz
#临时调正dns配个网
[root@storage ~ 15:35:37]# nmcli connection modify ens33 ipv4.dns 223.5.5.5    
[root@storage ~ 15:36:34]# nmcli connection up ens33
[root@storage ~ 15:36:49]# yum install gcc make pcre-devel zlib-devel
[root@storage ~ 15:45:50]# yum install -y wget
[root@storage ~ 15:46:11]# wget https://nginx.org/download/nginx-1.24.0.tar.gz
[root@storage ~ 15:47:26]# tar -xf nginx-1.24.0.tar.gz
[root@storage ~ 15:49:21]# cd nginx-1.24.0/
[root@storage nginx-1.24.0 15:49:30]# ./configure --prefix=/usr/local/nginx
[root@storage nginx-1.24.0 15:49:44]#  make && make install
#最终结果
[root@storage nginx-1.24.0 15:50:23]# ls /usr/local/nginx/
conf  html  logs  sbin

- 配置nginx通过systemd管理,并设置 nginx 服务开机启动。
[root@storage ~ 15:56:41]# cp /usr/lib/systemd/system/sshd.service /etc/systemd/system/nginx.service
[root@storage ~ 15:56:53]# vim /etc/systemd/system/nginx.service
[Unit]
Description=Nginx server daemon

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[root@storage ~ 16:09:33]# systemctl daemon-reload 
[root@storage ~ 16:09:38]# systemctl enable nginx.service --now
[root@storage ~ 16:09:40]# systemctl status nginx.service 
  
  
- \*\*配置其他所有节点\*\*仓库来源于 http://yum.linux.com/dvd。
> yum.linux.com 对应ip 为 10.1.8.51,也就是存储节点,域名解析最终由DNS服务器提供。 
[root@其他的节点 ~ 16:12:37]# vim yum.repo
[yum]
name=yum
baseurl=http://10.1.8.51/dvd
gpgcheck=0

提示

  • 如果 nginx 服务想支持显示目录中文件清单,需要在配置文件中做如下修改,并重启服务:
bash 复制代码
[root@storage ~ 16:30:45]# vim /usr/local/nginx/conf/nginx.conf
http {
      # 添加如下参数
      autoindex on;
  ......
  }
[root@storage ~ 16:33:04]# systemctl restart nginx
  1. 配置 raid 存储。(2)

    使用sdb、sdc、sdd、sde、sdf创建 raid5 设备md5。

    bash 复制代码
    [root@storage ~ 16:36:42]# yum install -y mdadm
    [root@storage ~ 16:38:03]# mdadm --create /dev/md5 --level 5 --raid-devices 5 /dev/sd{b..f}
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md5 started.
    
    [root@storage ~ 16:39:48]# lsblk
  2. **配置 NFS 共享存储**。(8)

  3. 配置 NFS 共享存储。(8)

    • 准备NFS 共享目录1:/webapp/blog(3)

      • 在设备md5上创建分区1,容量为20G,格式化为 xfs 文件系统,持久化挂载在 /webapp/blog。
      • 将 wordpress-4.8-zh_CN.zip 中 wordpress 中所有文件提取到 /webapp/blog 中。
      • 只允许 web 服务器上 nginx 账户读写访问该目录,其他账户只能读该目录。
    bash 复制代码
    [root@storage ~ 16:40:01]# mkdir -p /webapp/blog
    [root@storage ~ 16:42:56]# fdisk /dev/md5
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    Device does not contain a recognized partition table
    Building a new DOS disklabel with disk identifier 0x0ccb613e.
    
    Command (m for help): "m"
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       g   create a new empty GPT partition table
       G   create an IRIX (SGI) partition table
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    Command (m for help): "n"
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): "p""
    Partition number (1-4, default 1): "回车"
    First sector (4096-167632895, default 4096):"回车" 
    Using default value 4096
    Last sector, +sectors or +size{K,M,G} (4096-167632895, default 167632895):"+20G" 
    Partition 1 of type Linux and of size 20 GiB is set
    
    Command (m for help): 'p'
    
    Disk /dev/md5: 85.8 GB, 85828042752 bytes, 167632896 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 524288 bytes / 2097152 bytes
    Disk label type: dos
    Disk identifier: 0x0ccb613e
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/md5p1            4096    41947135    20971520   83  Linux
    
    Command (m for help): "w"
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@storage ~ 16:47:02]# lsblk
    [root@storage ~ 16:49:09]# mkfs.xfs /dev/md5p1
    [root@storage ~ 16:49:35]# mount /dev/md5p1 /webapp/blog/
    [root@storage ~ 16:50:00]# lsblk
    [root@storage ~ 16:50:06]# blkid /dev/md5p1
    /dev/md5p1: UUID="482125b4-07e4-4e5b-9e1f-4e6d5d1ded17" TYPE="xfs" 
    [root@storage ~ 16:50:37]# vim /etc/fstab 
    [root@storage ~ 16:52:06]# cat /etc/fstab 
    #
    # /etc/fstab
    # Created by anaconda on Sat Apr 25 13:47:57 2026
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    /dev/mapper/centos-root /                       xfs     defaults        0 0
    UUID=3d14fa50-47e9-4c6c-b1f8-395c889a74a3 /boot                   xfs     defaults        0 0
    /dev/mapper/centos-home /home                   xfs     defaults        0 0
    /dev/mapper/centos-swap swap                    swap    defaults        0 0
    /dev/sr0 /usr/local/nginx/html/dvd iso9660 defaults 0 0
    #加这条 UUID="482125b4-07e4-4e5b-9e1f-4e6d5d1ded17" /webapp/blog xfs defaults 0 0
    
    [root@storage ~ 16:52:18]# umount /webapp/blog 
    [root@storage ~ 16:52:34]# lsblk
    [root@storage ~ 16:52:37]# mount -a
    [root@storage ~ 16:52:46]# lsblk
    
    #第二题
    [root@storage ~ 16:55:38]# ls
    anaconda-ks.cfg  jiaoben.sh~   nginx-1.24.0.tar.gz    wordpress-4.9.4-zh_CN.zip
    jiaoben.sh       nginx-1.24.0  nginx-1.24.0.tar.gz.1  yum.repo
    [root@storage ~ 16:55:43]# unzip wordpress-4.9.4-zh_CN.zip
    [root@storage ~ 16:56:09]# ls
    anaconda-ks.cfg  nginx-1.24.0           wordpress
    jiaoben.sh       nginx-1.24.0.tar.gz    wordpress-4.9.4-zh_CN.zip
    jiaoben.sh~      nginx-1.24.0.tar.gz.1  yum.repo
    [root@storage ~ 16:56:21]# cp -aR wordpress/* /webapp/blog/
    [root@storage ~ 16:56:56]# cd /webapp/blog/
    [root@storage blog 16:57:09]# ls
    index.php        wp-blog-header.php    wp-includes        wp-settings.php
    license.txt      wp-comments-post.php  wp-links-opml.php  wp-signup.php
    readme.html      wp-config-sample.php  wp-load.php        wp-trackback.php
    wp-activate.php  wp-content            wp-login.php       xmlrpc.php
    wp-admin         wp-cron.php           wp-mail.php
    
    #第三题
    [root@storage ~ 17:26:26]# chown -R 998 /webapp/blog/
    [root@storage ~ 17:26:29]# ll -d /webapp/blog/
    drwxr-xr-x 5 998 root 4096 Apr 25 17:21 /webapp/blog/

    准备NFS 共享目录2:/webapp/company(3)

    • 在设备md5上创建分区2,容量为20G,格式化为 ext4 文件系统,持久化挂载在 /webapp/company。
      • 将欢迎词 Welcome to Linux Cloud Company. 写入文件 /webapp/company/index.html 中。
      • 只允许 web 服务器上 nginx 账户读写访问该目录,其他账户只能读该目录。
    • 配置 NFS 共享:允许 10.1.8.0/24 网段访问共享目录 /webapp/company和/webapp/blog。(2)
    bash 复制代码
      [root@storage ~ 17:38:25]# umount /webapp/blog 
    [root@storage ~ 17:38:59]# fdisk /dev/md5
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): "p"
    
    Disk /dev/md5: 85.8 GB, 85828042752 bytes, 167632896 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 524288 bytes / 2097152 bytes
    Disk label type: dos
    Disk identifier: 0x0ccb613e
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/md5p1            4096    41947135    20971520   83  Linux
    /dev/md5p2        41947136    83890175    20971520   83  Linux
    
    Command (m for help): "d"
    Partition number (1,2, default 2): "2"
    Partition 2 is deleted
    
    Command (m for help): "p"
    
    Disk /dev/md5: 85.8 GB, 85828042752 bytes, 167632896 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 524288 bytes / 2097152 bytes
    Disk label type: dos
    Disk identifier: 0x0ccb613e
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/md5p1            4096    41947135    20971520   83  Linux
    
    Command (m for help): "n"
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): "p"
    Partition number (2-4, default 2): 
    First sector (41947136-167632895, default 41947136): 
    Using default value 41947136
    Last sector, +sectors or +size{K,M,G} (41947136-167632895, default 167632895): "+20G"
    Partition 2 of type Linux and of size 20 GiB is set
    
    Command (m for help): "p"
    
    Disk /dev/md5: 85.8 GB, 85828042752 bytes, 167632896 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 524288 bytes / 2097152 bytes
    Disk label type: dos
    Disk identifier: 0x0ccb613e
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/md5p1            4096    41947135    20971520   83  Linux
    /dev/md5p2        41947136    83890175    20971520   83  Linux
    
    Command (m for help): "w"
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@storage ~ 17:39:58]# lsblk
    [root@storage ~ 17:42:16]# mkfs.ext4 /dev/md5p2
    [root@storage ~ 17:42:37]# blkid /dev/md5p2
    /dev/md5p2: UUID="28d6577e-4854-4be8-8d4c-d4e380966a07" TYPE="ext4" 
    [root@storage ~ 17:44:37]# cat /etc/fstab 
    UUID="28d6577e-4854-4be8-8d4c-d4e380966a07" /webapp/company ext4 defaults 0 0
    
    #第二题
    [root@storage ~ 17:49:09]# echo Welcome to Linux Cloud Company. > /webapp/company/index.html
    [root@storage ~ 17:50:20]# cat /webapp/company/index.html 
    Welcome to Linux Cloud Company.
    #第三题
    [root@storage ~ 17:45:37]# chown -R 992 /webapp/company/
    
    #第四题
    [root@storage ~ 17:50:36]# yum install -y nfs-utils
    [root@storage ~ 17:59:19]# cat yum.repo 
    [yum]
    name=yum
    baseurl=http://yum.linux.com/dvd
    enabled=0
    gpgcheck=0
    [root@storage ~ 17:54:24]# systemctl enable nfs-server --now
    [root@storage ~ 17:58:04]# cat /etc/exports
    /webapp/company 10.1.8.0/24(rw)
    /webapp/blog 10.1.8.0/24(rw)
    
    
    
    提示:文件 wordpress-4.8-zh\_CN.zip 找考官索取。
  4. 配置 iSCSI 共享存储。(5)

    • 在设备md5上创建分区3,容量为40G,暂不格式化。(2)
    • 共享设备md5分区3。(2)
    • 只允许备份服务器(backup.linux.com)访问该设备。(1)
    bash 复制代码
    [root@storage ~ 18:17:52]# fdisk /dev/md5
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): 'n
    Partition type:
       p   primary (2 primary, 0 extended, 2 free)
       e   extended
    Select (default p): 'p
    Partition number (3,4, default 3): ""
    First sector (83890176-167632895, default 83890176): ""
    Using default value 83890176
    Last sector, +sectors or +size{K,M,G} (83890176-167632895, default 167632895): 
    Using default value 167632895
    Partition 3 of type Linux and of size 40 GiB is set
    
    Command (m for help): "w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@storage ~ 18:18:19]# lsblk
    [root@storage ~ 18:18:26]# yum install -y targetd targetcli
    [root@storage ~ 18:21:53]# systemctl enable target --now
    [root@storage ~ 18:21:54]# targetcli
    #配置 iscsi
    /> cd /backstores/block
    /backstores/block> 
    
    Created block storage object myblock1 using /dev/md5p3.
    /backstores/block> cd /iscsi 
    /iscsi> create iqn.2026-04.cloud.jiang.iscsi-server:disk1
    Created target iqn.2026-04.cloud.jiang.iscsi-server:disk1.
    Created TPG 1.
    Global pref auto_add_default_portal=true
    Created default portal listening on all IPs (0.0.0.0), port 3260.
    /iscsi> cd /iscsi/iqn.2026-04.cloud.jiang.iscsi-server:disk1/tpg1/luns
    /iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/myblock1 
    Created LUN 0.
    /iscsi> cd /iscsi/iqn.2026-04.cloud.jiang.iscsi-server:disk1/tpg1/luns
    /iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/myblock1 
    /iscsi/iqn.20...sk1/tpg1/luns> cd /iscsi/iqn.2026-04.cloud.jiang.iscsi-server:disk1/tpg1/acls
    /iscsi/iqn.20...sk1/tpg1/acls> create iqn.2026-04.com.linux.backup
    Created Node ACL for iqn.2026-04.com.linux.backup
    Created mapped LUN 0.
    /iscsi/iqn.20...sk1/tpg1/acls> exit

    配置-备份服务器(8)

    配置节点backup.linux.com

  5. 扫描并登录存储服务器通过iSCSI共享的块设备。(2)

    bash 复制代码
    [root@backup ~ 18:39:43]# yum install -y iscsi-initiator-utils
    [root@backup ~ 18:43:23]# vim /etc/iscsi/initiatorname.iscsi 
    InitiatorName=iqn.2026-04.com.linux.backup
    [root@backup ~ 18:43:29]# iscsiadm -m discovery -t st -p 10.1.8.51
    10.1.8.51:3260,1 iqn.2026-04.cloud.jiang.iscsi-server:disk1
    [root@backup ~ 18:58:51]# iscsiadm -m node -T iqn.2026-04.cloud.jiang.iscsi-server:disk1 -l
    [root@backup ~ 18:59:49]# lsblk /dev/sdb
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sdb    8:16   0  40G  0 disk 
  6. 格式化为 xfs 文件系统,持久化挂载在/webapp。(2)

bash 复制代码
[root@backup ~ 19:00:12]# mkfs.xfs /dev/sdb
[root@backup ~ 19:01:17]# mkdir /webapp
[root@backup ~ 19:01:46]# blkid /dev/sdb
/dev/sdb: UUID="d9925abb-74f1-4178-bdd5-d8480d83bbf5" TYPE="xfs"
[root@backup ~ 19:02:59]# cat /etc/fstab
UUID="d9925abb-74f1-4178-bdd5-d8480d83bbf5" /webapp xfs _netdev 0 0
[root@backup ~ 19:03:17]# mount -a
[root@backup ~ 19:05:23]# df -h /webapp/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb         40G   33M   40G   1% /webapp

3.配置备份。(4)

    • 每天 22:58 将存储服务器上的目录 /webapp中内容同步到本地 /webapp。
    • 每天 23:58 将数据库服务器上的目录 /var/lib/mysql 中内容同步到本地 /webapp/mysql。
    bash 复制代码
    [root@backup ~ 19:07:59]# systemctl enable crond --now
    [root@backup ~ 19:09:31]# crontab -e
    [root@backup ~ 19:17:09]# crontab -l
    58 22 * * * rsync -av storage:/webapp /webapp
    58 23 * * * rsync -av db1:/var/lib/mysql /webapp
    58 23 * * * rsync -av db2:/var/lib/mysql /webapp
    
    [root@backup ~ 19:17:12]# echo 'StrictHostkeyChecking no' >> /etc/ssh/ssh_config
    [root@backup ~ 19:18:04]# ssh-keygen 
    [root@backup ~ 19:18:24]# ssh-copy-id 10.1.8.49
    [root@backup ~ 19:19:16]# ssh-copy-id 10.1.8.50
    [root@backup ~ 19:19:24]# ssh 10.1.8.49
    [root@backup ~ 19:20:09]# ssh 10.1.8.50
    [root@backup ~ 19:30:14]# rsync -av 10.1.8.51:/webapp/ /webapp
    Warning: Permanently added '10.1.8.51' (ECDSA) to the list of known hosts.
    root@10.1.8.51's password: 
    [root@backup ~ 19:30:59]# ls /webapp/
    blog  company

    配置-网络服务器(14)

    配置节点network.linux.com

  1. 配置 DHCP 服务器。(6)

    • 网络范围:10.1.8.0/24
    • 地址池:10.1.8.101-10.1.8.120
    • 网关:10.1.8.4
    • DNS:10.1.8.53
    • 域名:linux.com
    • 为客户端 client.linux.com 分配固定 IP 地址:10.1.8.54。
    • 确保dhcp服务开机启动。
    bash 复制代码
    [root@client ~ 16:27:11]# ip -br link
    lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP> 
    ens33            UP             #00:0c:29:15:61:2d# 复制这个地址
    [root@network ~ 19:37:44]# yum install -y dhcp
    root@network ~ 19:49:06]# cat /etc/dhcp/dhcpd.conf 
    #
    # DHCP Server Configuration file.
    #   see /usr/share/doc/dhcp*/dhcpd.conf.example
    #   see dhcpd.conf(5) man page
    #
    subnet 10.1.8.0 netmask 255.255.255.0 {
      range 10.1.8.101 10.1.8.120;
      option domain-name-servers 10.1.8.53;
      option domain-name linux.com;
      option routers 10.1.8.4;
      option broadcast-address 10.1.8.255;
      default-lease-time 600;
      max-lease-time 7200;
    }
    host client.linux.com {
      hardware ethernet 00:0c:29:15:61:2d;
      fixed-address 10.1.8.54;
    }
    [root@network ~ 19:53:26]# systemctl enable dhcpd --now
    [root@network ~ 19:53:33]# systemctl status dhcpd
    ● dhcpd.service - DHCPv4 Server Daemon
       Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
       Active: active (running) since Sat 2026-04-25 19:53:33 CST; 2s ago
  2. 配置 DNS 服务器。(8)

    • 允许所有客户端查询
    • 允许递归查询
    • 禁止 dnssec 校验
    • 该 zone 由服务器 dns.linux.com 负责,对应IP为10.1.8.53。
    • 该 zone 提供实验环境中所有主机正向和反向解析。
    • 确保named服务开机启动。
    bash 复制代码
    [root@network ~ 08:57:31]# yum install -y bind bind-utils
    root@network ~ 09:09:53]# vim /etc/named.conf 
    [root@network ~ 09:16:11]# touch /var/named/linux.com.zone
    [root@network ~ 09:16:31]# touch /var/named/10.1.8.zone
    [root@network ~ 09:16:50]# chmod 640 /var/named/*.zone
    
    [root@network ~ 10:06:16]# cat /etc/named.conf 
    //
    // named.conf
    //
    // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
    // server as a caching only nameserver (as a localhost DNS resolver only).
    //
    // See /usr/share/doc/bind*/sample/ for example named configuration files.
    //
    // See the BIND Administrator's Reference Manual (ARM) for details about the
    // configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
    
    options {
    	listen-on port 53 { 127.0.0.1;10.1.8.53; };
    	listen-on-v6 port 53 { ::1; };
    	directory 	"/var/named";
    	dump-file 	"/var/named/data/cache_dump.db";
    	statistics-file "/var/named/data/named_stats.txt";
    	memstatistics-file "/var/named/data/named_mem_stats.txt";
    	recursing-file  "/var/named/data/named.recursing";
    	secroots-file   "/var/named/data/named.secroots";
    	allow-query     { localhost;any; };
    
    	/* 
    	 - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
    	 - If you are building a RECURSIVE (caching) DNS server, you need to enable 
    	   recursion. 
    	 - If your recursive DNS server has a public IP address, you MUST enable access 
    	   control to limit queries to your legitimate users. Failing to do so will
    	   cause your server to become part of large scale DNS amplification 
    	   attacks. Implementing BCP38 within your network would greatly
    	   reduce such attack surface 
    	*/
    	recursion yes;
    
    	dnssec-enable no;
    	dnssec-validation yes;
    
    zone "linux.com" IN {
            type master;
            file "linux.com.zone";
    };
    
    zone "8.1.10.in-addr.arpa" IN {
             type master;
             file "10.1.8.zone";[]
    };
    
    
    [root@network ~ 10:06:21]# cat /var/named/linux.com.zone
    $TTL 1D
    @	IN SOA	linux.com. root.linux.com. (
    					0	; serial
    					1D	; refresh
    					1H	; retry
    					1W	; expire
    					3H )	; minimum
            	IN NS 	dns.linux.com.
    ha1			IN A	10.1.8.41
    ha2			IN A	10.1.8.42
    proxy1		IN A	10.1.8.43
    proxy2		IN A	10.1.8.44
    company1	IN A	10.1.8.45
    company2	IN A	10.1.8.46
    blog1		IN A	10.1.8.47
    blog2		IN A	10.1.8.48
    db1			IN A	10.1.8.49
    db2			IN A	10.1.8.50
    storage		IN A	10.1.8.51
    backup		IN A	10.1.8.52
    network		IN A	10.1.8.53
    client		IN A	10.1.8.54
    yum			IN A	10.1.8.51
    dns			IN A	10.1.8.53
    www			IN A	10.1.8.100
    db			IN A	10.1.8.200
    
    [root@network ~ 10:07:24]# cat /var/named/10.1.8.zone 
    $TTL 1D
    @	IN SOA  linux.com. root.linux.com. (
    					0	; serial
    					1D	; refresh
    					1H	; retry
    					1W	; expire
    					3H )	; minimum
            IN NS   dns.linux.com.
    41      IN PTR  ha1.linux.com.
    42      IN PTR  ha2.linux.com.
    43      IN PTR  proxy1.linux.com.
    44      IN PTR  proxy2.linux.com.
    45      IN PTR  company1.linux.com.
    46      IN PTR  company2.linux.com.
    47      IN PTR  blog1.linux.com.
    48      IN PTR  blog2.linux.com.
    49      IN PTR  db1.linux.com.
    50      IN PTR  db2.linux.com.
    51      IN PTR  storage.linux.com.
    52      IN PTR  backup.linux.com.
    53      IN PTR  network.linux.com.
    54      IN PTR  client.linux.com.
    51      IN PTR  yum.linux.com.
    53      IN PTR  dns.linux.com.
    100     IN PTR  www.linux.com.
    200     IN PTR  db.linux.com.
    
    [root@network ~ 10:07:32]# systemctl enable named.service --now
    [root@network ~ 10:08:26]# systemctl status named

    配置-数据库服务器(16)

    配置节点db1.linux.comdb2.linux.com

  3. 所有数据库节点部署 Mariadb 服务。(2)

    bash 复制代码
    [db1]
    [root@db1 yum.repos.d 18:34:46]# vim yum.repo
    [yum]
    name=yum
    baseurl=http://10.1.8.51/dvd
    gpgcheck=0
    [root@db1 yum.repos.d 18:35:03]# yum install -y mariadb-server
    [root@db1 yum.repos.d 18:37:44]# systemctl enable mariadb --now
    Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
    #同理db2
  4. 所有数据库节点进行安全初始化:设置 root 密码为Laoma@123,禁止root用户远程登录,删除匿名用户,删除测试数据库。(4)

    bash 复制代码
    [root@db1 ~]# mysql_secure_installation
    同理db2
  5. 配置两台数据库节点为主主架构。(8)

    所有节点开启日志。

    bash 复制代码
    [root@db1 ~ 18:42:56]# vim /etc/my.cnf
    [mysqld]
    server-id=1
    log_bin=mysql-bin
    relay_log=mysql-relay-bin
    datadir=/var/lib/mysql
    
    [root@db2 ~ 18:42:59]# vim /etc/my.cnf
    [mysqld]
    server-id=2
    log_bin=mysql-bin
    relay_log=mysql-relay-bin
    [root@db1 ~ 18:45:11]# systemctl restart mariadb.service 
    [root@db2 ~ 18:45:11]# systemctl restart mariadb.service 
    [root@db1 ~ 18:48:34]# systemctl status mariadb.service 
    [root@db2 ~ 18:48:34]# systemctl status mariadb.service 

    所有节点创建同步账户。

    bash 复制代码
    [root@db1 ~ 18:49:50]# mysql -uroot -pLaoma@123
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.68-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> grant replication slave, replication client on *.* to 'repl'@'%'identified by 'huawei';Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    [root@db2 ~ 18:49:58]# mysql -uroot -pLaoma@123
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.68-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> grant replication slave, replication client on *.* to 'repl'@'%'identified by 'huawei';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    配置 db1.linux.com 作为 db2.linux.com 的从。

    bash 复制代码
    [db2]
    MariaDB [(none)]> show master status \G
    *************************** 1. row ***************************
                File: mysql-bin.000001
            Position: 481
        Binlog_Do_DB: 
    Binlog_Ignore_DB: 
    1 row in set (0.00 sec)
    
    MariaDB [(none)]> 
    
    [db1]
    MariaDB [(none)]> change master to master_host='10.1.8.49',#这个ip为db2的ip
        -> master_user='repl',
        -> master_password='redhat',
        -> master_port=3306,
        -> master_log_file='mysql-bin.000001',
        -> master_log_pos=481,
        -> master_connect_retry=30;
    Query OK, 0 rows affected (0.02 sec)
    Query OK, 0 rows affected (0.02 sec)
    
    MariaDB [(none)]> start slave;
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]> show slave status\G;
    #db1db2  GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.1.8.49' IDENTIFIED BY 'redhat';

    配置 db2.linux.com 作为 db1.linux.com 的从。

    bash 复制代码
  6. 为博客站点准备数据库:(2)

    • 数据库名称为 blog
    • 创建账户:账户名 blog@'%',密码为Laoma@123
    • 账户名 blog@'%' 对数据库 blog 有完全控制权限。
    bash 复制代码
    ### 配置-公司站点服务器(6)
    
    **配置节点**:company1.linux.com 和 company2.linux.com。
  7. 所有公司站点服务器持久化挂载存储服务器提供的nfs共享目录 /webapp 到本地/usr/share/nginx/html目录。(4)

    bash 复制代码
    [company1]
    [root@company1 ~ 20:57:45]# yum install -y nfs-utils nginx
    [root@company1 ~ 20:58:12]# showmount -e 10.1.8.51
    [root@company1 ~ 20:58:56]# vim /etc/fstab 
    storage:/webapp /usr/share/nginx/html  nfs defaults 0 0
    [root@company1 ~ 21:06:13]# mount /usr/share/nginx/html/
    [root@company1 ~ 21:06:42]# df -h /usr/share/nginx/html
    
    [company2]
    [root@company2 ~ 20:57:45]# yum install -y nfs-utils nginx
    [root@company2~ 20:58:12]# showmount -e 10.1.8.51
    [root@company2 ~ 20:58:56]# vim /etc/fstab 
    storage:/webapp /usr/share/nginx/html  nfs defaults 0 0
    [root@company1 ~ 21:06:13]# mount /usr/share/nginx/html/
    [root@company1 ~ 21:06:42]# df -h /usr/share/nginx/html
  8. 所有公司节点部署 Nginx 服务器,确保客户端可以通过以下地址访问 company 站点:(2)

    bash 复制代码
    [root@company1 ~ 21:06:55]# vim /etc/nginx/conf.d/vhost-company.linux.com.conf
    [root@company1 ~ 21:16:00]# cat /etc/nginx/conf.d/vhost-company.linux.com.conf
    server {
       listen      80;
       listen      [::]:80;
       server_name company1:linux.com;
       root        /usr/share/nginx/html/company;
    }
    [root@company1 ~ 21:16:09]# systemctl enable nginx.service --now
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
    [root@company1 ~ 21:16:22]# curl http://company1.linux.com/
    
    
    [root@company2 ~ 21:06:55]# vim /etc/nginx/conf.d/vhost-company.linux.com.conf
    [root@company2 ~ 21:16:00]# cat /etc/nginx/conf.d/vhost-company.linux.com.conf
    server {
       listen      80;
       listen      [::]:80;
       server_name company2:linux.com;
       root        /usr/share/nginx/html/company;
    }
    [root@company1 ~ 21:16:09]# systemctl enable nginx.service --now
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
    [root@company1 ~ 21:16:22]# curl http://company2.linux.com/

    配置-博客站点服务器(6)

    配置节点blog1.linux.comblog2.linux.com

  9. 博客使用LNMP架构。

  10. 所有博客节点持久化挂载存储服务器提供的nfs共享目录/webapp到本地/usr/share/nginx/html目录。(4)

    bash 复制代码
  11. 所有博客节点部署 Nginx 服务器,确保客户端可以通过以下地址访问博客站点:(2)

    php 相关软件包通过http://mirrors.aliyun.com/repo/Centos-7.repo获取。

    bash 复制代码
  12. 注意: 等高可用和负载均衡服务器配置完成后,再对博客站点进行初始化。

    配置-反向代理(6)

    配置节点proxy1.linux.comproxy2.linux.com

    使用 nginx 配置反向代理,每个代理节点需完成以下功能:

bash 复制代码
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
subnet 10.1.8.0 netmask 255.255.255.0 {
range 10.1.8.101 10.1.8.120;
option domain-name-servers 10.1.8.53;
option domain-name "linux.com";
option routers 10.1.8.4;
option broadcast-address 10.1.8.255;
default-lease-time 600;
max-lease-time 7200;
}




host client.linux.c#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
subnet 10.1.8.0 netmask 255.255.255.0 {
range 10.1.8.101 10.1.8.120;
option domain-name-servers 10.1.8.53;
option domain-name "linux.com";
option routers 10.1.8.4;
option broadcast-address 10.1.8.255;
default-lease-time 600;
max-lease-time 7200;
}




host client.linux.com {
hardware ethernet 00:0c:29:90:bb:83;
fixed-address 10.1.8.54;
}om {
hardware ethernet 00:0c:29:90:bb:83;
fixed-address 10.1.8.54;
}
}
}
bash 复制代码
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
subnet 10.1.8.0 netmask 255.255.255.0 {
range 10.1.8.101 10.1.8.120;
option domain-name-servers 10.1.8.53;
option domain-name "linux.com";
option routers 10.1.8.4;
option broadcast-address 10.1.8.255;
default-lease-time 600;
max-lease-time 7200;
}




host client.linux.com {
hardware ethernet 00:0c:29:90:bb:83;
fixed-address 10.1.8.54;
}
相关推荐
国冶机电安装2 小时前
计算机网络系统安装的结构逻辑、施工重点与运维价值
运维·网络·计算机网络
The Chosen One9852 小时前
遗漏知识点补充(lesson12&&Linux进程(1))
linux·运维·服务器
醇氧2 小时前
WSL2(Windows Subsystem for Linux ) 从入门到实践指南
linux·运维·服务器·windows·学习
wangyangyangcumt2 小时前
银河麒麟V10 SP3离线安装Nginx1.21.5全记录
linux·运维·数据库
羊小蜜.3 小时前
Linux 03:僵死进程(Zombie Process)原理、危害与解决方案
linux·运维·服务器
yang9yun3 小时前
linux宝塔面板使用API自动部署更新文件
linux·运维·状态模式
cen__y3 小时前
Linux06(进程)
linux·运维·服务器·c语言·ubuntu
码银3 小时前
使用VMware安装CentOS7(Linux)操作系统(图文步骤)附vmware安装包/centos.iso镜像文件
linux·运维·centos
似水এ᭄往昔3 小时前
【Linux】--磁盘和文件系统
linux·运维·数据库