说明:内部转载自自己创作的语雀文档。🔱 Vagrant_KylinOS-10-SP2 · 语雀
1. 环境准备
已安装:
- MobaXterm
- VirtualBox(注意:重装VB后需要重新安装Vagrant)
- Vagrant
账户口令:root/Kylin123123
2. 虚拟机安装
2.1. 安装Vagrant插件
将 ${VAGRRANT_HOME}\embedded\gems 所有文件中的“https://rubygems.org”替换为“https://gems.ruby-china.com”,以加快Vagrant插件下载速度。
vagrant plugin list
# 集群主机名管理插件
vagrant plugin install vagrant-hostmanager
# guest addtions
vagrant plugin install vagrant-vbguest
# 目录共享插件
vagrant plugin install vagrant-bindfs
2.2. 导入基本操作系统镜像
# 查看box列表
vagrant box list
# 新增box
cd /cygdrive/e/learn_resource/tools/vagrant/box/KylinOS/
vagrant box add KylinOS_tmp Vagrant-Kylin-10-SP2.VirtualBox-original.box
vagrant box remove KylinOS_tmp
2.3. 编写VagrantFile
cd /cygdrive/d/boxes/kylin
vi Vagrantfile
内容如下:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
{
:name => "kylin10sp2base",
:eth1 => "192.168.56.201",
:mem => "12288",
:cpu => "6"
}
]
Vagrant.configure(2) do |config|
config.vm.box = "KylinOS_tmp"
# 第一次安装时请注释以下三行配置,配置ssh密码验证(sshd_config)后再打开
#config.ssh.username = 'root'
#config.ssh.password = 'Kylin123123'
#config.ssh.insert_key = true
# ssh config end
config.vm.box_check_update = false
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
# 禁用系统默认的共享目录
config.vm.synced_folder '.', '/vagrant', disabled: true
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--name", opts[:name]]
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
end
config.vm.network :private_network, ip: opts[:eth1]
end
end
end
注意:OB对CPU和内存要求较高,虚拟机需分配足够资源::mem => "12288"、:cpu => "6",否则可能导致无法正常创建OB。
2.4. 初始化虚拟机
# Cygwin终端 | MobaXterm本地终端
cd /cygdrive/d/boxes/kylin
vagrant up
# 登录虚拟机,如果ssh无法登录,可通过VBox进入
vagrant ssh
# 查看虚拟机运行状态
vagrant status
2.5. Vagrant配置更新
修改“D:\software\vagrant\boxs\boxes\KylinOS_tmp\0\virtualbox\box.ovf”,将“<AudioAdapter codec="AD1980" useDefault="true" driver="WAS" enabled="true" enabledOut="true"/>”修改为“<AudioAdapter codec="AD1980" useDefault="true" driver="Pulse" enabled="true" enabledOut="true"/>”。
更新前创建虚拟机报错如下:
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: [“import”, “-n”, “\\\\?\\D:\\software\\vagrant\\boxs\\boxes\\KylinOS_tmp\\0\\virtualbox\\box.ovf”]
Stderr: 0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Interpreting \\?\D:\software\vagrant\boxs\boxes\KylinOS_tmp\0\virtualbox\box.ovf…
VBoxManage.EXE: error: Error in (line 312) – Invalid value ‘WAS’ in AudioAdapter/@driver attribute.
VBoxManage.EXE: error: F:\tinderbox\win-6.0\out\win.amd64\release\obj\VBoxAPIWrap\ApplianceWrap.cpp[393] (long __cdecl ApplianceWrap::Interpret(void))
VBoxManage.EXE: error: Details: code E_FAIL (0x80004005), component ApplianceWrap, interface IAppliance, callee IAppliance
VBoxManage.EXE: error: Context: “Interpret” at line 352 of file VBoxManageAppliance.cpp
2.6. 禁用USB
VirtualBox上设置禁用USB(右键“设置/USB设备”,取消勾选“启用USB控制器”,之后点击“OK”即可),否则创建虚拟机报错如下:
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: [“startvm”, “9d8131a6-e482-4800-8180-8c709c371f30”, “–type”, “headless”]
Stderr: VBoxManage.EXE: error: Implementation of the USB 2.0 controller not found!
VBoxManage.EXE: error: Because the USB 2.0 controller state is part of the saved VM state, the VM cannot be started. To fix this problem, either install the ‘Oracle VM VirtualBox Extension Pack’ or disable USB 2.0 support in the VM settings.
VBoxManage.EXE: error: Note! This error could also mean that an incompatible version of the ‘Oracle VM VirtualBox Extension Pack’ is installed (VERR_NOT_FOUND)
VBoxManage.EXE: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
2.7. 系统用户密码更新
由于box操作系统用户密码遗失,可通过VirtualBox进行密码更新。
- VirtualBox启动虚拟机按
e,进入单用户模式。 - 如果页面提示
“Enter username”,则输入用户名和密码。(root/Kylin123123) - 找到
“linux /vmlinuz...............”所在行,在末尾添加命令:init=/bin/bash console=tty0,之后按ctrl+x或F10继续。
linux /vmlinuz-4.19.90-24.4.v2101.ky10.x86_64 root=/dev/mapper/\klas-root ro resume=/dev/mapper/klas-swap rd.lvm.lv=klas/root rhgb quiet crash\kernel=1024M,high [此处新增]
initrd /initramfs-4.19.90-24.4.v2101.ky10.x86_64.img
- 更新密码,之后重启系统。
passwd root
2.8. SSH登录配置
sudo chmod 766 /etc/ssh/sshd_config
sudo vi /etc/ssh/sshd_config
配置如下:
PasswordAuthentication yes ## 开启ssh密码登陆
PubkeyAuthentication yes ## 启用公钥私钥配对认证方式
PermitRootLogin yes ## 不限制登录方式
AuthorizedKeysFile .ssh/authorized_keys ## 公钥文件路径(和上面生成的文件同)
设置完之后记得重启SSH服务,才能使刚才设置有效。
/sbin/service sshd restart
# 或者
systemctl restart sshd.service
3. 系统基本设置
3.1. 配置源
sudo su
rm -f /var/run/yum.pid # 当出现"Another app is currently holding the yum lock; waiting for it to exit..."时执行
yum update
# 常用工具安装
yum install -y dos2unix
yum install -y lsof
yum install -y network-scripts
3.2. 防火墙设置
# 停止防火墙
sudo systemctl stop firewalld
# 禁用防火墙
sudo systemctl disable firewalld
# 查看防火墙状态
sudo systemctl status firewalld
3.3. 禁用系统安全机制
sudo vi /etc/selinux/config
SELINUX=disabled
注意:重启liunx系统后才生效。
3.4. 修改IP地址
- 修改IP。
ifconfig # 查询设备名称,如:enp0s8
vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
内容如下:
DEVICE=enp0s8
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.56.201
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
DNS1=8.8.8.8
DNS2=8.8.4.4
- 修改对应网卡的网关的配置文件。
vi /etc/sysconfig/network
内容如下:
NETWORKING=yes
HOSTNAME=kylin10sp2base
GATEWAY=192.168.56.1
- 重启网络服务。
systemctl restart network
systemctl status network
3.5. 主机列表配置
# 设置主机名(集群所有节点)
sudo vi /etc/hosts
配置如下:
127.0.0.1 localhost
# 注意:务必注释# 127.0.1.1 ${HOST_NAME}
# 本机内网IP建议配置于第一行(多个域名情况下)
192.168.56.201 kylin10sp2base
3.6. 基础目录
- **软件包目录:**软件安装包统一放置于
“/data/module/software/”目录下,组件安装后统一置于“/data/module/”。
sudo mkdir -p /data/module/software
sudo chmod -R 777 /data/module/software
4. 导出虚拟机
# 退出宿主机
vagrant halt
# 查看虚拟机名称(VagrantFile中box的名称:config.vm.hostname)
vboxmanage list vms
cd /cygdrive/e/learn_resource/tools/vagrant/box/KylinOS/
# 注意:--base后面指定的是虚拟机名称而不是box名称
vagrant package --base kylin10sp2base --output Vagrant-Kylin-10-SP2.VirtualBox-base.box