环境说明:centos 7 主机使用kvm创建openstack动态扩容根分区镜像。
安装kvm包
yum install -y qemu-kvm qemu-kvm-tools libvirt virt-manager virt-install libguestfs-tools
创建kvm网络环境
cat <<EOF | tee /etc/sysconfig/network-scripts/ifcfg-eth0 >> /dev/null
BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED=no
EOF
cat <<EOF | tee /etc/sysconfig/network-scripts/ifcfg-br0 >> /dev/null
TYPE=Bridge
BOOTPROTO=static
IPV4_FAILURE_FATAL=no
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
DNS1=223.5.5.5
EOF
systemctl restart network
上传centos ISO镜像
自行上传镜像到宿主机上。本教程将镜像上传到 /opt/image
目录。
创建qcow2文件
mkdir /opt/images
qemu-img create -f qcow2 /opt/images/Debian-10.9.0-amd64.qcow2 10G
启动kvm虚机
systemctl start libvirtd
virt-install --virt-type kvm --name Debian10 --ram 1024 --cdrom=/opt/image/debian-10.9.0-amd64-DVD-1.iso --disk path=/opt/images/Debian-10.9.0-amd64.qcow2 --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
安装系统自行决定怎么安装,分区最好手动分区。
安装好系统,是让reboot
重启系统。重启后kvm虚拟机不会启动系统。需要手动启动系统。
virsh list --all
virsh start Debian10
更改apt源
cat << EOF | sudo tee /etc/apt/sources.list >> /dev/null
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
EOF
安装vscode
wget https://az764295.vo.msecnd.net/stable/507ce72a4466fbb27b715c3722558bb15afa9f48/code_1.57.1-1623937013_amd64.deb
sudo dpkg -i code_1.57.1-1623937013_amd64.deb
rm -rf code_1.57.1-1623937013_amd64.deb
安装常用工具
sudo apt install -y vim curl telnet traceroute autocutsel ntp
sudo systemctl enable ntp
修改时间
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
sudo hwclock -w
安装vncserver
wget https://www.realvnc.com/download/file/vnc.files/VNC-Server-6.2.1-Linux-x64.deb
sudo dpkg -i VNC-Server-6.2.1-Linux-x64.deb
rm -rf VNC-Server-6.2.1-Linux-x64.deb
安装flameshop截图
sudo apt install -y flameshot
# 启动指令
/usr/bin/flameshot gui
设置快捷键
Setting - Shortcuts - Customer Shortcuts - Edit - NEW - Global Shortcut - Command/URL - Trigger(设置快捷键) 和 Action(设置命令)
安装搜狗输入法
sudo apt install -y fcitx fcitx-libs libfcitx-qt0
wget https://ime.sogouimecdn.com/202106250002/2613c0aff1bc1ab79199d2af3f89b3ff/dl/index/1612260778/sogoupinyin_2.4.0.3469_amd64.deb
sudo dpkg -i sogoupinyin_2.4.0.3469_amd64.deb
配置搜狗输入法时,需要注销重新登录。不然看不到搜狗输入法
配置搜狗输入法
fcitx-config-gtk3
修复vim复制粘贴的问题
cat << EOF | sudo tee -a /etc/vim/vimrc.local >>/dev/null
source /usr/share/vim/vim81/defaults.vim
let skip_defaults_vim = 1
if has('mouse')
set mouse=r
endif
EOF
sudo sed -i 's#set mouse=a#set mouse=r#' /usr/share/vim/vim81/defaults.vim
安装cloud-init
下载cloud-init包
sudo apt install -y gdisk cloud-init cloud-guest-utils qemu-guest-agent acpid
sudo systemctl enable qemu-guest-agent.service acpid.service
查看根分区的编号
$ mount |grep /dev/vd
/dev/vda3 on / type xfs (rw,relatime,attr2,inode64,noquota)
/dev/vda2 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
填写cloud-init配置
配置文件
/etc/cloud/cloud.cfg
。只修改下面的配置,其他保持不变。 如果想修改/etc/hosts模板的话,/etc/cloud/templates/hosts.发行版.tmpl