空无以求全
宁静以致远
当前位置:首页 > .html

kvm管理平台webvirtmgr的部署

作者:大熊空间发布时间:2022-02-19 17:09分类: 浏览:231评论:0


导读: 知道大家部署可视化的kvm管理平台webvirtmgr不容易,这不,给大家带干活来啦~~~ 前景概要: web...

知道大家部署可视化的kvm
管理平台webvirtmgr
不容易,这不,给大家带干活来啦~~~



前景概要:

webvirtmgr
开源框架:Git

地址:https://github.com/retspen/webvirtmgr


环境:

system:centos6.8

libvirt: 0.10.2

webvirtmgr
的安装,参考:https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr


1.
安装虚拟化环境(KVM
环境)


1. yum -y groupinstall 'Virtualization Tools'

2. yum -y groupinstall 'Virtualization'

3. yum -y groupinstall 'Virtulization Client'

4. yum -y groupinstall 'Virtulization Platform'



开始部署

2.
安装依赖包

$ sudo yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

安装epel
依赖包建议查看一下 centos6
安装 ./epel
笔记$ sudo yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor ngin



3.
克隆github
代码

cd /usr/local/src/

git clone git://github.com/retspen/webvirtmgr.git



4.
安装webvirtmgr


cd webvirtmgr/

pip install -r requirements.txt



5
安装数据库

yum install -y python-sqlite2



6
django
进行环境配置

./manage.py syncdb

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: 2733176200@qq.com

Password:*********

Password (again):*********

./manage.py collectstatic #
生成配置文件

./manage.py createsuperuser #
添加管理员账号



7
拷贝web
到 相关目录

cd ..

mkdir -pv /var/www

cp -Rv webvirtmgr /var/www/webvirtmgr



8
设置ssh


ssh-keygen

ssh-copy-id 192.168.1.50

ssh 192.168.1.50 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080



9
编辑nginx
配置文件

vim /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 $remote_addr;

proxy_connect_timeout 600;

proxy_read_timeout 600;

proxy_send_timeout 600;

client_max_body_size 1024M; # Set higher depending on your needs

}

}

保存文件

mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak



10
启动nginx


/etc/init.d/nginx restart



11
修改防火墙规则

/usr/sbin/setsebool httpd_can_network_connect true



12
设置 supervisor


chown  -R  nginx:nginx   /var/www/webvirtmgr

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

修改/var/www/webvirtmgr/conf/gunicorn.conf.py


bind = "0:8000"



13
设置开机启动

chkconfig supervisord on

vim /etc/rc.local

/usr/sbin/setsebool httpd_can_network_connect true



14
启动进程

/etc/init.d/supervisord restart



15
查看进程

netstat -lnpt
即可以看到6080
8000
已经启动



16.
启动Django
服务

./manage.py runserver 0.0.0.0:8000



访问:http://x.x.x.x:8000
(x.x.x.x - your server IP address )
,输入创建的django
用户和密码,如果没有创建,请用python manager.py createsuperuser,
命令创建。登录后如下图所示



初始登录时

webvirtmgr
客户端就这样搭建完了,接下来需要配置虚拟机所在宿主机的,参考git
地址

.



配置宿主机

配置宿主机环境:

system: centos 6.8

libvirt: 0.10.2



17.
下载并执行脚本:libvirt-bootstrap.sh


如果虚拟机比较多,该脚本执行时间会比较长,因为会执行service libvirt-guests restart
,会将所有运行的虚拟机挂起然后再恢复,感觉这一步不是必须的,因为我有一台只设置ssh
认证,也可以正常连接。

一步不是必须的,因为我有一台只设置ssh
认证,也可以正常连接。

curlhttp://retspen
.github.io/libvirt-bootstrap.sh | sudo sh



18.
设置防火墙:

sudo iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 16509 -j ACCEPT



19.
设置TCP
认证Setup TCP authorization


参考:https://github.com/retspen/webvirtmgr/wiki/Setup-TCP-authorization

webvirtmgr
新建服务器连接时需要此账号

$ sudo saslpasswd2 -a libvirt demo

Password: xxxxxxAgain (for verification): xxxxxx

查看新加的账号

$ sudo sasldblistusers2 -f /etc/libvirt/passwd.db

demo@webvirtmgr.net: userPassword

删除新加的账号:

sudo saslpasswd2 -a libvirt -d demo

验证新加的账号:

$virsh -c qemu+tcp://IP_address/system nodeinfo  (virsh -c qemu+tcp://192.168.1.50/system nodeinfo)

Please enter your authentication name: demo@webvirtmgr.net

Please enter your password: xxxxxx

CPU model:          x86_64

CPU(s):              2

CPU frequency:      2611 MHz

CPU socket(s):      1

Core(s) per socket:  2

Thread(s) per core:  1

NUMA cell(s):        1

Memory size:        2019260 kB

注意:账号全名带hostname
,如demo@webvirtmgr

.NET




20.
设置ssh
认证

ssh
tcp
设置一种即可,其实就是设置无密码登录,要注意的是从webvirtmgr
的什么用户到宿主机的什么用户的无密码登录,比如我用root
跑的django webvirtmgr
,而宿主机也是root
跑的virsh
,所以需要设置root
root
的无密码登录。而git
官网推荐的是用nginx
用户跑django webvirtmgr
webvirtmgr
用户跑的virsh
,所以设置的是nginx
用户到宿主机webvirtmgr
用户的无密码登录。

参考:
https://github.com/retspen/webvirtmgr/wiki/Setup-SSH-Authorizatio




21.
使用tcp
认证连接服务器

访问:
http://xxxx:8000

xxxx
webvirtmgr
ip
地址,点击new connection



使用TCP
连接,label
填写ip
地址,FQDN/IP
填写ip
地址,用户名填写第三步设置tcp
认证所增加的账号,这里的用户名不用加@hostname
,点击添加完成。如下图:


发表评论: