VMWare 虚拟机创建 + 初始化

这篇具有很好参考价值的文章主要介绍了VMWare 虚拟机创建 + 初始化。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

概述

1. VMware创建虚拟机

2. IP 配置

nmtui

nmcli

3. Yum 源配置

光盘的Packages作为Yum源

配置开机自动挂载(光盘)

配置私有Yum仓库

跟新私有yum仓库

 报错和修复

4. 文件共享系统配置

跟新配置文件/etc/hosts + /etc/yum.repo.d/ftp.repo

 同步配置文件

测试yum私有仓库

5. Ansible 安装配置

 ssh 配置

hostlist 配置

ansible.cfg

6. init.yaml == 系统初始化脚本

command

7. sudo 提权


概述

创建虚拟机,从新构建项目

1. VMware创建虚拟机

2. IP 配置

3. Yum 源配置

4. 文件共享系统配置

5. Ansible 安装配置

6. 系统初始化脚本

1. VMware创建虚拟机

虚拟机配置

VMWare 虚拟机创建 + 初始化VMWare 虚拟机创建 + 初始化VMWare 虚拟机创建 + 初始化VMWare 虚拟机创建 + 初始化VMWare 虚拟机创建 + 初始化

VMWare 虚拟机创建 + 初始化

 (45条消息) VMware Workstation 网络备忘 + 集群规模_HJJ-DREAMER的博客-CSDN博客

2. IP 配置

nmtui

nmtui

VMWare 虚拟机创建 + 初始化VMWare 虚拟机创建 + 初始化VMWare 虚拟机创建 + 初始化

 VMWare 虚拟机创建 + 初始化

 使用xshell或其他软件验证

VMWare 虚拟机创建 + 初始化

nmcli

# 查看链接状态
nmcli connection show

# 修改现有网络配置ens35
nmcli connection modify ens35 ipv4.method manual ipv4.addresses 192.168.164.10/24 connection.autoconnect yes

# 启动ip网段
nmcli connection up ens35

# 关闭ip网段
nmcli connection up ens33

VMWare 虚拟机创建 + 初始化

连通性测试

VMWare 虚拟机创建 + 初始化

3. Yum 源配置

光盘的Packages作为Yum源

VMWare 虚拟机创建 + 初始化

# 备份已有yum仓库的配置
cd /etc/yum.repos.d/    # 进入仓库

# 备份配置
mkdir bakup ; mv ./Cent* ./bakup/

VMWare 虚拟机创建 + 初始化

# 挂载光盘
mount /dev/cdrom /mnt

# 更新配置
cat > /etc/yum.repos.d/dvd.repo << EOF
[centos7-dvd-repo]
name=centos7
baseurl=file:///mnt
enabled=1
gpgcheck=1
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
EOF

VMWare 虚拟机创建 + 初始化

# YUM 源更新
yum clean all   # 清理所有缓存
yum makecache   # 创建缓存
yum update      # 升级linux 系统
yum repolist    # 验证仓库信息

# 安装测试
yum install -y net-tools lftp rsync psmisc vim-enhanced tree vsftpd  bash-completion createrepo lrzsz iproute zip unzip yum-utils wget

# 卸载不必要程序,系统优化
yum remove -y postfix at audit kexec-tools firewalld-*

# 更新/etc/hosts文件
cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.164.10          orgin
192.168.164.16          reporsitory
192.168.164.11          master01
192.168.164.12          master02
192.168.164.13          master03
192.168.164.14          node04
192.168.164.15          node05
192.168.164.17          node07
192.168.164.51          db01
192.168.164.52          db02
192.168.164.53          db03
192.168.164.54          db04
192.168.164.55          db05
192.168.164.56          db06
192.168.164.26          node6

# 最后重启服务器
reboot
常用软件
名称 作用 备忘
net-tools 用于管理网络的工具
lftp 命令行界面的 FTP 客户端软件
rsync 可实现全量及增量(差异化备份)的本地或远程数据同步备份的优秀工具
psmisc 进程管理软件包套装
vim-enhanced vim
tree 树形结构列出指定目录下的所有内容
vsftpd 建构一个以安全为重的 FTP 服务器
bash-completion bash 自动补全
createrepo 用于更新已有的yum仓库
lrzsz 可拖拽上传下载linux代码到windows
iproute 一个网络管理工具包合集
yum-utils yum的工具包集合
wget 下载
zip unzip zip 压缩包的解压和压缩

