2024真机项目

作者 : admin 本文共9139个字,预计阅读时间需要23分钟 发布时间: 2024-06-10 共3人阅读

项目需求:

1. 172.25.250.101 主机上的 Web 服务要求提供 www.exam.com 加密站点,该站点在任何路由可达 的主机上被访问,页面内容显示为 “Hello,Welcome to www.exam.com !”,并提供 content.exam.com/yum/AppStream和content.exam.com/yum/BaseOS URL 作为网络仓库供所 有主机使用。
2. 172.25.250.102 主机提供的 NTP 服务将本主机作为服务器,对外提供 NTP 服务,并设置本服务器 为 3 层。
3. 172.25.250.103 主机提供的MySQL 数据库服务使用源码安装官方 mysql-8.4.0 版,并将数据库密 码设定为 redhat。创建名称为 bbs 的数据库提供给论坛服务使用。
4. 172.25.250.104 主机提供 NFS 服务,该服务将导出本地的 /bbs 目录作为论坛数据目录,该导出指 定只能论坛所在主机使用,并且开机自动挂载。
5. 172.25.250.105 主机提供 DNS 服务,该服务需要提供对项目中所有主机名的正向和反向解析,并 要求所有服务器的 DNS 配置为该 DNS 服务器。
6. 172.25.250.106 主机提供 PXE 自动化部署服务,其他两台服务器的系统安装由该服务提供。
7. 172.25.250.107 主机提供基于 Discuz 的论坛服务,该论坛服务使用 172.25.250.103 主机提供的数 据库 bbs,使用 172.25.250.104 主机提供的 NFS 作为论坛数据目录,并开机挂载。并使用 172.25.250.101 主机提供的网络仓库,172.25.250.102 主机提供的 NTP 服务,172.25.250.105 主 机提供的 DNS 服务。
8. 172.25.250.108 主机作为客户端出现,并使用 172.25.250.101 主机提供的网络仓库, 172.25.250.102 主机提供的 NTP 服务,172.25.250.105 主机提供的 DNS 服务。
9. 根据所有服务的相关代码,编写一键部署shell脚本,最基础的功能为 通过执行该脚本实现所有上面 服务。
10. 扩展需求:根据所有服务的相关代码,编写Ansible 角色 exam,通过该角色快速部署上面所有服 务。 其他注意事项 所有服务器的防火墙服务和 SELinux 服务必须开启。 所有服务器提供的网络服务必须在系统重启后仍然可以正常提供服务。

环境拓扑结构

2024真机项目插图

主机环境描述

2024真机项目插图(1)

注意:

172.25.250.101-172.25.250.106 共 6 个 IP 地址由servera.exam.com服务器进行提供。

172.25.250.107 由 serverb.exam.com 服务器进行提供。

172.25.250.108 由 serverc.exam.com 服务器进行提供。

项目需求描述

2024真机项目插图(2)

1.配置网络

[root@server ~]# nmcli connection modify ens32 ipv4.addresses 172.25.250.101/24 ipv4.method manual ipv4.gateway 172.25.250.2 ipv4.dns 172.25.250.105 connection.autoconnect yes
[root@server ~]# nmcli connection modify ens32 +ipv4.addresses 172.25.250.102/24
[root@server ~]# nmcli connection modify ens32 +ipv4.addresses 172.25.250.103/24
[root@server ~]# nmcli connection modify ens32 +ipv4.addresses 172.25.250.104/24
[root@server ~]# nmcli connection modify ens32 +ipv4.addresses 172.25.250.105/24
[root@server ~]# nmcli connection modify ens32 +ipv4.addresses 172.25.250.106/24
[root@server ~]# nmcli connection up ens32

登录172.25.250.101

2024真机项目插图(3)

2.配置DNS

2.1安装软件包(这里下载软件包注意网关是否改为自己电脑的网关)

[root@server ~]# dnf install bind -y

 2.2放行防火墙规则

[root@server ~]# systemctl start firewalld
[root@server ~]# firewall-cmd --permanent --add-service=dns
success
[root@server ~]# firewall-cmd --reload
success
[root@server ~]# 

