前提:安装好KVM环境
第一种:Docker方式安装
#安装KVM(已经安装的可以跳过)
yum -y install qemu-kvm qemu-kvm-tools libvirt virt-install bridge-utils novnc
systemctl start libvirtd
systemctl enable libvirtd
grep -c vmx /proc/cpuinfo
#安装Docker容器并拉取webvirtmgr镜像
yum -y install docker
systemctl enable docker
systemctl start docker
docker pull primiano/docker-webvirtmgr
mkdir -p /data/vm
groupadd -g 1010 webvirtmgr
useradd -u 1010 -g webvirtmgr -s /sbin/nologin -d /data/vm webvirtmgr
chown -R webvirtmgr:webvirtmgr /data/vm
docker run -d -p 8080:8080 -p 6080:6080 --name webvirtmgr -v /data/vm:/data/vm --restart=always web:v1
docker container update --restart=always webvirtmgr
cat > /etc/default/libvirt-bin << EOF
start_libvirtd="yes"
libvirtd_opts="-d -l"
EOF
cat > /etc/libvirt/libvirt.conf << EOF
listen_tls = 0
listen_tcp = 1
listen_addr = "0.0.0.0"
unix_sock_group = "libvirtd"
unix_sock_ro_perms = "0777"
unix_sock_rw_perms = "0770"
auth_unix_ro = "none"
auth_unix_rw = "none"
auth_tcp = "none"
auth_tls = "none"
EOF
cat > /etc/libvirt/qemu.conf << EOF
vnc_tls = 0
EOF
systemctl restart libvirtd
#login to docker edit webvirtmgr
docker exec -it webvirtmgr /bin/bash
#modify novnc config
sed -i 's/172.17.42.1/0.0.0.0/g' /webvirtmgr/vrtManager/create.py
#modify default admin passwd
cd /webvirtmgr
python manage.py changepassword admin
#create new supperuser
cd /webvirtmgr
python manage.py createsuperuser
#modify webvirtmgr user not passwd login to kvm host
su - webvirtmgr -s /bin/bash
ssh-keygen -q -P '' -t rsa -f /data/vm//.ssh/id_rsa
touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
chmod 0600 ~/.ssh/config
ssh-copy-id root@192.168.6.171
#login webvirtmgr default user:admin passwd:1234
http://192.168.6.171:8080
read -p "please input interface name: " int
read -p "please input add br name: " br
cat > /etc/sysconfig/network-scripts/ifcfg-$int << EOF
DEVICE=$int
ONBOOT=yes
BOOTPROTO=none
BRIDGE=$br
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-$br << EOF
DEVICE=$br
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.66.100
PREFIX=24
GATEWAY=192.168.66.2
DNS1=192.168.66.2
EOF
ifup $int
ifup $br
brctl show |grep $br
第二种:本地物理机安装
原本地址:
https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr
#有人说访问不了github怎么办
#这里教你一招
#只要有阿里云服务器就行
#第一步:命令行输入
#curl https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr >index.html
#第二步:下载该HTML文件到本地电脑,用什么方法都行
#sz index.html
#第三步:使用浏览器打开访问就可以了
01.环境准备
#安装常用工具、更换yum源
yum -y install wget curl
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum install -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip ntpdate gcc make gcc-c++
#关闭防火墙和selinux
systemctl stop firewalld NetworkManager
systemctl disable firewalld NetworkManager
setenforce 0
sed -i s/enforcing/disabled/g /etc/sysconfig/selinux
#安装WebVirtMgr依赖的环境
yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx
yum -y install gcc python-devel
pip install numpy
02.开始安装
#获取源码
cd /usr/local/src/
git clone git://github.com/retspen/webvirtmgr.git
cd webvirtmgr
pip install -r requirements.txt
#
./manage.py syncdb
./manage.py collectstatic
输入用户信息:
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 (Put: yes)
Username (Leave blank to use 'admin'): admin (Put: your username or login)
E-mail address: username@domain.local (Put: your email)
Password: xxxxxx (Put: your password)
Password (again): xxxxxx (Put: confirm password)
Superuser created successfully.
03.端口转发(可以跳过)
ssh user@server:port -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080
#使用SSH协议访问的配置
#user可以不写,默认是root
#server为本机的IP地址
#port可以不写
04.配置nginx代理
cd ..
mkdir /var/www
mv webvirtmgr /var/www/
cd /etc/nginx/conf.d/
cat > webvirtmgr.conf << EOF
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 ~ .*\.(js|css)$ {
proxy_pass http://127.0.0.1:8000;
}
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
}
}
EOF
05.注释配置文件的server块
vim /etc/nginx/nginx.conf
# server {
# listen 80 default_server;
# server_name localhost;
# root /usr/share/nginx/html;
#
# #charset koi8-r;
#
# #access_log /var/log/nginx/host.access.log main;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# # redirect server error pages to the static page /40x.html
# #
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# # redirect server error pages to the static page /50x.html
# #
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
06.重启nginx
#给站点目录授权
chown -R nginx:nginx /var/www/webvirtmgr
#检查nginx语法是否正确
nginx -t
#重启nginx
systemctl restart nginx.service
07.配置supervisord
cat > /etc/supervisord.d/webvirtmgr.ini << EOF
[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
EOF
08.重启supervisord服务
systemctl restart supervisord.service
09.更新配置
cd /var/www/webvirtmgr
git pull
./manage.py collectstatic
systemctl restart supervisord.service
10.浏览器访问:
http://x.x.x.x (x.x.x.x - your server IP address )
11.配置免交互访问:
mkdir -p /home/nginx
chown nginx.nginx /home/nginx
chmod 700 -R /home/nginx/
su - nginx -s /bin/bash
-bash-4.2$ ssh-keygen -f ~/.ssh/id_rsa -N '' -q
-bash-4.2$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.2$ chmod 0600 ~/.ssh/config
-bash-4.2$ ssh-copy-id webvirtmgr@192.168.66.100
配置NFS网络文件系统存储(可选)
需要两台机器,一台服务端、一台客户端。
服务端操作:
#安装NFS
yum install nfs-utils -y
#配置NFS配置文件
cat > /etc/exports << EOF
/data 192.168.66.0/24(rw,sync,all_squash)
EOF
#创建共享目录
mkdir /data
#将共享目录授予权限
chown -R nfsnobody:nfsnobody /data/
#启动NFS
systemctl start nfs-server.service
#检查配置文件
showmount -e 192.168.66.33
#设置开机自启
systemctl enable rpcbind nfs-server
systemctl restart rpcbind nfs-server
客户端操作:
#安装NFS服务
yum install nfs-utils rpcbind -y
#启动rpcbind
systemctl restart rpcbind
#查看nfs共享信息
showmount -e 192.168.66.33
#创建空的挂载目录
mkdir /data -p
# 使用mount命令并结合-t参数挂载nfs
mount -t nfs 192.168.66.33:/data /data
df -h
#写入开机自动挂载
cat >> /etc/fstab << EOF
192.168.66.33:/data /data nfs defaults 0 0
EOF
mount -a
df -h
在WebVirtMgr
添加存储池
网友评论