【kvm】CentOS 7.5 kvm虚拟化管理平台WebVirtMgr部署
2019年05月28日 13:55:18 作者:Jiaozn 分类:虚拟化 评论(0)一、部署安装KVM
1 2 3 4 5 6 7 | #close firewalld and NetworkManager [root@linux-node1 ~]# systemctl disable firewalld [root@linux-node1 ~]# systemctl disable NetworkManager #关闭SELinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 |
1.1 检查是否支持虚拟机
1 | [root@localhost ~]# egrep '(vmx|svm)' --color=always /proc/cpuinfo |
如果看不到vmx,说明不支持VT虚拟化技术
1.2 安装kvm
1 | [root@localhost ~]# yum install -y qemu-kvm libvirt libguestfs-tools virt-install virt-manager libvirt-python –y |
1.3 启动与开机启动,查询
1 2 3 4 5 6 7 8 | [root@localhost ~]# systemctl start libvirtd //启动 [root@localhost ~]# systemctl enable libvirtd //开机启动 [root@localhost ~]# systemctl is-enabled libvirtd //查看是否开机启动 enabled [root@localhost ~]# lsmod |grep kvm //查看KVM是否安装成功 kvm_intel 174841 0 kvm 578558 1 kvm_intel irqbypass 13503 1 kvm |
1.4 配置桥接网络br0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | [root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# vi ifcfg-br0 //新建文件ifcfg-br0 TYPE=Bridge DEVICE=br0 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.199.148 GATEWAY=192.168.199.1 NETMASK=255.255.255.0 DNS1=192.168.199.1 [root@localhost network-scripts]# vi ifcfg-ens33 //修改文件ifcfg-ens33 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none //这里修改为none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=e6111d0a-7674-4e60-b697-63a6b86d2cbf DEVICE=ens33 ONBOOT=yes BRIDGE=br0 //增加桥接br0 ZONE=public [root@localhost network-scripts]# systemctl restart network //重新启动网络 |
1.5 启动libvirt
1 2 | [root@localhost network-scripts]# systemctl restart libvirtd [root@localhost network-scripts]# systemctl status libvirtd |
1.6 测试
1 2 3 4 5 6 7 8 9 10 11 12 | [root@localhost network-scripts]# virsh -c qemu:///system list Id 名称 状态 ---------------------------------------------------- [root@localhost network-scripts]# virsh --version 3.9.0 [root@localhost network-scripts]# virt-install --version 1.4.3 [root@localhost network-scripts]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm [root@localhost network-scripts]# lsmod |grep kvm kvm_intel 174841 0 kvm 578558 1 kvm_intel irqbypass 13503 1 kvm |
1.7 查看网桥
1 2 3 4 | [root@localhost network-scripts]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000c29c84915 no ens33 virbr0 8000.5254004992ae yes virbr0-nic |
二、部署webvirtmgr
2.1 安装依赖包
1 2 3 4 5 | [root@localhost network-scripts]# yum -y install http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm [root@localhost network-scripts]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx [root@localhost network-scripts]# yum -y install gcc python-devel [root@localhost network-scripts]# pip install numpy //安装后这里要求更新 [root@localhost network-scripts]# pip install --upgrade pip |
2.2 从git-hub中下载相关的webvirtmgr代码
1 2 3 4 5 6 7 | [root@localhost network-scripts]# cd /usr/local/src/ [root@localhost src]# git clone git://github.com/retspen/webvirtmgr.git [root@localhost src]# cd webvirtmgr [root@localhost webvirtmgr]# pip install -r requirements.txt [root@localhost webvirtmgr]# ./manage.py syncdb [root@localhost webvirtmgr]# ./manage.py collectstatic [root@localhost webvirtmgr]# ./manage.py createsuperuser |
2.3 设置SSH
1 | [root@localhost webvirtmgr]# ssh 192.168.199.148 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080 |
2.4 拷贝web到 相关目录
1 2 | [root@localhost webvirtmgr]# mkdir -pv /var/www [root@localhost webvirtmgr]# cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr |
2.5 编辑nginx配置文件
#添加这行代码: include /etc/nginx/conf.d/*.conf;
1 2 3 4 5 | [root@localhost webvirtmgr]# mkdir -pv /var/www [root@localhost webvirtmgr]# cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr [root@localhost webvirtmgr]# cd /etc/nginx/ [root@localhost nginx]# mv nginx.conf /tmp [root@localhost nginx]# cp nginx.conf.default nginx.conf |
#编辑配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [root@localhost nginx]#vi nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; #添加这一行代码 # 中间万千代码忽略,记住只添加上边一行即可 } |
#添加 /etc/nginx/conf.d/webvirtmgr.conf 配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [root@localhost nginx]# vi /etc/nginx/conf.d/webvirtmgr.conf server { listen 80 default_server; server_name $hostname; #access_log /var/log/nginx/webvirtmgr_access_log; location /static/ { root /var/www/webvirtmgr/webvirtmgr; # or /srv instead of /var expires max; } location / { proxy_pass http://127.0.0.1:8000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-Proto $scheme; proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600; client_max_body_size 1024M; # Set higher depending on your needs } } |
#重启nginx服务 | 添加nginx开机启动
1 2 3 | [root@localhost nginx]# service nginx restart [root@localhost nginx]# systemctl status nginx [root@localhost nginx]# chkconfig nginx on |
2.6 修改防火墙规则
1 2 3 4 5 6 | #直接执行这行 [root@localhost nginx]# /usr/sbin/setsebool httpd_can_network_connect true #设置开机加载 [root@localhost nginx]# vi /etc/rc.local //在末尾加上下边这段 /usr/sbin/setsebool httpd_can_network_connect true |
2.7 授权
1 | [root@localhost nginx]# chown -R nginx:nginx /var/www/webvirtmgr |
2.8 设置 supervisor (如果iptables防火墙开启的话,就必须要开通80、8000、6080端口访问)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | [root@localhost nginx]# vi /etc/supervisord.d/webvirtmgr.ini [program:webvirtmgr] command=/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py directory=/var/www/webvirtmgr autostart=true autorestart=true logfile=/var/log/supervisor/webvirtmgr.log log_stderr=true user=nginx [program:webvirtmgr-console] command=/usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-console directory=/var/www/webvirtmgr autostart=true autorestart=true stdout_logfile=/var/log/supervisor/webvirtmgr-console.log redirect_stderr=true user=nginx |
#检查
1 2 | [root@localhost nginx]# vi /var/www/webvirtmgr/conf/gunicorn.conf.py //确保下面bind绑定的是本机的8000端口,这个在nginx配置中定义了,被代理的端口 bind = '127.0.0.1:8000' |
#重启服务、设置开机启动
1 2 3 4 5 6 | [root@localhost nginx]# cd /var/www/webvirtmgr [root@localhost webvirtmgr]# git pull [root@localhost webvirtmgr]# ./manage.py collectstatic [root@localhost webvirtmgr]# systemctl restart supervisord [root@localhost webvirtmgr]# systemctl status supervisord [root@localhost webvirtmgr]# systemctl enable supervisord.service 或 chkconfig supervisord on |
2.9 查看端口 备注:6080和8000已经启动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@localhost nginx]# netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:16509 0.0.0.0:* LISTEN 1206/libvirtd tcp 0 0 0.0.0.0:6080 0.0.0.0:* LISTEN 929/python2 tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 930/python2 tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 11489/qemu-kvm tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 11701/qemu-kvm tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 742/rpcbind tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1284/nginx: master tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1917/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1185/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1613/master tcp6 0 0 :::111 :::* LISTEN 742/rpcbind tcp6 0 0 :::22 :::* LISTEN 1185/sshd tcp6 0 0 ::1:25 :::* LISTEN 1613/master</code>2.3 访问地址:http://192.168.199.148/login/ |
错误解决方案
A.登录后创建TCP连接时,如果出现以下错误:
unable to connect to server at ‘192.168.199.59:16509’: Connection refused
解决方案如下:
修改文件vi /etc/sysconfig/libvirtd,用来启用tcp的端口
1 2 3 | [root@localhost nginx]# vi /etc/sysconfig/libvirtd LIBVIRTD_CONFIG=/etc/libvirt/libvirtd.conf LIBVIRTD_ARGS="--listen" |
修改文件vi /etc/libvirt/libvirtd.conf
1 2 3 4 5 6 7 | [root@localhost nginx]# vi /etc/libvirt/libvirtd.conf listen_tls = 0 listen_tcp = 1 tcp_port = "16509" listen_addr = "0.0.0.0" auth_tcp = "none" |
重新运行 service libvirtd restart
1 | [root@localhost nginx]# service libvirtd restart |
B.如果出现 noVNC ready: native WebSockets, canvas rendering(如下图)
解决方案如下:(一般是6080端口没有放行的原因,记住,一定要放行6080与8000端口哦)
1.1 先确定是否有放行6080端口,如果没放行6080端口请先放行,然后进入控制台看看是否可以正常访问;
上图表示正常,如果还是不行请进入第2步
1.2 就是安装 novnc
1 | [root@localhost nginx]# yum install novnc |
评论
发表评论