Skip to content

Commit

Permalink
部署环境说明
Browse files Browse the repository at this point in the history
  • Loading branch information
hhr66 committed May 30, 2014
1 parent c038bb3 commit d40a554
Show file tree
Hide file tree
Showing 24 changed files with 243 additions and 27 deletions.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,68 @@ django 1.6.2
salt-master 2014.1.0-1
Python 2.6.6

saltweb部署
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-2.1.tar.gz
tar zxf setuptools-2.1.tar.gz
cd setuptools-2.1
python setup.py install
cd ..
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-1.5.tar.gz
tar zxf pip-1.5.tar.gz
cd pip-1.5
python setup.py install
cd ..
yum -y install gcc gcc-c++ python-devel
yum install php-devel mysql mysql-server mysql-devel nginx php-mysql php php-fpm MySQL-python
yum install salt-master salt-minion salt
yum install rrdtool-devel python-rrdtool
pip install django
pip install uwsgi
pip install apscheduler paramiko
sed -i 's/\(.*\)HAVE_DECL_MPZ_POWM_SEC/#\1HAVE_DECL_MPZ_POWM_SEC/' /usr/lib64/python2.6/site-packages/Crypto/Util/number.py
sed -i 's/\(.*\)mpz_powm_sec/#\1mpz_powm_sec/' /usr/lib64/python2.6/site-packages/Crypto/Util/number.py
mkdir /etc/salt/master.d
cat << EOF > /etc/salt/master.d/group.conf
nodegroups:
master: testgroups
EOF
echo "auto_accept: True" >>/etc/salt/master
grep "^default_include: master.d/\*\.conf" /etc/salt/master >/dev/null 2>&1|| echo "default_include: master.d/*.conf" >> /etc/salt/master


/etc/init.d/mysqld start
chkconfig mysqld on
mysqladmin -uroot password 123
mysql -uroot -p123 -e "create database saltweb default charset utf8"

./manage.py syncdb
#注:第一次执行syncdb会提示创建超级管理员,该账号为saltweb的登录账号及后台超级管理员
./manage.py runserver 0.0.0.0:8001

sed -i 's/^user.*/user root;/' /etc/nginx/nginx.conf
cat << EOF > /etc/nginx/conf.d/virtual.conf
server {
listen 80;
server_name www.hhr.com;
charset utf-8;
index index.html index.htm index.php;
access_log /var/log/nginx/hhr.access.log;
error_log /var/log/nginx/hhr.error.log;
location / {
uwsgi_pass 127.0.0.1:8008;
include uwsgi_params;
}
location /static/ {
alias /root/saltweb/saltweb/static/;
index index.html index.htm;
}
}
EOF

注意:如果saltweb在/root目录下,必须修改nginx的配置文件改成root用户,否则访问css报403错误
python /root/saltweb/saltweb/init.py
python /root/saltweb/saltweb/salt_service.py start
python /root/saltweb/saltweb/salt_service.py status

测试
修改本机host,添加"172.16.1.237 www.hhr.com",访问http:https://www.hhr.com/salt
4 changes: 4 additions & 0 deletions nohup.out
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,7 @@ Quit the server with CONTROL-C.
[21/May/2014 16:42:53] "POST /salt/monitor1/ HTTP/1.1" 200 11552
[21/May/2014 16:42:53] "GET /static/rrd/172.16.1.238_test1/connum.png HTTP/1.1" 200 12915
[21/May/2014 16:42:53] "GET /static/rrd/172.16.1.238_test1/load.png HTTP/1.1" 200 12844
[21/May/2014 16:53:43] "GET /salt/monitor1/ HTTP/1.1" 200 11444
[21/May/2014 16:53:49] "POST /salt/monitor1/ HTTP/1.1" 200 11552
[21/May/2014 16:53:49] "GET /static/rrd/172.16.1.238_test1/connum.png HTTP/1.1" 200 12456
[21/May/2014 16:53:49] "GET /static/rrd/172.16.1.238_test1/load.png HTTP/1.1" 200 12943
Binary file modified rrdtool/172.16.1.220_localhost.localdomain/connum.rrd
Binary file not shown.
Binary file modified rrdtool/172.16.1.220_localhost.localdomain/load.rrd
Binary file not shown.
Binary file modified rrdtool/172.16.1.238_test1/connum.rrd
Binary file not shown.
Binary file modified rrdtool/172.16.1.238_test1/load.rrd
Binary file not shown.
2 changes: 1 addition & 1 deletion saltweb/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
####################
#全局变量
from_mail = '[email protected]'
samail_list = ['[email protected]','[email protected]']
samail_list = ['[email protected]',]
interval = 7200 #报警间隔
masterip = '172.16.1.237'
network_list = ('172.16','192.168','10.0')
Expand Down
Binary file modified saltweb/comm.pyc
Binary file not shown.
21 changes: 4 additions & 17 deletions saltweb/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,12 @@
#author: hhr
import os,sys,time,re
import threading
import comm
import comm, db_connector
from saltweb.models import *