配置开机自动挂载(光盘)

# 查看光驱设备文件系统类型
blkid  /dev/cdrom

# 追加 /etc/fstab 下面的配置
echo "/dev/cdrom   /mnt    iso9660    defaults   0  0"  >> /etc/fstab
cat /etc/fstab

# 挂载检测
umount /mnt
mount  -a
ls   /mnt

VMWare 虚拟机创建 + 初始化

配置私有Yum仓库

# 创建 /var/ftp/localrepo/centos7 
mkdir -p /var/ftp/localrepo/centos7 

# 将光盘挂载到 /var/ftp/localrepo/centos7 
echo "/dev/cdrom   /var/ftp/localrepo/centos7    iso9660    defaults   0  0"  >> /etc/fstab

# 修改配置
cat /etc/yum.repos.d/dvd.repo
[centos7-dvd-repo]
name=centos7
baseurl=file:///var/ftp/localrepo/centos7
enabled=1
gpgcheck=0

# 更新yum源
yum clean all && yum makecache && yum repolist


# 开机自启动 vsftpd
systemctl enable --now vsftpd

# 初始化私有镜像仓库
createrepo --update /var/ftp/localrepo
ls /var/ftp/localrepo

VMWare 虚拟机创建 + 初始化

跟新私有yum仓库

# 解压文件
tar xvf ansible_centos7.tar.gz

# 配置私有仓库
cat /etc/yum.repos.d/ftp.repo
[ftp-yum-repo]
name=ansible
baseurl=ftp://192.168.164.16/localrepo/ansible
enabled=1
gpgcheck=0

# 更新仓库
createrepo --update /var/ftp/localrepo/ansible
yum clean all && yum makecache && yum repolist
ls /var/ftp/localrepo/ansible

VMWare 虚拟机创建 + 初始化

 报错和修复

failure: repodata/repomd.xml from ftp-yum-repo: [Errno 256] No more mirrors to try.
ftp://192.168.164.16/localrepo/ansible/repodata/repomd.xml: [Errno 14] FTP Error 550 - Server denied you to change to the given directory

报错原因是错误指定rpm包的位置 ( /var/ftp/localrepo )

正确指定rpm的位置是 /var/ftp/localrepo/ansible

正确更新yum仓库的命令是 createrepo --update /var/ftp/localrepo/ansible

VMWare 虚拟机创建 + 初始化

详细报错

[root@reporsitory localrepo]# createrepo --update /var/ftp/localrepo
Spawning worker 0 with 2 pkgs
Spawning worker 1 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@reporsitory localrepo]# yum clean all && yum makecache && yum repolist
已加载插件:fastestmirror
正在清理软件源: centos7-dvd-repo ftp-yum-repo
Cleaning up list of fastest mirrors
已加载插件:fastestmirror
Determining fastest mirrors
centos7-dvd-repo                                                           | 3.6 kB  00:00:00
ftp://192.168.164.16/localrepo/ansible/repodata/repomd.xml: [Errno 14] FTP Error 550 - Server denied you to change to the given directory
正在尝试其它镜像。


 One of the configured repositories failed (ansible),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=ftp-yum-repo ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable ftp-yum-repo
        or
            subscription-manager repos --disable=ftp-yum-repo

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=ftp-yum-repo.skip_if_unavailable=true

failure: repodata/repomd.xml from ftp-yum-repo: [Errno 256] No more mirrors to try.
ftp://192.168.164.16/localrepo/ansible/repodata/repomd.xml: [Errno 14] FTP Error 550 - Server denied you to change to the given directory

4. 文件共享系统配置

跟新配置文件/etc/hosts + /etc/yum.repo.d/ftp.repo

# 更新配置文件
]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.164.10          origin
192.168.164.16          reporsitory
192.168.164.11          master01
192.168.164.12          master02
192.168.164.13          master03
192.168.164.14          node04
192.168.164.15          node05
192.168.164.17          node07
192.168.164.51          db01
192.168.164.52          db02
192.168.164.53          db03
192.168.164.54          db04
192.168.164.55          db05
192.168.164.56          db06
192.168.164.26          node6

]# cat /etc/yum.repos.d/ftp.repo
[ftp-yum-repo]
name=ansible
baseurl=ftp://192.168.164.16/localrepo/ansible
enabled=1
gpgcheck=0

