[Kvm] study notes 9: WebVirtMgr foundation and installation

 Contents
- 1. Introduction
- 2. webvirtmgr Introduction
- 3. webvirtmgr deployment practices
    - webvirtmgr Host Configuration 3.1
    - 3.2 kvm node node configuration
    - 3.3 kvm console and node configuration interaction

 

1 Introduction

Previous: [KVM] oVirt foundation and installation describes the installation and basic use of ovirt herein, this presentation is more lightweight webvirtmgr, compared ovirt, webvirtmgr is even more lightweight and simple to use.

ovirt more suitable for large-scale clusters, such as virtual machine thousands of clusters, and between 10-200 For virtual machine, using webvirtmgr will be more convenient.

 

2. webvirtmgr Profile

webvirtmgr Features

Simple, easy to use
to manage kvm libvirt API interface through the
offer of virtual machine lifecycle management

 

WebVirtMgr function

Host management supports the following features:

CPU utilization
Memory utilization
network resource pool management
storage resource pool management
virtual machine image
clone a virtual machine
snapshot management
log management
virtual machine migration

 

Virtual Machine Manager supports the following features:

CPU utilization
Memory utilization
Disc Manager
Off / On / pause the virtual machine
to install a virtual machine
VNC console connection
to create a snapshot

 

3. webvirtmgr deployment practices

We have also in line with webvirtmgr, here set up to do the next record in a test environment, the environment is as follows:

First, selinux and firewalls are turned off.

Modify the host name:

[[email protected] ~]#hostnamectl set-hostname webvirtmgr.super.com
[[email protected] ~]#echo -e "192.168.118.14    webvirtmgr.super.com\n192.168.118.15    node1.super.com" >> /etc/hosts

[[email protected] ~]#hostnamectl set-hostname node1.super.com
[[email protected] ~]#echo -e "192.168.118.14    webvirtmgr.super.com\n192.168.118.15    node1.super.com" >> /etc/hosts

 Close NetworkManager service, or when the back by virsh create a bridge device, creates failure.

#systemctl stop  NetworkManager ; systemctl disable NetworkManager

 

3.1 Host Configuration webvirtmgr

Enable source epel, I usually use Ali cloud centos source and epel source, see `http: // mirrors.aliyun.com / help / centos`,` http: // mirrors.aliyun.com / help / epel`

#wget Precinct /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
#wget /etc/yum.repos.d/epel Precinct. repo http://mirrors.aliyun.com/repo/epel-7.repo

First, install the necessary number of packages

[[email protected] ~]#yum install gcc python-devel openssl-devel -y
[[email protected] ~]#yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx

 

Configuring pip domestic sources, foreign pip default too slow.

[[email protected] ~]#mkdir -pv ~/.pip/
mkdir: created directory ‘/root/.pip/’
[[email protected] ~]#cat ~/.pip/pip.conf
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

 
Numpy module installation

[[email protected] ~]#pip install numpy

 

Local python 2.7 is the latest version of numpy does not support, which will need to manually download and install.

Download Link: https://pypi.tuna.tsinghua.edu.cn/packages/c4/33/8ec8dcdb4ede5d453047bbdbd01916dbaccdb63e98bba60989718f5f0876/numpy-1.16.2-cp27-cp27mu-manylinux1_x86_64.whl#sha256=fb3c83554f39f48f3fa3123b9c24aecf681b1c289f9334f8215c1d3c8e2f6e5b

[[email protected] ~]#wget https://pypi.tuna.tsinghua.edu.cn/packages/c4/33/8ec8dcdb4ede5d453047bbdbd01916dbaccdb63e98bba60989718f5f0876/numpy-1.16.2-cp27-cp27mu-manylinux1_x86_64.whl#sha256=fb3c83554f39f48f3fa3123b9c24aecf681b1c289f9334f8215c1d3c8e2f6e5b

[[email protected] ~]#pip install numpy-1.16.2-cp27-cp27mu-manylinux1_x86_64.whl

测试是否安装成功:
[[email protected] ~]#python 
Python 2.7.5 (default, Jun 20 2019, 20:27:34) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy

 No error, the installation is successful.

 

Download webvirtmgr package

[[email protected] ~] #git clone Go: //github.com/retspen/webvirtmgr.git

 

Install python program depends on libraries

[[email protected] ~/webvirtmgr]# pip install -r requirements.txt 
[[email protected] ~/webvirtmgr]#./manage.py syncdb

 

 

Generate a configuration file

 

Create an administrator user

 

Next, the entire project will webvirtmgr made web site can be accessed

[[email protected] ~] #mkdir -PV / var / www 
[[email protected] ~] -a #cp webvirtmgr / / var / www / 
[[email protected] ~] #chown -R nginx: nginx / var / www /

Modify nginx master configuration file:
the default server segment commented

[[email protected] ~]#vim /etc/nginx/nginx.conf

 

New configuration file webvirtmgr.conf

[[email protected] ~]#cat /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 
    }
}

 

检查语法:

[[email protected] ~]#nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[[email protected] ~]#nginx 
[[email protected] ~]#netstat -ntplu | egrep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      17710/nginx: master

启动成功,通过 web 尝试访问。

 

修改配置 supervisor 服务