2.3 配置DNS服务          

[root@server ~]# cat /etc/named.conf
options {
 listen-on port 53 { 172.25.250.105; };
 directory "/var/named";
};
zone "exam.com" IN {
 type master;
 file "named.exam";
};
[root@server ~]# cat /var/named/named.exam
$TTL 1D
@ IN SOA  @   admin.exam.com. (
			0
			5
			3
			10
			15 )
   		IN 	 NS dns.exam.com.
dns  		IN	A  172.25.250.105
content 	IN  	A  172.25.250.101
www 		IN  	A  172.25.250.101
ntp 		IN  	A  172.25.250.102
mysql  		IN 	A  172.25.250.103
nfs		 IN  	A  172.25.250.104
pxw 		IN  	A  172.25.250.106
bbs 		IN  	A  172.25.250.107
workstation  	IN 	A  172.25.250.108
[root@server ~]# systemctl restart named /重启named/

 3、配置 Web 服务 

[root@server ~]# dnf install httpd -y
[root@server ~]#  grep ServerName /etc/httpd/conf/httpd.conf 
# ServerName gives the name and port that the server uses to identify itself.
ServerName www.example.com:80

将图中画箭头一行的#去掉

2024真机项目插图(4)

  2024真机项目插图(5) 

[root@server ~]# systemctl restart httpd
[root@server ~]# echo "Hello,Welcome to www.exam.com !" > /var/www/html/index.html
[root@server ~]# firewall-cmd --permanent --add-service=http
success
[root@server ~]# firewall-cmd --reload
success
[root@server ~]# curl www.exam.com
Hello,Welcome to www.exam.com !

4、配置 YUM 仓库                                                                         

[root@server ~]# mkdir /var/www/html/yum
[root@server ~]# mount /dev/sr0 /var/www/html/yum
mount: /var/www/html/yum: WARNING: source write-protected, mounted read-only.
[root@server ~]# cat /etc/yum.repos.d/rpm.repo 
[openEuler-everything]
name=openEuler-everything
baseurl=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS-SP3/everything/x86_64/
enabled=1
gpgcheck=0
gpgkey=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS-SP3/everything/x86_64/RPM-GPG-KEY-openEuler

[openEuler-EPOL]
name=openEuler-epol
baseurl=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS-SP3/EPOL/main/x86_64/
enabled=1
gpgcheck=0

[openEuler-update]
name=openEuler-update
baseurl=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS-SP3/update/x86_64/
enabled=1
gpgcheck=0
[root@server ~]# vim /etc/yum.repos.d/rpm.repo 

2024真机项目插图(6)

以上代码详情请参照下面超链接

【汇总贴】openEuler常用repo源 – #24,来自 HLG523653667 – 迁移 – openEuler 论坛为了方便大家快速找到openEuler所需版本的repo源,现将openEuler各版本的repo源进行了整理并归类,具体如下: 1、长期支持版本: openEuler-20.03-LTS: repo源 openEul…2024真机项目插图(7)http://forum.openeuler.org/t/topic/768/24

5、配置时间服务器   

   server主机配置服务器端                                                                  

[root@server ~]# vim /etc/chrony.conf

 改下图  2024真机项目插图(8)        2024真机项目插图(9) 

[root@server ~]# systemctl enable chronyd
[root@server ~]# firewall-cmd --permanent --add-service=ntp
success
[root@server ~]# firewall-cmd --reload
success
[root@server ~]# systemctl restart chronyd
[root@server ~]# 

node主机配置客户端  

node主机配置网络172.25.250.107/24                                                                                                       2024真机项目插图(10)

[root@node ~]# vim /etc/chrony.conf

进入/etc/chrony.conf文件改下图中的一行

2024真机项目插图(11)  2024真机项目插图(12)                                                                                                                                       


[root@node ~]# systemctl restart chronyd
[root@node ~]# systemctl enable chronyd
[root@node ~]# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 172.25.250.102                3   6    17    13    +21us[+5190ns] +/-  133us
[root@node ~]# 

