在vm母盘中设定实验环境【RHEL】

目录

1、yum仓库

(1)RHEL9

(2)RHEL7

2、shell 脚本

(1)RHEL9

(2)RHEL7

3、清空历史命令


1、yum仓库

(1)RHEL9

[root@local ~]# mkdir /rhel9
[root@local ~]# mount /dev/sr0 /rhel9
[root@local ~]# vim /etc/rc.d/rc.local    # 将挂载命令写入开机自启动文件中
[root@local ~]# chmod +x /etc/rc.d/rc.local
[root@local ~]# cd /rhel9
[root@local rhel9]# ls
AppStream  EFI   extra_files.json  images    media.repo               RPM-GPG-KEY-redhat-release
BaseOS     EULA  GPL               isolinux  RPM-GPG-KEY-redhat-beta

[root@local yum.repos.d]# cat rhel9.repo 
[AppStream]
name=AppStream
baseurl=file:///rhel9/AppStream
gpgcheck=0

[BaseOS]
baseurl=file:///rhel9/BaseOS
gpgcheck=0

(2)RHEL7

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# touch local.repo    //建立本地源repo文件
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  local.repo 
[root@localhost yum.repos.d]# vi local.repo      //编辑本地源repo文件

//在local.repo中写入,保存并退出即可
[local.repo]
name=local.repo
baseurl=file:///mnt/
enable=1
gpgcheck=0

2、shell 脚本

(1)RHEL9

[root@localhost rhel9]# grubby --update-kernel ALL --args net.ifnames=0    # 设定网卡名称编号规范

[root@localhost rhel9]# grubby --update-kernel ALL --args selinux=0        # 设定selinux关闭

[root@localhost rhel9]# systemctl stop firewalld                           # 关闭防火墙 
[root@localhost rhel9]# systemctl mask firewalld                           # 锁定防火墙

[root@localhost yum.repos.d]# vmset.sh eth1 172.25.254.100 apache.zx.org # 使用范例
[root@local system-connections]# cat eth0.nmconnection 
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
address1=172.25.254.100/24,172.25.254.2
method=manual
dns=114.114.114.114;
[root@local system-connections]# cat /bin/vmset.sh
#!/bin/bash
rm -fr /etc/NetworkManager/system-connections/$1.nmconnection
cat > /etc/NetworkManager/system-connections/$1.nmconnection <<EOF
[connection]
id=$1
type=ethernet
interface-name=$1

[ipv4]
address1=$2/24,172.25.254.2
method=manual
dns=114.114.114.114;
EOF

chmod 600 /etc/NetworkManager/system-connections/$1.nmconnection
nmcli connection reload
nmcli connection up $1

hostnamectl hostname $3
cat > /etc/hosts <<EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
$2	$3
EOF

(2)RHEL7

[root@localhost ~]# grubby --update-kernel ALL --args net.ifnames=0    # 设定网卡名称编号规范

[root@localhost ~]# grubby --update-kernel ALL --args selinux=0        # 设定selinux关闭

[root@localhost ~]# systemctl stop firewalld                           # 关闭防火墙 
[root@localhost ~]# systemctl mask firewalld                           # 锁定防火墙
[root@nginx ~]# cat /bin/vmset.sh
#!/bin/bash
rm -fr /etc/sysconfig/network-scripts/ifcfg-$1
cat > /etc/sysconfig/network-scripts/ifcfg-$1 <<EOF
DEVICE=$1
ONBOOT=yes
BOOTPROTO=none
IPADDR=$2
PREFIX=24
GATEWAY=172.25.254.2
DNS1=114.114.114.114
NAME=$1

EOF

nmcli connection reload
nmcli connection up $1

hostnamectl set-hostname $3

cat > /etc/hosts <<EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
$2	$3
EOF

[root@nginx ~]# chmod +x /bin/vmset.sh
[root@nginx ~]# cat /etc/hosts

3、清空历史命令

[root@nginx ~]# history -c
[root@nginx ~]# > ~/.bash_history 
[root@nginx ~]# poweroff

 openEuler 的 shell 脚本配置部分同RHEL7大致一致。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值