现在云技术很火,大家都在研究openstack,但是openstack使用和维护目前还不是很成熟,所以如果打算使用openstack的话需要配备专门的技术人员负责维护,而一般的中小企业是不愿承担这些费用的。
今天给大家带来的另一个解决方案WEBvirtmgr,这套方案是基于Django、Nginx和KVM的一套完整管理解决方案,部署和维护相对openstack比较简单,支持web方式管理,方便日常使用。
一.WEBvirtmgr部署
1.1安装支持的软件源
yum-y installhttp://dl.Fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
1.2部署环境和软件
yum-y install git python-pip libvirt-python libxml2-python python-websockifysupervisor nginx
1.3从github中下载webvirtmgr的相关代码
mkdir-pv /var/www
cd/var/www/
gitclone git://github.com/retspen/webvirtmgr.git
1.4部署webvirtmgr
cd/var/www/webvirtmgr/
pipinstall -r requirements.txt
1.5部署SQLite数据库
yuminstall python-sqlite
1.6配置数据库
cd/var/www/webvirtmgr/
./manage.pysyncdb
会出现如下提示信息:
Youjust installed Django's auth system, which means you don't have any superusersdefined.
Wouldyou like to create one now? (yes/no): yes
Username(leave blank to use 'root'): admin #管理账号
Password:*********#admin账号的密码
Password(again):********* #确认密码
./manage.pycollectstatic #生成配置文件
./manage.pycreatesuperuser #添加管理员账号
1.7配置ssh
ssh-keygen
ssh-copy-id192.168.2.32
ssh192.168.2.32 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080
1.8配置nginx配置文件
vim/etc/nginx/conf.d/webvirtmgr.conf
添加下面内容到webvirtmgr.conf文件中
server{
listen80 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
expiresmax;
}
location/ {
proxy_passhttp://127.0.0.1:8000;
proxy_set_headerX-Real-IP $remote_addr;
proxy_set_headerX-Forwarded-for $proxy_add_x_forwarded_for;
proxy_set_headerHost $host:$server_port;
proxy_set_headerX-Forwarded-Proto $remote_addr;
proxy_connect_timeout600;
proxy_read_timeout600;
proxy_send_timeout600;
client_max_body_size1024M; # Set higher depending on your needs
}
}
#将nginx默认配置文件更名
mv/etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
1.9启动nginx
/etc/init.d/nginxrestart
1.10关闭防火墙
serviceiptables stop #关闭防火墙
1.11配置supervisor
chown-R nginx:nginx /var/www/webvirtmgr #修改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
vim/var/www/webvirtmgr/conf/gunicorn.conf.py
bind= "127.0.0.1:8000"改为 bind = "0:8000"
1.12设置supervisord开机自启动,设置防火墙开机不启动
chkconfigsupervisord on
chkconfigiptables off
1.13重启supervisord进程
/etc/init.d/supervisordrestart
1.14查看服务状态
netstat-lnpt进程正常启动即可以看到6080和8000端口已经打开
1.15通过浏览器访问管理界面
http://IP:8000账号为前面设置的admin
二.常见报错处理方法
2.1页面配置ssh方式连接后报错解决
创建nginx用户家目录(默认nginx服务安装时是没有nginx家目录的)
[root@openstackops]# cd /home/
[root@openstackhome]# mkdir nginx
[root@openstackhome]# chown nginx.nginx nginx/
[root@openstackhome]# chmod 700 nginx/ -R
[root@openstackhome]# su - nginx -s /bin/bash
-bash-4.1$ssh-keygen #直接回车
-bash-4.1$touch ~/.ssh/config && echo -e"StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >>~/.ssh/config
-bash-4.1$chmod 0600 ~/.ssh/config
以上的配置是采用root用户,如果采用其他用户,比如webvirtmgr,增加如下操作:
[root@openstackops]#useradd webvirtmgr
[root@openstackops]#echo "123456" | passwd --stdin webvirtmgr
[root@openstackops]#groupadd libvirt
[root@openstackops]#usermod -G libvirt -a webvirtmgr
2.2将nginx用户的ssh-key上传到kvm服务器上
[root@openstackops]# su - nginx -s /bin/bash
Warning:Permanently added '192.168.1.17' (RSA) to the list of known hosts.
.ssh/authorized_keys
tomake sure we haven't added extra keys that you weren't expecting.
这里采用的是root用户,如果采用其他用户,比如上面假设的webvirtmgr用户,操作如下:
[root@openstackops]#su - nginx -s /bin/bash
2.3配置 libvirt ssh授权
新建50-libvirt-remote-access.pkla文件
[root@openstackops]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
将下面的内容粘贴到50-libvirt-remote-access.pkla文件中
[Remotelibvirt SSH access]
Identity=unix-user:root#注意这里采用的是root用户
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@openstackops]# chown -R root.root/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
这里采用的是root用户,如果采用其他用户,比如上面假设的webvirtmgr用户,操作如下:
[root@openstackops]#vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remotelibvirt SSH access]
Identity=unix-user:webvirtmgr#这里就设定webvirtmgr用户
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@openstackops]#chown -R webvirtmgr.webvirtmgr/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
2.4重启 libvirtd 服务
/etc/init.d/libvirtdrestart
这样上面报错的问题就迎刃而解了!
领取专属 10元无门槛券
私享最新 技术干货