[centos7-yum-repo]
name=centos7
baseurl=ftp://192.168.164.16/localrepo/centos7
enabled=1
gpgcheck=0

 同步配置文件

scp /etc/yum.repos.d/ftp.repo root@reporsitory:/etc/yum.repos.d/ftp.repo

rsync -av /etc/hosts root@origin:/etc/hosts

linux上的rsync命令详解 - 简书 (jianshu.com)

Linux scp命令 - 知乎 (zhihu.com)

测试yum私有仓库

yum clean all && yum makecache && yum repolist
sudo yum -y install ansible

VMWare 虚拟机创建 + 初始化

5. Ansible 安装配置

 ssh 配置

# 安装系统
yum -y install ansible
mkdir -p ~/ansible

# 配置ssh服务
ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa

# 更新权限
chmod 0400 /root/.ssh/id_rsa

# 循环传输公钥
for ip in 192.168.164.{10..17} 192.168.164.{51..56}
do
  ssh-copy-id -f -o stricthostkeychecking=no -i /root/.ssh/id_rsa.pub root@${ip}
done

hostlist 配置

ansible]# cat hostlist
[k8s]
192.168.164.[11:15]
192.168.164.17

[k8sm]
192.168.164.[11:13]

[k8ss]
192.168.164.[14:15]
192.168.164.17

[mysql]
192.168.164.[51:53]

[mysqlslave]
192.168.164.[52:53]

[redis]
192.168.164.[51:56]

[redismaster]
192.168.164.[51:53]

[redisslave]
192.168.164.[54:56]

[origin]
192.168.164.10

[repo]
192.168.164.16

ansible.cfg

Ansible的配置文件 — 国内最专业的Ansible中文官方学习手册

]# cat ansible.cfg
[defaults]
inventory   = /home/junjie/ansible/hostlist
roles_path  = /home/junjie/ansible/roles
host_key_checking = False

6. init.yaml == 系统初始化脚本

---
- name: init
  hosts: k8s,redis
  tasks:
  - name: delete the error dir
    file:
      path: /etc/yum.repos.d
      state: absent
  - name: cp the ftp.repo
    copy:
      src: /etc/yum.repos.d/
      dest: /etc/yum.repos.d
      force: yes
      mode: "0755"
  - name: cp the hosts
    copy:
      src: /etc/hosts
      dest: /etc/hosts
      mode: "0644"
  - name: init the yum repo
    shell: yum clean all && yum makecache && yum repolist
  - name: install softwares
    yum:
      name: zip,unzip
      state: present
  - name: remove softwares
    yum:
      name: postfix,at,audit,kexec-tools,firewalld
      state: absent
  - name: create ssh key
    shell: "ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa"
  - name: chmod ssh file
    shell: "chmod 0400 /root/.ssh/id_rsa"

VMWare 虚拟机创建 + 初始化

command

# 查看命令帮助
ansible-doc yum

# 检查
ansible-playbook file.yml --syntax-check    #检查yaml文件的语法是否正确
ansible-playbook file.yml --list-task       #检查tasks任务
ansible-playbook file.yml --list-hosts      #检查生效的主机

# 执行命令
ansible-playbook init.yaml

ansible  k8s,redis -m   command   -a   "ls -l /etc/yum.repo.d"

7. sudo 提权

sudo命令和sudoers文件详解 - 简书 (jianshu.com)文章来源地址https://www.toymoban.com/news/detail-447415.html

