1)网关服务器:ens36:12.0.0.254/24,ens33:192.168.241.254/24;Server1:192.168.241.0/24;PC1和server2:自动获取IP;交换机无需配置。要求能够使用Xshell等远程工具登录Server1和网关服务器。
Sever的网卡调整设置
PC1的网卡设置
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0
setenforce: SELinux is disabled
[root@node2 ~]#hostname server1
[root@node2 ~]#su
[root@server1 ~]#systemctl stop firewalld
[root@server1 ~]#setenforce 0
[root@node3 ~]#hostname pc1
[root@node3 ~]#su
[root@pc1 ~]#systemctl stop firewalld
[root@pc1 ~]#setenforce 0
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0
[root@localhost ~]#cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]#ls
ifcfg-ens33 ifdown-ppp ifup-ib ifup-Team
ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-Team ifup-isdn ifup-wireless
ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global
ifdown-ib ifdown-tunnel ifup-plusb network-functions
ifdown-ippp ifup ifup-post network-functions-ipv6
ifdown-ipv6 ifup-aliases ifup-ppp
ifdown-isdn ifup-bnep ifup-routes
ifdown-post ifup-eth ifup-sit
[root@localhost network-scripts]#cp ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]#vim ifcfg-ens36
[root@localhost network-scripts]#vim ifcfg-ens33
[root@localhost network-scripts]#systemctl restart network
[root@localhost network-scripts]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:51:4b:b5 brd ff:ff:ff:ff:ff:ffinet 192.168.241.11/24 brd 192.168.241.255 scope global ens33valid_lft forever preferred_lft foreverinet6 fe80::de6f:32c8:5a64:a6b2/64 scope link valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000link/ether 52:54:00:53:c1:45 brd ff:ff:ff:ff:ff:ffinet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000link/ether 52:54:00:53:c1:45 brd ff:ff:ff:ff:ff:ff
5: ens36: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:51:4b:bf brd ff:ff:ff:ff:ff:ffinet 12.0.0.254/24 brd 12.0.0.255 scope global ens36valid_lft forever preferred_lft foreverinet6 fe80::8cb:b13b:40ac:6df1/64 scope link valid_lft forever preferred_lft forever
[root@node3 ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens33
[root@node3 ~]#systemctl restart network
2)网关服务器提供DHCP服务给PC1和server2分配对应网段的IP地址和DNS服务器地址(注意后面题目的需求)。
[root@localhost ~]#cd /etc/yum.repos.d/
[root@localhost yum.repos.d]#ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo epel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo
[root@localhost yum.repos.d]#mkdir bak
[root@localhost yum.repos.d]#mv *.repo bak/
[root@localhost yum.repos.d]#ls
bak
[root@localhost yum.repos.d]#vim local.repo[local]
name=local
baseurl=file:///mnt
gpgcheck=0[root@localhost yum.repos.d]#mount /dev/sr0 /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost yum.repos.d]#yum install dhcp -y
[root@localhost yum.repos.d]#systemctl start dhcpd
Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and "journalctl -xe" for details.
[root@localhost yum.repos.d]#cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
[root@localhost yum.repos.d]#cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost yum.repos.d]#vim /etc/dhcp/dhcpd.conf subnet 192.168.241.0 netmask 255.255.255.0 {range 192.168.241.20 192.168.241.50;option routers 192.168.241.11;
}subnet 12.0.0.0 netmask 255.255.255.0 {range 12.0.0.20 12.0.0.50;option routers 12.0.0.1;
}[root@localhost yum.repos.d]#systemctl start dhcpd
7-4修改为dhcp获取IP地址
[root@localhost ~]#systemctl restart network
3)server1服务器上创建密钥对并上传给网关服务器,并使server1的root用户可以使用root用户免交互登录网关服务器。
[root@node2 ~]#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:oxzlK2AzEXt6XPy7ksjeGwdX1BXtyJkyzhmFmqOYlbA root@node2.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| . .o o+|
| o.. .. o .|
| o .o+. o.o = |
| =E+o.+.+ = .|
| * ++S.o+ = |
| . *oo.= .+ |
| .+.o.o |
| oooo . |
| .. oo. |
+----[SHA256]-----+
[root@node2 ~]#ssh-copy-id -i .ssh/id_rsa.pub 192.168.241.11
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
The authenticity of host '192.168.241.11 (192.168.241.11)' can't be established.
ECDSA key fingerprint is SHA256:k/dmSIE+ic90gNaqecVvZT0PdW+9hJf9EwJQDXY1f7w.
ECDSA key fingerprint is MD5:e1:61:2b:5d:fe:10:a9:72:1f:c2:7e:2b:5b:51:f4:7c.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.241.11's password: _oo0oo_08888888088" . "88(| -_- |)0\ = /0___/'---'\___.' \\| |// './ \\||| : |||// \/_ ||||| -:- |||||- \| | \\\ - /// | || \_| ''\---/'' |_/ |\ .-\__ '-' __/-. /___'. .' /--.--\ '. .'___."" '< '.___\_<|>_/___.' >' "".| | : '- \'.;'\ _ /';.'/ - ' : | |\ \ '_. \_ __\ /__ _/ .-' / /====='-.____'.___ \_____/___.-'____.-'====='=---='^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^佛祖保佑 永无BUG 永不宕机Number of key(s) added: 1Now try logging into the machine, with: "ssh '192.168.241.11'"
and check to make sure that only the key(s) you wanted were added.
[root@node2 ~]#ssh 192.168.241.11
Last login: Sun Feb 25 13:42:09 2024 from 192.168.241.1_oo0oo_08888888088" . "88(| -_- |)0\ = /0___/'---'\___.' \\| |// './ \\||| : |||// \/_ ||||| -:- |||||- \| | \\\ - /// | || \_| ''\---/'' |_/ |\ .-\__ '-' __/-. /___'. .' /--.--\ '. .'___."" '< '.___\_<|>_/___.' >' "".| | : '- \'.;'\ _ /';.'/ - ' : | |\ \ '_. \_ __\ /__ _/ .-' / /====='-.____'.___ \_____/___.-'____.-'====='=---='^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^佛祖保佑 永无BUG 永不宕机
[root@localhost ~]#
4)server1服务器安装和启动httpd服务搭建Web网站,首页内容自定,但需要把server2的/share目录中的首页文件index.html,通过NFS挂载到server1的/var/www/html目录下使用。
[root@node2 ~]#yum install httpd -y
[root@node2 ~]#systemctl start httpd
[root@node2 ~]#curl 192.168.241.11
[root@node2 ~]#showmount -e 192.168.241.20
Export list for 192.168.241.20:
/share *
[root@node2 ~]#mount 192.168.241.20:/share /var/www/html
[root@node2 ~]#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 3.7G 47G 8% /
devtmpfs 897M 0 897M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.0M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 5.0G 179M 4.9G 4% /boot
tmpfs 183M 12K 183M 1% /run/user/42
tmpfs 183M 0 183M 0% /run/user/0
192.168.241.20:/share 50G 4.9G 46G 10% /var/www/html
[root@localhost ~]#mkdir /share
[root@localhost ~]#cd /share
[root@localhost share]#vim index.htmlcxk wby ctrl[root@localhost share]#systemctl start nfs
[root@localhost ~]#vim /etc/exports/share *[root@localhost ~]#exportfs -v
[root@localhost ~]#exportfs -r
exportfs: No options for /share *: suggest *(sync) to avoid warning
[root@localhost ~]#exportfs -v
/share <world>(ro,sync,wdelay,hide,no_subtree_check,sec=sys,secure,root_squash,no_all_squash)
[root@localhost ~]#systemctl start nfs
[root@localhost ~]#curl 192.168.241.22
cxk wby ctrl