栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

配置实验用的 Linux 虚拟机

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

配置实验用的 Linux 虚拟机

环境介绍

虚拟机软件:VirtualBox

Linux 发行版本:Ubuntu 20.04.4

为什么使用 VirtualBox ?

  1. 免费
  2. Windows 和 macOS 都有
模板机准备 初始化 root 密码
$ sudo passwd
连不上 VirtualBox 虚拟机

网络模式设置两个网卡,分别为 NAT 和 Host-Only

NAT 用于连外网,Host-Only 用于连内网

静态 IP

查看网卡信息

$ ip addr

enp0s3 可见是 dhcp 动态分配的,也就是上面的网卡 1

enp0s8 也就是网卡 2,没有分配 ip ,我们需要给网卡 2 设置静态 ip,通过他来内网通信

配置网卡

$ vim /etc/netplan/00-installer-config.yaml
network:
  ethernets:
    enp0s3:
      dhcp4: yes
    enp0s8:
      dhcp4: no
      addresses: [192.168.128.101/24]
      nameservers:
        addresses: [8.8.8.8]
  version: 2

应用网卡配置

$ netplan apply
配置主机名
$ vim /etc/hosts

192.168.128.101 node01
192.168.128.102 node02
192.168.128.103 node03

$ vim /etc/hostname

node01
配置 ssh

更改 ssh 配置文件

$ vim /etc/ssh/sshd_config
# 允许登录 root 用户
PermitRootLogin yes
# 允许密码登录
PasswordAuthentication yes

重启 ssh 服务

$ service ssh restart
更换阿里源
$ vim /etc/apt/sources.list
# 复制以下内容
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
$ apt update
多机

准备

上述模板机准备完毕后,关机。复制出多台机子,本文起三台。

复制虚拟机

注意:

  1. 生成新的 mac 地址
  2. 完全复制

更改 HostName 和 IP

详细配置参考上文

HostNameIP
node01192.168.128.101
node02192.168.128.102
node03192.168.128.103
免密登录

生成公私钥

# 默认位置在 ~/.ssh
$ ssh-keygen

id_rsa 是私钥,id_rsa.pub 是公钥

把生成的公钥复制给要登录的机子上 ~/ssh/authorized_keys

配置多个只要另起一行就行

分发脚本
$ vim /bin/xsync
#!/bin/bash
#1 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if((pcount==0)); then
echo no args;
exit;
fi

#2 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname

#3 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir

#4 获取当前用户名称
user=`whoami`

#5 循环,分发到 node01 ~ node03
for((i=1; i<=3; i++)); do
echo ------------------- node0$i --------------
        rsync -rvl $pdir/$fname $user@node0$i:$pdir
done
$ chmod +x /bin/xsync

所有机子间都必须配置免密登录

将分发脚本分发下去

$ xsync /bin/xsync
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/866603.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号