到了这里,关于VMWare 虚拟机创建 + 初始化的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【源码解析】聊聊SpringBean是如何初始化和创建

    我们知道通过类进行修复不同的属性,比如单例、原型等,而具体的流程是怎么样的呢,这一篇我们开始从源码的视角分析以下。 在刷新容器中有一个方法,其实就是 Bean创建的过程。 而BeanFactory中 preInstantiateSingletons是初始化所有的bean对象的核心流程。 而这里通过去遍历所

    2024年02月05日
    浏览(32)
  • Java创建数组、赋值的四种方式,声明+创建+初始化 详解

    以int数据类型为例 注意: new 数据类型[]{},其中花括号可以省去,但要在[ ]中填写数组的个数; 创建多维数组时 new后面第一个方括号中的元素数量不能省略 1、一维数组的声明方式: type[] arrayName; 或 type arrayName[]; 推荐使用第一种格式,因为第一种格式具有更好的可读性,表

    2024年04月11日
    浏览(45)
  • 虚拟机安装 Ubuntu22.04 后的一些初始化配置

    server版 版本详情: 参考: 官方文档 虚拟机包含两个网络,网络地址转换用于访问互联网,启用DHCP,仅主机网络用于内部通信,指定静态IP地址,此版本中使用netplan作为默认的网络管理工具,执行命令 sudo vim /etc/netplan/00-installer-config.yaml 修改配置文件: 修改后执行命令 su

    2024年04月26日
    浏览(33)
  • 第3章 创建项目并初始化业务数据(过程记录)

    公用的声明、依赖、插件 properties 声明 log4g :处理日志的框架(日志的具体实现) sel4g :简单日志门面(简单日志的接口) mongodb-spark :MongoDB和Spark的接口 casbah :MongoDB在scala上的Driver(最新的有MongoScalaDriver) redis、kafka、spark、scala jblas:java线性代数库(矩阵运算) depen

    2024年02月13日
    浏览(32)
  • 用React给XXL-JOB开发一个新皮肤(二):目录规划和路由初始化

    一. 简述 二. 目录规划 三. Vite 配置 3.1. 配置路径别名 3.2. 配置 less 四. 页面 4.1. 入口文件 4.2. 骨架文件 4.3. 普通页面 五. 路由配置 六. 预览启动 上一篇文章我们介绍了项目初始化,此篇文章我们会先介绍下当前项目的目录规划,接着对 vite 配置以便我们后续的开发,最后会根

    2024年01月20日
    浏览(37)
  • Git第二讲 使用Git命令创建和初始化仓库

    在使用Git之前,您需要创建并初始化一个Git仓库。这个仓库将用于存储您的项目文件并跟踪其版本。 首先,让我们创建一个全新的Git仓库。请按照以下步骤进行操作: 打开命令行终端或Git Bash,并导航到您想要存储项目的目录。 运行以下命令来初始化一个新的Git仓库: 这将

    2024年02月11日
    浏览(32)
  • 顺序表创建,初始化,赋值,取值,查找,插入与删除(附小例题)

    由n(n≥0)个数据结构相同的元素构成的有限序列。 1)除了第一个元素外,结构中的每一个数据元素均只有一个前驱 2)除了最后一个元素外,结构中的每一个数据元素均只有一个后驱 用一组地址 连续的存储单元依次 存储线性表的数据元素。 优点 : 随机存储 缺点 :在做插

    2024年02月07日
    浏览(32)
  • 线性表的基本操作(初始化、创建、增、删、查)

    目录 顺序表 顺序表的定义和初始化 顺序表的基本操作 1.求表长 2.判空操作 3.创建顺序表 4.输出操作 5.插入操作 6.删除操作 7.按位查找操作 8.按值查找操作 单链表 单链表的定义 单链表的初始化 求表长 判空操作  尾插法建立单链表 头插法建立单链表 输出操作 前插操作 后插

    2024年02月08日
    浏览(33)
  • 从内核源码看 slab 内存池的创建初始化流程

    在上篇文章 《细节拉满,80 张图带你一步一步推演 slab 内存池的设计与实现 》中,笔者从 slab cache 的总体架构演进角度以及 slab cache 的运行原理角度为大家勾勒出了 slab cache 的总体架构视图,基于这个视图详细阐述了 slab cache 的内存分配以及释放原理。 slab cache 机制确实比

    2023年04月12日
    浏览(41)
  • C语言——结构体类型(一)【结构体定义,创建,初始化和引用】

    📝前言: 在实际编程过程中,我们可能会希望把一些关联的数据存放在一起,这样方便我们使用。但是这些数据的类型有时候并不一致,例如一个学生的信息:有名字(字符串),有年龄(整数),性别(字符)······这时候,我们就可以使用 自定义类型——结构体类型

    2024年02月03日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包