关键字:kvm、libvirt、virt-manager、debian
时间:2018年8月

前言

libvirt是linux下管理虚拟化的一套工具。
virt-manager是基于libvirt的图形界面管理程序,可以管理本机的libvirt,也可以远程管理其他安装有libvirt的物理机。

环境

宿主机环境Debian 9,Gnome或其他图像界面。由于virt-manager为图形界面程序,所以必须安装图形界面才能使用。

安装

root@debian:# apt-get install virt-manager

注:virt-manager依赖libvirt相关包,因此libvirt会被自动安装。

配置

root@debian:~# vim /etc/network/interfaces.d/br0
auto br0
iface br0 inet static
	address 172.17.1.101/20
	gateway 172.17.0.1
	bridge_ports enp0s25
	bridge_waitport 0
	bridge_fd 0
:wq
root@debian:~# vim /etc/network/interfaces
...
source /etc/network/interfaces.d/*
...
auto lo
iface lo inet loopback

:wq
root@debian:~# systemctl restart network-manager
root@debian:~# vim /etc/libvirt/qemu.conf
...
#user = "root"
user = "root"
...
#group = "root"
group = "root"
...
:wq
root@debian:~# systemctl restart libvirtd

注意:
1、网卡须配置成bridge模式,否则虚拟机无法被局域网中其他主机ping通。
2、如果不修改qemu.conf文件中的user和group,在创建虚拟机时会出现’unsupported configuration: CPU mode ‘custom’ for x86_64 kvm domain on x86_64 host is not supported by hypervisor’。

图像界面使用

运行virt-manager。
创建虚拟机时,网卡设置时,“Network source”选择“Specify shared device name”,然后“Bridge name”填写“br0”。

shell使用

root@debian:~# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
'quit' to quit

virsh # help
virsh # list --all
virsh # start vm1
virsh # quit
root@debian:~#

关键字:ssh、证书、免密码

目标

server主机有james用户,client主机有john用户,在client主机上使用john用户通过ssh登录A主机的root用户。

配置

client主机设置

john@client:/# ssh-keygen -t rsa
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
john@client:/# scp ~/.ssh/id_rsa.pub james@server:~/.ssh/authorized_keys.john
...

注:执行ssh-keygen后,生成私钥存放id_rsa中,生成公钥存放在id_rsa.pub中。

server主机设置

jame@server:~# cat ~/.ssh/authorized_keys.john >> ~/.ssh/authorized_keys

注:私钥留给自己,公钥发给对方。

测试

john@client:/# ssh james@server
Last login...   --无需输入密码,root账号登录成功

关键字:lvs、dr、realserver
时间:2017年1月

#!/bin/bash
# description: Config realserver
LVS_VIP=192.168.2.5
/etc/rc.d/init.d/functions
case "$1" in
start)
/sbin/ifconfig lo:0 $LVS_VIP netmask 255.255.255.255 broadcast $LVS_VIP
/sbin/route add -host $LVS_VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $LVS_VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0