os.system('cd %s ;nohup python -m SimpleHTTPServer >/tmp/t.out 2>&1 &' % comm.upload_dir)
#Pro_type.objects.all().delete()
#Pro_type.objects.create(name='SSH')
#Pro_type.objects.create(name='SSH-KEY')
Monitortype.objects.all().delete()
Monitortype.objects.create(name='connum',alias='连接数')
Monitortype.objects.create(name='load',alias='负载')
os.system('python %smanage.py' % comm.script_dir )
os.system('python %shostping.py' % comm.script_dir)
os.system('python %smonitor.py' % comm.script_dir)
os.system('cd %s ;nohup python -m SimpleHTTPServer >/tmp/t.out 2>&1 &' % comm.upload_dir)
os.system('rm -rf %s %s' % (comm.rrd_dir,comm.rrdpic_dir))
os.system('uwsgi --ini %s' % comm.base_dir + 'uwsgi.ini')
if not os.path.exists(rrdfile):rrdcreate1(rrdfile,rrdstep)
os.system('echo "auto_accept: True" >>/etc/salt/master')
os.system('grep "^default_include: master.d/\*\.conf" /etc/salt/master >/dev/null 2>&1|| echo "default_include: master.d/*.conf" >> /etc/salt/master')
groupsconfdir = os.path.dirname(comm.groupsconf)
if not os.path.exists(groupsconfdir): os.makedirs(groupsconfdir)
if not os.path.exists(comm.groupsconf): os.system('echo "nodegroups:\n dfgroup: testhostid" > %s' % comm.groupsconf)
Mastermonitor.objects.all().delete()
Mastermonitor.objects.create(ip='%s' % comm.masterip)
os.system('rm -rf %s/* %s' % (comm.rrd_dir,comm.rrdpic_dir))
6 changes: 4 additions & 2 deletions saltweb/salt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ def service_status(service_name):
return "Dead"

uwsgicmd = 'uwsgi --ini %suwsgi.ini' % comm.base_dir
minioncmd = '/etc/init.d/salt-minion start'
#minioncmd = '/etc/init.d/salt-minion start'
mastercmd = '/etc/init.d/salt-master start'
phpfpmcmd = '/etc/init.d/php-fpm start'
nginxcmd = '/etc/init.d/nginx start'
saltcroncmd = 'python %ssaltcron.py &' % comm.script_dir
services = {'uwsgi':uwsgicmd,'salt-master':mastercmd,'salt-minion':minioncmd,'php-fpm':phpfpmcmd,'nginx':nginxcmd,'saltcron':saltcroncmd}
SimpleHTTPServercmd = 'cd %s ;nohup python -m SimpleHTTPServer >/tmp/t.out 2>&1 &' % comm.upload_dir
#services = {'uwsgi':uwsgicmd,'salt-master':mastercmd,'salt-minion':minioncmd,'php-fpm':phpfpmcmd,'nginx':nginxcmd,'saltcron':saltcroncmd}
services = {'uwsgi':uwsgicmd,'salt-master':mastercmd,'php-fpm':phpfpmcmd,'nginx':nginxcmd,'saltcron':saltcroncmd,'SimpleHTTPServer':SimpleHTTPServercmd}
try:
if sys.argv[1].startswith('restart') and sys.argv[1] != 'restart':
servicename = sys.argv[1].replace('restart','')
Expand Down
Binary file modified saltweb/static/rrd/172.16.1.220_localhost.localdomain/connum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified saltweb/static/rrd/172.16.1.220_localhost.localdomain/load.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified saltweb/static/rrd/172.16.1.238_test1/connum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified saltweb/static/rrd/172.16.1.238_test1/load.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions saltweb/templates/alarm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'index.html' %}

{% block title %}监控报警记录{% endblock %}

{% block page-content %}
<div class="location_div">位置:监控 >> 监控报警记录 </div>
<h2>监控报警记录</h2>
<table class="table">
<th>Saltid</th><th>To</th><th>报警信息</th><th>变更时间</th>
<tr>
{% for ret in rets %}
<td>{{ ret.hostid }}</td>
<td>{{ ret.to }}</td>
<td>{{ ret.msg }}</td>
<td>{{ ret.nowtime }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
12 changes: 11 additions & 1 deletion saltweb/templates/groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block page-content %}
<div class="location_div">位置:分组管理 </div>
<h3>添加监控</h3>
<h3>主机分组</h3>
说明:<br>
<form class="form-inline" action="" method="post" style="margin-bottom:0;">
组名:<input type="text" name='groupname' class="input-small" placeholder="输入组名">
Expand All @@ -23,4 +23,14 @@ <h3>添加监控</h3>
</tr>
{% endfor %}
</table>
<h3>联系人分组</h3>
<table class="table">
<th>组名</th><th>联系人</th>
{% for k,v in rets.items %}
<tr>
<td>{{k}}</td>
<td>{{v}}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
4 changes: 4 additions & 0 deletions saltweb/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<li><a href="{% url 'server' %}">服务监控</a></li>
<li class="divider"></li>
<li><a href="{% url 'monitor1' %}">图形监控</a></li>
<li class="divider"></li>
<li><a href="{% url 'alarm' %}">监控报警记录</a></li>
</ul>
</li>
<li><a href="{% url 'sysuser' %}">系统用户管理</a></li>
Expand Down Expand Up @@ -144,6 +146,8 @@
<li><a href="{% url 'server' %}">服务监控</a></li>
<li class="divider"></li>
<li><a href="{% url 'monitor1' %}">图形监控</a></li>
<li class="divider"></li>
<li><a href="{% url 'alarm' %}">监控报警记录</a></li>
</ul>
</li>
<li><a href="{% url 'sysuser' %}">系统用户管理</a></li>
Expand Down
1 change: 1 addition & 0 deletions saltweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
url(r'^salt/monitor/$', monitor ,name='monitor'),
url(r'^salt/monitor1/$', monitor1 ,name='monitor1'),
url(r'^salt/urlmonitor/$', urlmonitor ,name='urlmonitor'),
url(r'^salt/alarm/$', alarm ,name='alarm'),
url(r'^salt/server/$', server ,name='server'),
url(r'^salt/assets/$', assets ,name='assets'),
url(r'^salt/minions/$', minions ,name='minions'),
Expand Down
Binary file modified saltweb/urls.pyc
Binary file not shown.
Loading

0 comments on commit d40a554

Please sign in to comment.