6、配置数据库服务器                                                                     

[root@server ~]# groupadd mysql
[root@server ~]# useradd -r -g mysql -s /b
bin/  boot/ 
[root@server ~]# useradd -r -g mysql -s /bin/false mysql
[root@server ~]# tar xvf mysql-8.4.0.tar.gz
[root@server /]# cd  mysql-8.4.0/
[root@server mysql-8.4.0]# mkdir bld
[root@server mysql-8.4.0]# cd bld/
[root@server ~]# yum install mysql-server -y
[root@server ~]# systemctl start mysqld 

 解压MySQL8.4.0之前,打开xftp,将下载的软件包拖到虚拟机的根目录再进行解压

2024真机项目插图(13) 2024真机项目插图(14)
 

[root@server ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.37 Source distribution

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user root@localhost identified by 'redhat';  /更改或设置MySQL登录密码
Query OK, 0 rows affected (0.01 sec)

mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush peivileges;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'peivileges' at line 1
mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
mysql> create database bbs;
Query OK, 1 row affected (0.00 sec)



更改防火墙规则

[root@server ~]# firewall-cmd --permanent --add-service=mysql
success
[root@server ~]# firewall-cmd --reload
success
[root@server ~]# 

                                                                                                        7、配置 NFS 服务器                                                                     

[root@server bld]# mkdir /bbs
[root@server bld]# chmod 777 /bbs/
[root@server bld]# vim /etc/exports
[root@server bld]# cat /etc/exports
/bbs   bbs.exam.com(rw)
[root@server bld]# systemctl start nfs-server
[root@server bld]# showmount -e nfs.exam.com
Export list for nfs.exam.com:
/bbs bbs.exam.com
[root@server bld]# firewall-cmd --permanent --add-service=nfs
success
[root@server bld]# firewall-cmd --permanent --add-service=mountd 
success
[root@server bld]# firewall-cmd --permanent --add-service=rpc-bind 
success 
[root@node ~]# showmount -e nfs.exam.com
Export list for nfs.exam.com:
/bbs bbs.exam.com
[root@node ~]# mount nfs.exam.com:/bbs /var/www/html/
[root@node ~]# df -h /var/www/html/
Filesystem         Size Used Avail Use% Mounted on
nfs.exam.com:/bbs   44G   10G   35G  23% /var/www/html
[root@node ~]# tail -1 /etc/fstab 
nfs.exam.com:/bbs   /var/www/html       nfs   defaults  0 0
[root@node ~]# reboot
[root@node ~]# Connection closing...Socket close.
[root@node ~]# df -h /var/www/html/
Filesystem         Size Used Avail Use% Mounted on
nfs.exam.com:/bbs   44G   11G   34G  25% /var/www/html

   8、配置论坛服务器                                                                    

[root@node ~]# dnf install httpd php php-mysqlnd -y
[root@node ~]# cp Discuz_X3.5_SC_UTF8_20230520.zip /var/www/html/
[root@node ~]# cd /var/www/html/
[root@node  html]# ll
total 11500
-rw-r--r--. 1 nobody nobody 11775903 May 10 13:02 
Discuz_X3.5_SC_UTF8_20230520.zip
[root@node html]# unzip Discuz_X3.5_SC_UTF8_20230520.zip 
Archive: Discuz_X3.5_SC_UTF8_20230520.zip
 inflating: LICENSE                 
 inflating: qqqun.png               
   creating: readme/
 inflating: readme.html             
 inflating: readme/changelog.txt    
[root@node html]# cd upload/
[root@node upload]# chmod 777 data/ uc_server/ uc_client/ config/ -R
[root@node upload]# setsebool -P httpd_use_nfs 1
[root@node upload]# systemctl start --now httpd
[root@node upload]# firewall-cmd --permanent --add-service=http
success
[root@node upload]# firewall-cmd --reload 
success
[root@node ~]# setsebool -P httpd_can_network_connect_db 1

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

本站无任何商业行为
个人在线分享 » 2024真机项目
E-->