[[email protected] ~]#vim /etc/supervisord.conf
添加如下内容:
[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

启动服务
[[email protected] ~]#systemctl start  supervisord
[[email protected] ~]#systemctl status   supervisord
● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-08-13 09:51:25 CST; 1s ago
  Process: 17741 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
 Main PID: 17744 (supervisord)
   CGroup: /system.slice/supervisord.service
           ├─17744 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
           ├─17745 /usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-console
           ├─17746 /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
           ├─17755 /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
           ├─17756 /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
           ├─17757 /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
           ├─17758 /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
           ├─17759 /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
           └─17760 /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py

Aug 13 09:51:25 webvirtmgr.super.com systemd[1]: Starting Process Monitoring and Control Daemon...
Aug 13 09:51:25 webvirtmgr.super.com systemd[1]: Started Process Monitoring and Control Daemon.

 

浏览器尝试访问webvirtmgr  地址:http://192.168.118.14/login/

 

 

 上面创建的两个用户都可以登录。

 

 

 

 登录成功。到此,webvirtmgr控制台安装完毕。

 

3.2 kvm node节点配置

切换到 node1 节点(192.168.118.15)安装部署

[[email protected] ~]#yum install libvirt qemu-kvm virt-viewer -y

 这里有一步容易忽视,会造成后面虚拟机无法创建成功,需要注意下。

[[email protected] ~]#ln -vs /usr/libexec/qemu-kvm  /usr/bin/
‘/usr/bin/qemu-kvm’ -> ‘/usr/libexec/qemu-kvm’

不需要默认nat网络模式,移除

[[email protected] ~]#mv /etc/libvirt/qemu/networks/default.xml /tmp/
[[email protected] ~]#systemctl start libvirtd
[[email protected] ~]#systemctl status  libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-08-13 09:59:25 CST; 1s ago
     Docs: man:libvirtd(8)
           http://libvirt.org
 Main PID: 20741 (libvirtd)
   CGroup: /system.slice/libvirtd.service
           └─20741 /usr/sbin/libvirtd

Aug 13 09:59:25 node1.super.com systemd[1]: Starting Virtualization daemon...
Aug 13 09:59:25 node1.super.com systemd[1]: Started Virtualization daemon.

 

3.3 控制台和kvm节点交互配置

到此,kvm 主机算配置完成,接下来需要配置控制台到kvm主机交互的环节

webvirtmgr 主机

切换到 nginx 用户,生成密钥对,然后将公钥拷贝到 kvm主机节点,实现免密码登录,因为命令是通过nginx用户发送到kvm主机执行的。

[[email protected] ~]#su - nginx -s /bin/bash
-bash-4.2$ ssh-keygen -t rsa -P ''
Generating public/private rsa key pair.

Enter file in which to save the key (/var/lib/nginx/.ssh/id_rsa): Created directory '/var/lib/nginx/.ssh'.
Your identification has been saved in /var/lib/nginx/.ssh/id_rsa.
Your public key has been saved in /var/lib/nginx/.ssh/id_rsa.pub.
The key fingerprint is:
b4:0d:f6:0e:2d:5e:94:2b:56:97:b4:e0:7b:e3:26:f9 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|          . .    |
|         . + o   |
|        + = +    |
|       o O +     |
|        S B o    |
|       o * + .   |
|        . + o    |
|           +     |
|            E    |
+-----------------+

 

可以在 webvirtmgr 安装 libvirt-client 进行测试:

[[email protected] ~]#yum install  libvirt-client -y 
-bash-4.2$ virsh --connect qemu+ssh://[email protected]/system list --all
 Id    Name                           State
----------------------------------------------------

 

访问成功,接下来就可以在 web 页面进行操作了。

 

这里是直接使用 root用户,建议使用普通用户,但是要注意权限,点击添加

 

 点进来如果没有任何报错,那么基本上已经添加主机成功了。

 

1. 创建网桥

在创建网桥这一步要非常小心,因为稍微不注意网卡起不来就有可能直接无法连接服务器。

关闭 NetworkManager 服务

[[email protected] ~]#systemctl stop  NetworkManager; systemctl disable NetworkManager

点击创建。

这里发现使用 web 页面创建网桥没有成功。

[[email protected] ~]#brctl show
bridge name        bridge id                STP enabled        interfaces

如果没有创建成功,则直接通过命令行创建:

[[email protected] ~]#virsh iface-bridge eth0 br0
Created bridge br0 with attached device eth0
Bridge interface br0 started
[[email protected] ~]#brctl show
bridge name        bridge id                STP enabled        interfaces
br0                8000.5254006205ad        yes                eth0

 

创建成功,切换到web页面刷新

 

创建的 br0 网桥已经出现。

 

2. 创建网络池

 

3. 创建存储池

一般可以创建两个存储池:

  (1) 用来存放虚拟磁盘文件(本地)

  (2) 用来存放 iso 文件 (nfs)

 

 

创建 iso 存储池需要在 webvirtmgr 节点安装 nfs 配置

[[email protected] ~]#yum install nfs-utils -y
[[email protected] ~]#cat /etc/exports
/iso        *(rw,sync)
[[email protected] ~]#systemctl start rpcbind
[[email protected] ~]#systemctl start nfs

 

在 kvm 主机上测试

[[email protected] ~]#showmount -e 192.168.118.14
Export list for 192.168.118.14:
/iso *
[[email protected] ~]#mkdir -pv /iso
mkdir: created directory ‘/iso’

 

ok,nfs是可以访问到的。切换到 web 界面进行配置

两个存储池创建成功,接下来就可以尝试创建虚拟机了。

 

4. 创建虚拟机

(1)创建虚拟磁盘文件

 

(2)创建虚拟机

 

 创建完成后,启动虚拟机

 

可以直接通过控制台查看虚拟机。虚拟机创建完成。

现在拷贝 Centos 7 镜像到 存储池的 iso 目录下。

[[email protected] ~]#scp 192.168.118.8:/usr/local/src/CentOS-7-x86_64-Minimal-1511.iso /iso/

 切换到web页面查看存储池。

 

关闭当前虚拟机,为虚拟机添加 iso CDROM

 

再次开启虚拟机,就可以为虚拟机安装操作系统了。

 

完毕。

 

Guess you like

Origin www.cnblogs.com/hukey/p/11344676.html