CentOS 7.5 kvm虚拟化管理平台WebVirtMgr部署

5,370次阅读
一条评论

共计 7305 个字符,预计需要花费 19 分钟才能阅读完成。

一、部署安装 KVM

#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 检查是否支持虚拟机

[root@localhost ~]# egrep '(vmx|svm)' --color=always /proc/cpuinfo

如果看不到 vmx, 说明不支持 VT 虚拟化技术

1.2 安装 kvm

[root@localhost ~]# yum install -y qemu-kvm libvirt libguestfs-tools virt-install virt-manager libvirt-python –y

1.3  启动与开机启动,查询

[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

[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

[root@localhost network-scripts]# systemctl restart libvirtd
[root@localhost network-scripts]# systemctl status libvirtd

1.6 测试

[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 查看网桥

[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 安装依赖包

[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 代码

[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

[root@localhost webvirtmgr]# ssh 192.168.199.148 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080

2.4 拷贝 web 到 相关目录

[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;

[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

# 编辑配置文件

[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 配置文件

[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 开机启动

[root@localhost nginx]#  service nginx restart
[root@localhost nginx]#  systemctl status nginx
[root@localhost nginx]#  chkconfig nginx on

2.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 授权

[root@localhost nginx]# chown -R nginx:nginx /var/www/webvirtmgr

2.8 设置 supervisor (如果 iptables 防火墙开启的话,就必须要开通 80、8000、6080 端口访问)

[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

# 检查

[root@localhost nginx]# vi /var/www/webvirtmgr/conf/gunicorn.conf.py    // 确保下面 bind 绑定的是本机的 8000 端口,这个在 nginx 配置中定义了,被代理的端口
bind = '127.0.0.1:8000'

# 重启服务、设置开机启动

[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 已经启动

[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/master2.3 访问地址:http://192.168.199.148/login/

CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署

CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署

CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署

错误解决方案

A. 登录后创建 TCP 连接时,如果出现以下错误:

unable to connect to server at '192.168.199.59:16509': Connection refused

解决方案如下:

修改文件 vi /etc/sysconfig/libvirtd,用来启用 tcp 的端口

[root@localhost nginx]# vi /etc/sysconfig/libvirtd
LIBVIRTD_CONFIG=/etc/libvirt/libvirtd.conf
LIBVIRTD_ARGS="--listen"

修改文件 vi /etc/libvirt/libvirtd.conf

[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

[root@localhost nginx]# service libvirtd restart

B. 如果出现 noVNC ready: native WebSockets, canvas rendering(如下图)

CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署

CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署

 

解决方案如下:(一般是 6080 端口没有放行的原因,记住,一定要放行 6080 与 8000 端口哦)

1.1 先确定是否有放行 6080 端口,如果没放行 6080 端口请先放行,然后进入控制台看看是否可以正常访问;

CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署

上图表示正常,如果还是不行请进入第 2 步

1.2 就是安装 novnc

[root@localhost nginx]# yum install novnc

 

 

 

 

 

打赏小哥

CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署 微信打赏 CentOS 7.5 kvm 虚拟化管理平台 WebVirtMgr 部署 支付宝打赏

正文完
 0
评论(一条评论)
2018-08-14 09:43:16 回复

看看怎么安装

     中国广西南宁市联通