WebVirtMgr
地址: http://retspen.github.io/
简介 :
WebVirtMgr是一个基于libvirt的Web界面,用于管理虚拟机。它允许您创建和配置新域,并调整域的资源分配。VNC查看器为来宾域提供完整的图形控制台。KVM是目前唯一支持的虚拟机管理程序
技术:
应用程序逻辑是用Python和Django编写的。LIBVIRT Python绑定用于与底层管理程序进行交互
系统:centos7
| Bash |
|---|
| serverIP: 192.168.68.30
clientIP: 192.168.68.30 # client就是kvm主机,这里部署在了一起,也可以是不同服务器
|
安装KVM
- 安装基础包
| Bash |
|---|
| yum install epel-release
yum install qemu-kvm libvirt libvirt-python \
libguestfs-tools virt-install virt-manager \
python-virtinst libvirt-client virt-viewer
|
- 启动服务
systemctl enable libvirtd && systemctl start libvirtd
- 创建软连接
ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
安装WebVirtMgr
- yum安装(因为在1台机器上,所以安装包与kvm安装有重复)
| Bash |
|---|
| yum -y install git python-pip libvirt-python libxml2-python \
python-websockify supervisor nginx gcc python-devel
pip install --trusted-host pypi.python.org --trusted-host pypi.org numpy==1.14.5
# 安装慢的话可以使用国内源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \
--trusted-host pypi.tuna.tsinghua.edu.cn numpy==1.14.5
|
- 从git-hub中下载相关的webvirtmgr代码
| Bash |
|---|
| cd /usr/local/src/
git clone git://github.com/retspen/webvirtmgr.git
# 或者
git clone https://github.com/retspen/webvirtmgr.git
|
- .安装python需求并设置Django环境
| Bash |
|---|
| cd webvirtmgr/
pip install --trusted-host pypi.python.org --trusted-host pypi.org -r requirements.txt
# 国内源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \
--trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt
|
- 安装数据库sqlite3
默认已安装,没有安装执行yum安装一下
| Bash |
|---|
| yum install sqlite
# 查看版本
sqlite3 -version
|
- 对django进行环境配置,请注意python的版本
cd /usr/local/src/webvirtmgr
建表
| Bash |
|---|
| # 同步数据库
./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: test@exmail.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
..........
..........
|
- 添加管理员账号
| Bash |
|---|
| ./manage.py createsuperuser
WARNING:root:No local_settings file found.
Username: user1 # 这个是管理员账号,用上面的admin和这个管理员账号都可以登陆webvirtmgr的web界面管理平台
Email address: user1@exmail.com
Password:
Password (again):
Superuser created successfully.
|
设置nginx
警告
通常WebVirtMgr只能从端口8000上的localhost获得。此步骤将使端口80上的所有人都可以使用WebVirtMgr .Web接口也是不受保护的(没有https),这意味着所有人可以以明文形式查看登录凭据"
- 拷贝web到 相关目录
| Bash |
|---|
| mkdir -pv /var/www
cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr
|
- 编辑nginx配置文件
vim /etc/nginx/conf.d/webvirtmgr.conf
| Bash |
|---|
| server {
listen 80 default_server;
server_name $hostname;
#access_log /var/log/nginx/webvirtmgr_access_log;
location /static/ {
root /var/www/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 $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M; # 可以根据具体情况设置更高
}
}
|
vim /etc/nginx/nginx.conf
| Bash |
|---|
| user root; # 自己使用,为避免麻烦,将nginx改为root运行
.......
### server { # 将默认的80端口注释,或者修改,别与web冲突就行
### listen 80 default_server;
### listen [::]:80 default_server;
.......
|
- 启动
| Bash |
|---|
| # 检查配置
/usr/sbin/nginx -t
# 启动nginx
/usr/sbin/nginx
|
设置 supervisor
vim /etc/supervisord.conf
| Bash |
|---|
| # 在文件末尾添加
[program:webvirtmgr]
# 启动8000端口
command=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=root
[program:webvirtmgr-console]
# 启动6080端口(这是控制台vnc端口)
command=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=root
|
vim /var/www/webvirtmgr/conf/gunicorn.conf.py
| Bash |
|---|
| # 确保下面bind绑定的是本机的8000端口,这个在nginx配置中定义了,被代理的端口
bind = '127.0.0.1:8000'
|
设置开机启动并启动服务
systemctl enable supervisord.service
web访问
http://ip地址
这里使用ssh免密登录管理,需要在管理机可以ssh 登录到kvm主机
这里记一个手动创建虚拟机pxe启动命令
| Bash |
|---|
| virt-install --name 192.168.68.91 --vcpus=2 --ram 4096 \
--disk path=/share/images/192.168.68.91.img,size=80,format=qcow2 \
--graphics vnc,listen=0.0.0.0 --noautoconsole --network bridge=br0, --force \
--autostart --os-type=linux --os-variant=rhel7 --pxe
|