update
This commit is contained in:
parent
f46aff8c20
commit
39de3779f9
@ -13,30 +13,6 @@ categories: ["kvm", "container"]
|
||||
4核 | 8GB | 30GB | 30GB | Rocky9
|
||||
|
||||
### 操作系统配置
|
||||
- 禁用 selinux
|
||||
```BASH
|
||||
sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
|
||||
```
|
||||
|
||||
- 关闭并禁用防火墙(firewalld)
|
||||
```BASH
|
||||
systemctl stop firewalld
|
||||
systemctl disable firewalld
|
||||
```
|
||||
|
||||
- 同步时间,这里可以把 ntp.tencent.com 换成自己内网的时间服务器
|
||||
```BASH
|
||||
sed -i '/^pool/d' /etc/chrony.conf
|
||||
echo 'pool ntp.tencent.com iburst' >> /etc/chrony.conf
|
||||
systemctl restart chronyd
|
||||
```
|
||||
|
||||
- 安装 epel
|
||||
```BASH
|
||||
dnf install epel-release
|
||||
dnf makecache
|
||||
```
|
||||
|
||||
- 在 /etc/security/limits.conf 中追加如下配置
|
||||
```
|
||||
* soft nofile 1048576
|
||||
@ -58,6 +34,38 @@ categories: ["kvm", "container"]
|
||||
vm.max_map_count = 262144
|
||||
```
|
||||
|
||||
- 安装 chrony,配置时间同步
|
||||
|
||||
#### debian 系 linux
|
||||
- (推荐)安装 gnome 和 virt-manager,用来运行虚拟机桌面
|
||||
```BASH
|
||||
apt install gdm3 virt-manager gnome-terminal
|
||||
```
|
||||
|
||||
- 创建普通用户 user1,加入 sudo
|
||||
```BASH
|
||||
useradd -m user1
|
||||
passwd user1
|
||||
echo 'user1 ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/boya
|
||||
```
|
||||
|
||||
- 修改 gdm3 配置文件 /etc/gdm3/daemon.conf,配置用户自动登录
|
||||
```
|
||||
AutomaticLoginEnable = true
|
||||
AutomaticLogin = user1
|
||||
```
|
||||
|
||||
- 重启操作系统,进入桌面环境下,自动登录 user1 用户
|
||||
|
||||
#### redhat 系 linux
|
||||
- 禁用 selinux
|
||||
- 关闭并禁用防火墙(firewalld)
|
||||
- 安装 epel
|
||||
```BASH
|
||||
dnf install epel-release
|
||||
dnf makecache
|
||||
```
|
||||
|
||||
- 配置子用户
|
||||
```BASH
|
||||
echo root:1000000:1000000000 > /etc/subuid
|
||||
@ -67,12 +75,29 @@ categories: ["kvm", "container"]
|
||||
- 重启操作系统
|
||||
|
||||
### 安装 incus 环境
|
||||
- 安装 incus 包
|
||||
#### debian 系 linux
|
||||
- 安装 qemu-system 包
|
||||
```BASH
|
||||
apt install qemu-system-x86
|
||||
```
|
||||
|
||||
- 安装 nicus 包
|
||||
```BASH
|
||||
apt install incus
|
||||
```
|
||||
|
||||
- 把 user1 用户加入 incus-admin 组
|
||||
```BASH
|
||||
usermod -a -G incus-admin user1
|
||||
```
|
||||
|
||||
#### redhat 系 linux
|
||||
- 安装 incus 包,**目前测试了红帽8及其更高版本的衍生 linux 都无法启动 kvm 虚拟机**
|
||||
```BASH
|
||||
dnf -y copr enable ligenix/enterprise-qemu-wider
|
||||
dnf install lvm2 incus incus-tools
|
||||
# 如果要运行 kvm 虚拟机,还需要安装如下 qemu 包
|
||||
dnf install qemu-system-x86
|
||||
# 打算尝试虚拟机的可以安装 qemu-system 包
|
||||
#dnf install qemu-system-x86
|
||||
```
|
||||
|
||||
- 修改 incus 服务文件
|
||||
@ -86,13 +111,6 @@ categories: ["kvm", "container"]
|
||||
systemctl start incus
|
||||
```
|
||||
|
||||
- 增加清华 lxc 镜像源
|
||||
```BASH
|
||||
incus remote add tuna https://mirrors.tuna.tsinghua.edu.cn/lxc-images/ \
|
||||
--protocol=simplestreams --public
|
||||
incus remote list # 查看镜像源
|
||||
```
|
||||
|
||||
### 初始化 incus 单机环境
|
||||
- 初始化 incus
|
||||
```BASH
|
||||
@ -118,11 +136,11 @@ categories: ["kvm", "container"]
|
||||
|
||||
## 集群环境
|
||||
### 服务器
|
||||
主机名 | 服务器网卡IP | 集群网卡IP | 操作系统 | 数据盘 | /etc/hosts
|
||||
---- | ---- | ---- | ---- | ---- | ----
|
||||
incus1 | eth0: 192.168.1.1 | 10.10.10.1 | Rocky9 | /dev/sdb | 10.10.10.1 incus1
|
||||
incus2 | eth0: 192.168.1.2 | 10.10.10.2 | Rocky9 | /dev/sdb | 10.10.10.2 incus2
|
||||
incus3 | eth0: 192.168.1.3 | 10.10.10.3 | Rocky9 | /dev/sdb | 10.10.10.3 incus3
|
||||
主机名 | 服务器网卡IP | 集群网卡IP | 数据盘 | /etc/hosts
|
||||
---- | ---- | ---- | ---- | ----
|
||||
incus1 | eth0: 192.168.1.1 | 10.10.10.1 | /dev/sdb | 10.10.10.1 incus1
|
||||
incus2 | eth0: 192.168.1.2 | 10.10.10.2 | /dev/sdb | 10.10.10.2 incus2
|
||||
incus3 | eth0: 192.168.1.3 | 10.10.10.3 | /dev/sdb | 10.10.10.3 incus3
|
||||
|
||||
### 操作系统配置
|
||||
- [每台服务器的操作与单机环境完全一致](#操作系统配置)
|
||||
@ -130,7 +148,7 @@ incus3 | eth0: 192.168.1.3 | 10.10.10.3 | Rocky9 | /dev/sdb | 10.10.10.3 incus
|
||||
### 安装 incus 环境
|
||||
- [每台服务器的操作与单机环境完全一致](#安装-incus-环境)
|
||||
|
||||
### 创建网桥和 lvm 卷组
|
||||
### 创建网桥
|
||||
- **在每台服务器里执行下面操作**
|
||||
- 创建网桥 incusbr,连接服务器网卡 eth0,**注意此操作可能会导致服务器断网**
|
||||
```BASH
|
||||
@ -147,6 +165,8 @@ incus3 | eth0: 192.168.1.3 | 10.10.10.3 | Rocky9 | /dev/sdb | 10.10.10.3 incus
|
||||
nmcli c add type bridge-slave con-name incusbr-eth0 ifname eth0 master incusbr
|
||||
```
|
||||
|
||||
### 创建 lvm 卷组
|
||||
- **在每台服务器里执行下面操作**
|
||||
- 基于数据盘创建 lvm 卷组 incusvg
|
||||
```BASH
|
||||
pvcreate /dev/sdb
|
||||
@ -238,6 +258,14 @@ incus3 | eth0: 192.168.1.3 | 10.10.10.3 | Rocky9 | /dev/sdb | 10.10.10.3 incus
|
||||
---
|
||||
|
||||
## 简单使用
|
||||
### 配置镜像源
|
||||
- 增加清华镜像源
|
||||
```BASH
|
||||
incus remote add tuna https://mirrors.tuna.tsinghua.edu.cn/lxc-images/ \
|
||||
--protocol=simplestreams --public
|
||||
incus remote list # 查看镜像源
|
||||
```
|
||||
|
||||
### lxc 容器
|
||||
- 拉取 alpine lxc 镜像
|
||||
```BASH
|
||||
@ -268,12 +296,11 @@ incus3 | eth0: 192.168.1.3 | 10.10.10.3 | Rocky9 | /dev/sdb | 10.10.10.3 incus
|
||||
```
|
||||
|
||||
### qemu 虚拟机
|
||||
- Windows 客户机需要安装 xmanager 和 xshell
|
||||
- 用 xshell 连接 incus 服务器
|
||||
- 登录已安装 incus 的 debian 操作系统的普通用户(user1)下
|
||||
- 下载 RockyLinux8 操作系统镜像文件:Rocky-8.10-x86_64-minimal.iso
|
||||
- 创建 iso 存储卷
|
||||
```BASH
|
||||
incus storage volume import pool1 \
|
||||
sudo incus storage volume import pool1 \
|
||||
/root/Rocky-8.7-x86_64-minimal.iso \
|
||||
rocky8-iso-volume --type=iso
|
||||
# pool1: 存储池
|
||||
@ -283,24 +310,24 @@ incus3 | eth0: 192.168.1.3 | 10.10.10.3 | Rocky9 | /dev/sdb | 10.10.10.3 incus
|
||||
|
||||
- 创建一个空的虚拟机,并设置 cpu、内存和系统盘大小和 boot 优先级
|
||||
```BASH
|
||||
incus create vm1 --empty --vm -c limits.cpu=2 -c limits.memory=4GiB -d root,size=6GiB -s pool1
|
||||
sudo incus create vm1 --empty --vm -c limits.cpu=2 -c limits.memory=4GiB -d root,size=6GiB -s pool1
|
||||
# vm1:虚拟机名字
|
||||
# limits.cpu=2:虚拟机占用 2 核
|
||||
# limits.memory:虚拟机占用 4G 内存
|
||||
# root,size=6GiB:虚拟机中的系统盘设备名是 root,大小是 6G
|
||||
# pool1: 存储池
|
||||
|
||||
incus config device set vm1 root boot.priority=20
|
||||
sudo incus config device set vm1 root boot.priority=20
|
||||
# boot.priority=20:boot 优先级,数字越大,优先级越高
|
||||
|
||||
# 修改虚拟机配置
|
||||
#incus config set vm1 limits.cpu=4
|
||||
#incus config edit vm1
|
||||
#sudo incus config set vm1 limits.cpu=4
|
||||
#sudo incus config edit vm1
|
||||
```
|
||||
|
||||
- 为虚拟机增加 iso 存储卷,并设置 boot 优先级
|
||||
```BASH
|
||||
incus config device add vm1 iso-cd disk \
|
||||
sudo incus config device add vm1 iso-cd disk \
|
||||
pool=pool1 source=rocky8-iso-volume boot.priority=10
|
||||
# vm1:虚拟机名字
|
||||
# iso-cd:虚拟机中的 iso 只读盘设备名
|
||||
@ -309,20 +336,19 @@ incus3 | eth0: 192.168.1.3 | 10.10.10.3 | Rocky9 | /dev/sdb | 10.10.10.3 incus
|
||||
# boot.priority=10:boot 优先级,数字越大,优先级越高
|
||||
```
|
||||
|
||||
- 启动虚拟机,这里会调用 windows 客户机的 xmanager
|
||||
- 启动虚拟机
|
||||
```BASH
|
||||
incus start vm1 --console=vga
|
||||
sudo incus start vm1
|
||||
```
|
||||
|
||||
- 在弹出的窗口中开始安装 RockyLinux8
|
||||
- 安装完成(点击“重新启动”)后,窗口自动关闭,此时虚拟机正在重启中
|
||||
- 打开已运行虚拟机的 console 终端
|
||||
- 打开已运行虚拟机的 console 终端,此时会在 debian gnome 桌面中自动打开 remove-viewer
|
||||
```BASH
|
||||
incus console vm1 --type=vga
|
||||
sudo incus console vm1 --type=vga
|
||||
```
|
||||
|
||||
- 在 remote-viewer 窗口中开始安装 RockyLinux8
|
||||
- 系统安装完成后,虚拟机不再需要 iso 只读盘设备,可以卸载
|
||||
```BASH
|
||||
incus config device remove vm1 iso-cd
|
||||
sudo incus config device remove vm1 iso-cd
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user