美文网首页
kvm 虚拟化(三 webvirtmgr 安装)

kvm 虚拟化(三 webvirtmgr 安装)

作者: 虚心的锄头 | 来源:发表于2019-04-15 17:14 被阅读0次

    WebVirtMgr 是KVM的web管理平台系统, 由django开发

    官网安装介绍

    安装

    建议先替换pip源为国内源 Python 更改pip源

    
    yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx 
    mkdir -p /var/www/
    cd /var/www/
    git clone git://github.com/retspen/webvirtmgr.git
    cd webvirtmgr
    pip install -r requirements.txt
    ./manage.py syncdb  #会提示创建Django 连接数据库账号密码等信息
    # ..........
    # You just installed Django's auth system, which means you don't have any superusers defined.
    # Would you like to create one now? (yes/no): yes
    # Username (leave blank to use 'root'): admin
    # Email address: lty@xxx.com
    # Password:*********
    # Password (again):*********
    # ..............
    
    ./manage.py collectstatic #同步项目文件
    # WARNING:root:No local_settings file found.
    
    # You have requested to collect static files at the destination
    # location as specified in your settings.
    
    # This will overwrite existing files!
    # Are you sure you want to do this?
    
    # Type 'yes' to continue, or 'no' to cancel: yes 
    # ..........
    # ..........
    
    ./manage.py createsuperuser   #配置webvirtmgr 登录账号
    # WARNING:root:No local_settings file found.
    # Username: ops     //这个是管理员账号,用上面的admin和这个管理员账号都可以登陆webvirtmgr的web界面管理平台
    # Email address: wangshibo@163.com
    # Password: 
    # Password (again): 
    # Superuser created successfully.
    
    chown nginx.nginx -R webvirtmgr/
    

    nginx 配置

    mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
    /etc/nginx/conf.d/webvirtmgr.conf
    server {
        listen 80 ;
        server_name kvm.cnyunwei.cc;
        access_log /var/log/nginx/webvirtmgr_access_log; 
     
        location /static/ {
            root /home/webvirtmgr/webvirtmgr; 
            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; 
        }
    }
    

    配置webvirtmgr 连接KVM服务器

    webvirtmgr 连接kvm有两种方式:SSH和TCP
    TCP模式最为简单方便,这里已tcp连接为例。

    1. 设置libvirtd 服务监听
      在kvm服务器上取消libvirtd 服务配置文件LIBVIRTD_ARGS 前的注释 /etc/sysconfig/libvirtd
    cp /etc/sysconfig/libvirtd{,_bak}  #先备份原文件再操作
    vim /etc/sysconfig/libvirtd
    LIBVIRTD_ARGS="--listen"
    

    2.配置libvirt 服务 /etc/libvirt/libvirtd.conf 允许通过tcp方式通讯,修改以下参数:

    cp  /etc/libvirt/libvirtd.conf{,_bak}
    vim /etc/libvirt/libvirtd.conf
    
    listen_tls = 0
    listen_tcp = 1
    tcp_port = "16509"
    listen_addr = "0.0.0.0"
    auth_tcp = "none"
    

    3.启动服务、创建libvirt管理用户

    service libvirtd start
    saslpasswd2 -a libvirt admin #创建用户admin 
    
    TCP链接

    KVM管理平台webvirtmgr配置SSH连接

    1 在webvirtmgr服务器(服务端)生成密钥

    [root@kvm_master ~] cd /home
    [root@kvm_master home] mkdir nginx  #因为nginx用户在创建的时候是设置的sbin/nologin 所以这里需要手动创建家目录
    [root@kvm_master home] chown nginx.nginx nginx/
    [root@kvm_master home] chmod 700 nginx/ -R
    [root@kvm_master home] su - nginx -s /bin/bash  
    -bash-4.2$ ssh-keygen   ---期间输入yes后直接回车,回车
    -bash-4.2$  touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
    -bash-4.2$  chmod 0600 ~/.ssh/config
    

    2 在kvm(受控端)服务器上配置webvirt用户

    [root@kvm_10 home] useradd webvirtmgr
    [root@kvm_10 home] echo "123456" | passwd --stdin webvirtmgr
    [root@kvm_10 home] groupadd libvirt
    [root@kvm_10 home] usermod -G libvirt -a webvirtmgr
    

    3 在webvirtmgr服务器(服务端)上,将ssh-key上传到kvm服务器上

    [root@kvm_master home] su - nginx -s /bin/bash
    -bash-4.2$ ssh-copy-id   webvirtmgr@192.168.0.23
    

    4 在kvm(受控端)服务器上配置 libvirt ssh授权

    [root@kvm_10 home] vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
    [Remote libvirt SSH access]
    Identity=unix-user:webvirtmgr
    Action=org.libvirt.unix.manage
    ResultAny=yes
    ResultInactive=yes
    ResultActive=yes
     
    [root@kvm_10 home] chown -R webvirtmgr.webvirtmgr /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
     
    重启 libvirtd 服务
    [root@kvm_10 home] service libvirtd restart
    
    SSH链接

    参考资料

    https://www.cnops.xyz/archives/category/nine/kvm
    https://www.cnblogs.com/kevingrace/p/5737724.html

    相关文章

      网友评论

          本文标题:kvm 虚拟化(三 webvirtmgr 安装)

          本文链接:https://www.haomeiwen.com/subject/gqnuwqtx.html