模板虚拟机:
1.还原快照
2.构建Yum仓库
3.实现/dev/cdrom开机自动挂载
4./etc/fstab修改UUID为设备路径
5.设置主机名为server.tedu.cn
6.修改网卡命名规则,实现网卡名称为eth0
7.nmcli命令删除错误网络命名
8.nmcli添加新的网络命名,本名与外号一致
9.nmcli设置IP地址与子网掩码192.168.88.240/24
10.修改虚拟机网卡连接的接口,vmware选择vmnet1,kvm虚拟机选择private1
11.关闭机器进行克隆
虚拟机B:
1.修改IP地址192.168.88.2/24
2.主机名为pc2.tedu.cn
虚拟机C:
1.修改IP地址192.168.88.3/24
2.主机名为pc3.tedu.cn
1.图形操作:将光盘镜像文件放入虚拟机光驱设备
2.挂载光驱设备
[root@localhost ~]# mount /dev/cdrom /mydvd
[root@localhost ~]# ls /mydvd
3.书写客户端配置文件
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
[root@localhost ~]# vim /etc/yum.repos.d/mydvd.repo
[app]
baseurl=file:///mydvd/AppStream #指定仓库位置file://表示本地为服务端
gpgcheck=0 #不检测红帽签名信息
[base] #仓库的标识,不能重复
baseurl=file:///mydvd/BaseOS #指定仓库位置file://表示本地为服务端
gpgcheck=0 #不检测红帽签名信息
[root@localhost ~]# yum -y install tftp-server
4.完成开机自动挂载
[root@localhost ~]# blkid /dev/cdrom #查看 光驱设备文件系统类型
[root@localhost ~]# vim /etc/fstab #添加一行配置
/dev/cdrom /mydvd iso9660 defaults 0 0
[root@localhost ~]# umount /mydvd
[root@localhost ~]# mount -a #进行检测
[root@localhost ~]# ls /mydvd
[root@localhost ~]# yum -y install ftp #测试安装软件包
[root@localhost ~]# df -h /boot #查看设备挂载情况
[root@localhost ~]# blkid /dev/vda1
[root@localhost ~]# vim /etc/fstab #vmware虚拟机
/dev/sda1 /boot xfs defaults 0 0
[root@localhost ~]# vim /etc/fstab #KVM虚拟机
/dev/vda1 /boot xfs defaults 0 0
[root@localhost ~]# reboot #重启系统
[root@localhost ~]# yum repolist #检测yum仓库
Yum常见错误:清空/var/run/yum.pid文件内容
[root@localhost ~]# yum repolist
已加载插件:fastestmirror, langpacks
/var/run/yum.pid 已被锁定,PID 为 2446 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:PackageKit
内存: 33 M RSS (378 MB VSZ)
已启动: Fri May 13 09:37:12 2022 - 00:07之前
状态 :睡眠中,进程ID:2446
……
[root@localhost ~]# > /var/run/yum.pid #清空文件内容
[root@localhost ~]# yum clean all #清空yum缓存
[root@localhost ~]# yum repolist #列出仓库信息
[root@localhost ~]# hostnamectl set-hostname server.tedu.cn
[root@localhost ~]# cat /etc/hostname #设置永久主机名配置文件
server.tedu.cn
[root@localhost ~]# hostname
server.tedu.cn
开启一个新的终端查看提示符的变化
修改网卡命令规则(eth0、eth1、eth2……)
[root@localhost ~]# ifconfig | head -2
ens33: flags=4163 mtu 1500
ether 00:0c:29:8a:72:4f txqueuelen 1000 (Ethernet)
[root@localhost ~]# vim /etc/default/grub #内核引导文件
……..此处省略一万字
GRUB_CMDLINE_LINUX="……quiet net.ifnames=0 biosdevname=0"
……此处省略一万字
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg #重新生成网卡命名的规则
[root@localhost ~]# reboot #重启系统
[root@localhost ~]# ifconfig | head -2
eth0: flags=4163 mtu 1500
inet 192.168.81.132 netmask 255.255.255.0 broadcast 192.168.81.255
内核指定:网卡名eth0
nmcli命令的使用:必须要使用nmcli命令的网卡命名
nmcli方式:原则是必须利用nmcli自己的命名,才能进行网络IP地址的设置
网卡命名: 系统命名 eth0 nmcli自己的命名
Linux系统内核将网卡命名成eth0,nmcli必须在为eth0网卡再起一个名字
规则:网卡的本名是什么,nmcli起的外号就是什么
[root@localhost ~]# nmcli connection show #查看网络命名的链接
nmcli命令的网卡命名,删除错误网卡命名
KVM虚拟机:
[root@server ~]# nmcli connection show #查看
[root@server ~]# nmcli connection delete enps0
[root@server ~]# nmcli connection show #查看
VMware虚拟机:
[root@server ~]# nmcli connection show #查看
[root@server ~]# nmcli connection delete ens160
[root@server ~]# nmcli connection show
[root@server ~]# nmcli connection show
nmcli命令的网卡命名,添加新的网络命名
[root@server ~]# nmcli connection add type ethernet ifname eth0 con-name eth0
解析: nmcli connection 添加 类型 以太网设备
网卡设备名为eth0 nmcli命令的命名为eth0
[root@server ~]# nmcli connection show
[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 #简单查看生成的网卡配置文件内容
利用nmcli修改IP地址、子网掩码、网关地址
[root@server ~]# nmcli connection modify eth0
ipv4.method manual
ipv4.addresses 192.168.88.77/24
ipv4.gateway 192.168.88.200
autoconnect yes
命令解析:
[root@server ~]# nmcli connection 修改 外号
ipv4.方法 手工配置
ipv4.地址 192.168.88.77/24
ipv4.网关 192.168.88.200
每次开机自动启用以上所有参数
[root@server ~]# nmcli connection up eth0 #激活
[root@server ~]# ifconfig | head -2
[root@server ~]# route -n #查看网关地址信息(了解)
[root@server ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
.....此处省略一万字......
IPADDR=192.168.88.240
PREFIX=24
GATEWAY=192.168.88.222
[root@server ~]# ifdown eth0 #停用设备(名字为网卡实际名字)
成功断开设备 'eth0'。
[root@server ~]# ifup eth0 #启用设备(名字为网卡实际名字)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/9)
[root@server ~]# ifconfig | head -2
•SSH协议,Secure Shell
软件包的安装
[root@localhost ~]# rpm -qa | grep openssh
openssh-askpass-8.0p1-13.el8.x86_64
openssh-8.0p1-13.el8.x86_64
openssh-clients-8.0p1-13.el8.x86_64
openssh-server-8.0p1-13.el8.x86_64
[root@server ~]#ls /usr/sbin/sshd#提供远程管理功能的程序
/usr/sbin/sshd
[root@server ~]# pgrep -l sshd #搜索sshd进程
1181 sshd
模板虚拟机:
[root@server /]# ssh [email protected]
………necting (yes/no)? yes
[email protected]'s password: #输入密码
[root@pc2 ~]# touch /root/hahaxixi.txt
[root@pc2 ~]# exit
登出
Connection to 192.168.88.2 closed.
[root@server /]# cat /root/.ssh/known_hosts #记录曾经远程管理的机器
scp [-r] 用户名@服务器:路径 本地路径
scp [-r] 本地路径 用户名@服务器:路径
虚拟机A:
[root@localhost ~]# scp /etc/passwd [email protected]:/root
[root@localhost ~]# scp -r /home [email protected]:/root
[root@localhost ~]# scp [email protected]:/etc/shadow /mnt
虚拟机B:
[root@localhost ~]# ls /root
真机上定义永久别名
[root@localhost ~]# vim /root/.bashrc
alias goa='ssh [email protected]'
alias gob='ssh [email protected]'
alias goc='ssh [email protected]'
开启新的终端进行验证
虚拟机A:
1.生成公钥(锁)与私钥(钥匙)进行验证
[root@server ~]# ssh-keygen #一路回车
…….save the key (/root/.ssh/id_rsa): #回车 设置默认保存位置
……..assphrase): #回车 设置密码为空
…….. again: #回车 设置密码为空
[root@server ~]# ls /root/.ssh/
id_rsa(私钥) id_rsa.pub(公钥) known_hosts
2.虚拟机A将公钥(锁)传递给虚拟机B
[root@server ~]# ssh-copy-id [email protected]
[root@server ~]# ssh [email protected] #测试无密码
[root@pc2 ~]# exit
登出
Connection to 192.168.88.2 closed.
[root@server ~]#
虚拟机B
[root@pc2 ~]# ls /root/.ssh/
authorized_keys(别的机器传递过来的公钥) known_hosts
[root@pc2 ~]#