现在云技术很火,大家都在研究openstack,但是openstack使用和维护目前还不是很成熟,所以如果打算使用openstack的话需要配备专门的技术人员负责维护,而一般的中小企业是不愿承担这些费用的。
今天给大家带来的另一个解决方案WEBvirtmgr,这套方案是基于Django、Nginx和KVM的一套完整管理解决方案,部署和维护相对openstack比较简单,支持web方式管理,方便日常使用。
一.WEBvirtmgr部署
1.1 安装支持的软件源
yum -y install http://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-websockify supervisor nginx
1.3从github中下载webvirtmgr的相关代码
mkdir -pv /var/www
cd /var/www/
git clone git://http://github.com/retspen/webvirtmgr.git
1.4部署webvirtmgr
cd /var/www/webvirtmgr/
pip install -r requirements.txt
1.5部署SQLite数据库
yum install python-sqlite
1.6配置数据库
cd /var/www/webvirtmgr/
./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:********* #admin账号的密码
Password (again):********* #确认密码
./manage.py collectstatic #生成配置文件
./manage.py createsuperuser #添加管理员账号
1.7 配置ssh
ssh-keygen
ssh-copy-id 192.168.2.32
ssh 192.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 {
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
}
}
#将nginx默认配置文件更名
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
1.9 启动nginx
/etc/init.d/nginx restart
1.10 关闭防火墙
service iptables 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
修改gunicorn.conf.py文件默认配置
vim /var/www/webvirtmgr/conf/gunicorn.conf.py
bind = "127.0.0.1:8000" 改为 bind = "0:8000"
1.12 设置supervisord开机自启动,设置防火墙开机不启动
chkconfig supervisord on
chkconfig iptables off
1.13 重启supervisord进程
/etc/init.d/supervisord restart
1.14 查看服务状态
netstat -lnpt 进程正常启动即可以看到6080和8000端口已经打开
1.15 通过浏览器访问管理界面
http://IP:8000 账号为前面设置的admin
二.常见报错处理方法
2.1 页面配置ssh方式连接后报错解决
创建nginx用户家目录(默认nginx服务安装时是没有nginx家目录的)
[root@openstack ops]# cd /home/
[root@openstack home]# mkdir nginx
[root@openstack home]# chown nginx.nginx nginx/
[root@openstack home]# chmod 700 nginx/ -R
[root@openstack home]# su - nginx -s /bin/bash
-bash-4.1$ ssh-keygen #直接回车
-bash-4.1$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=nonUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.1$ chmod 0600 ~/.ssh/config
以上的配置是采用root用户,如果采用其他用户,比如webvirtmgr,增加如下操作:
[root@openstack ops]#useradd webvirtmgr
[root@openstack ops]#echo "123456" | passwd --stdin webvirtmgr
[root@openstack ops]#groupadd libvirt
[root@openstack ops]#usermod -G libvirt -a webvirtmgr
2.2 将nginx用户的ssh-key上传到kvm服务器上
[root@openstack ops]# su - nginx -s /bin/bash
-bash-4.1$ ssh-copy-id root@192.168.1.17
Warning: Permanently added '192.168.1.17' (RSA) to the list of known hosts.
root@192.168.1.107's password: #输入本机的root密码
Now try logging into the machine, with "ssh 'root@192.168.1.17'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
这里采用的是root用户,如果采用其他用户,比如上面假设的webvirtmgr用户,操作如下:
[root@openstack ops]#su - nginx -s /bin/bash
-bash-4.1$ssh-copy-id webvirtmgr@192.168.0.23
2.3 配置 libvirt ssh授权
新建50-libvirt-remote-access.pkla文件
[root@openstack ops]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
将下面的内容粘贴到50-libvirt-remote-access.pkla文件中
[Remote libvirt SSH access]
Identity=unix-user:root #注意这里采用的是root用户
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@openstack ops]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
这里采用的是root用户,如果采用其他用户,比如上面假设的webvirtmgr用户,操作如下:
[root@openstack ops]#vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:webvirtmgr #这里就设定webvirtmgr用户
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@openstack ops]#chown -R webvirtmgr.webvirtmgr /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
2.4 重启 libvirtd 服务
/etc/init.d/libvirtd restart
这样上面报错的问题就迎刃而解了!
- 微信公众号ID:snmp161
- 我的微信
- 微信扫一扫
-
- 我的微信公众号
- 微信扫一扫
-
评论