學習 python 至今,一直是在 linux 上操做,感受仍是 linux 對 python 的支持更加友好,默認安裝了 python 的版本 2 和 3 。
爲了打造更好的 python 開發環境,我準備使用本身的 windows 辦公機器,利用 spice 的遠程鏈接特性,打造一個基於 centos 7.x 的虛擬機(系統爲 linuxmint 18.x 或 elementary os )開發環境。
再也不贅述。請自行谷歌......python
首先須要在宿主機上設置網橋,本文章的宿主機的系統是 Centos 7.x ,這是最關鍵的一步,不少人常常是死在這一步。linux
此處是以 eth0
網卡爲例,實際環境請替換爲本身的網卡名。網橋的名字建議設置爲 br0
。windows
# add bridge "br0" [root@ousikongjian ~]# nmcli c add type bridge autoconnect yes con-name br0 ifname br0 Connection 'br0' (0f4b7bc8-8c7a-461a-bff1-d516b941a6ec) successfully added. # set IP for br0 [root@ousikongjian ~]# nmcli c modify br0 ipv4.addresses 10.0.0.30/24 ipv4.method manual # set Gateway for br0 [root@ousikongjian ~]# nmcli c modify br0 ipv4.gateway 10.0.0.1 # set DNS for "br0" [root@ousikongjian ~]# nmcli c modify br0 ipv4.dns 10.0.0.1 # remove the current setting [root@ousikongjian ~]# nmcli c delete eth0 # add an interface again as a member of br0 [root@ousikongjian ~]# nmcli c add type bridge-slave autoconnect yes con-name eth0 ifname eth0 master br0 # restart [root@ousikongjian ~]# reboot
重啓以後,使用下面的命令。centos
[root@ousikongjian ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000 link/ether 00:0c:29:9f:9b:d3 brd ff:ff:ff:ff:ff:ff 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 22:f8:64:25:97:44 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 00:0c:29:9f:9b:d3 brd ff:ff:ff:ff:ff:ff inet 10.0.0.30/24 brd 10.0.0.255 scope global br0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe9f:9bd3/64 scope link valid_lft forever preferred_lft forever
至此,網橋已經設置成功。跨越這一步,將是康莊大道。網絡
[root@ousikongjian ~]# yum -y install qemu-kvm libvirt virt-install bridge-utils # make sure modules are loaded [root@ousikongjian ~]# lsmod | grep kvm kvm_intel 138567 0 kvm 441119 1 kvm_intel [root@ousikongjian ~]# systemctl start libvirtd [root@ousikongjian ~]# systemctl enable libvirtd
[root@ousikongjian ~]# yum -y install virt-manager
這個軟件安裝完成以後,你就可使用圖形化界面來安裝客戶機了。dom
Centos 7.x 默認安裝以後, /home 路徑分配的存儲空間最大,而 virt-manager 默認的 /var/lib/libvirt/images 路徑的空間每每不夠大,所以此處須要咱們在 /home 路徑下自定義設置存儲空間。tcp
至此,咱們已經把虛擬機建立完畢。能夠啓動該虛擬機,而後按照圖形界面安裝客戶機了。ide
[root@ousikongjian ~]# yum -y install spice-server spice-protocol
爲了讓 virt-viewer 可以遠程鏈接到客戶機,須要配置遠程鏈接的端口及可以訪問的 IP。oop
[root@ousikongjian ~]# virsh edit ousi-linuxmint # edit the configration of "ousi-linuxmint" <domain type='kvm'> <name>ousi-linuxmint</name> <uuid>b38a50ca-a1ae-4d37-ba10-caf1e05b43ce</uuid> <memory unit='KiB'>4194304</memory> <currentMemory unit='KiB'>4194304</currentMemory> <vcpu placement='static'>2</vcpu> . . . # add follows # set any password for "passwd=***" section # specify a uniq number for "sound" section "slot='0x06'" # the "slot='0x02'" in video section is fixed number for graphics <graphics type='spice' port='5900' autoport='no' listen='0.0.0.0' passwd='password'> <listen type='address' address='0.0.0.0'/> </graphics> # 主要是設置<graphics>的內容,若是不想再設置基於 virt-viewer 的密碼能夠刪除 passwd='password' <sound model='ich6'> # 客戶機若是是 linux,選擇 ich6 <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </sound> <video> <model type='qxl' ram='65536' vram='32768' heads='1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </memballoon> </devices> </domain> Domain ousi-linuxmint XML configuration edited. [root@ousikongjian ~]# virsh start ousi-linuxmint # start VM Domain ousi-linuxmint started
[root@ousikongjian ~]# firewall-cmd --add-port=5900/tcp --permanent [root@ousikongjian ~]# firewall-cmd --reload
爲了實現客戶機和宿主機之間的複製、粘貼功能,須要在客戶機上安裝 spice-vdagent。學習
[root@ousikongjian ~]# yum -y install spice-vdagent #基於紅帽的客戶機使用該命令
[root@ousikongjian ~]# apt-get -y install spice-vdagent #基於 debian 的客戶機使用該命令