forked from net592/OneOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.txt
210 lines (145 loc) · 6.41 KB
/
install.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
####saltshaker 环境搭建 Ubuntu 14.04.3 LTS
1、安装pip 详细文档及使用http://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/
下载pip
wget "https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz#md5=3823d2343d9f3aaab21cf9c917710196" --no-check-certificate
安装pip
tar -xzvf pip-7.1.2.tar.gz
cd pip-7.1.2
python setup.py install
2、安装saltstack 版本 salt 2015.5.3 (Lithium)
官方文档http://docs.saltstack.cn/zh_CN/latest/topics/installation/ubuntu.html
一键添加软件源仓库并导入PPA的key
add-apt-repository ppa:saltstack/salt
手动添加软件源仓库和导入PPA key
echo deb http://ppa.launchpad.net/saltstack/salt/ubuntu `lsb_release -sc` main | sudo tee /etc/apt/sources.list.d/saltstack.list
wget -q -O- "http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x4759FA960E27C0A6" | sudo apt-key add -
更新软件仓库
apt-get update
安装saltstack
apt-get install salt-master
apt-get install salt-minion
apt-get install salt-syndic
apt-get install salt-api
3、安装cherrypy
pip install cherrypy==3.8.0
4、配置api
使用系统pam进行认证,添加系统用户和密码
useradd -M -s /sbin/nologin admin
passwd admin
用户名:admin
密码:admin
添加saltapi.conf 文件
vim /etc/salt/master.d/saltapi.conf
rest_cherrypy:
port: 8000
host: 127.0.0.1
disable_ssl: true
external_auth:
pam:
admin:
- .*
- '@runner'
- '@wheel'
/etc/init.d/salt-master restart
/etc/init.d/salt-api restart
netstat -tnlp | grep 8000 看到8000端口监听在127.0.0.1上就可以了
5、安装及配置Django 和 Django crontab
pip install Django==1.8.4
pip install django-crontab
vim settings.py 配置数据库和salt api 认证信息
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'saltshaker', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'sina', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
根据添加的系统用户信息,在settings.py 行尾添加如下信息,进行salt api 的认证配置
# SaltStack API
SALT_API_URL = 'http://127.0.0.1:8000'
SALT_API_USER = 'admin'
SALT_API_PASSWD = 'admin'
#执行如下命令
python manage.py migrate 同步数据
python manage.py runserver 0.0.0.0:9000 运行服务
python manage.py createsuperuser 设置后台管理员用户名和密码,此用户名和密码用于登陆web页面
python manage.py crontab add 添加计划任务用于生成'/tmp/salt_dashboard.tmp' 文件
saltshaker 环境搭建 CentOS6.X
1、安装saltstack 版本 salt 2015.5.3 (Lithium)
rpm --import https://repo.saltstack.com/yum/redhat/6/x86_64/latest/SALTSTACK-GPG-KEY.pub
yum clean all
yum install salt-master salt-minion salt-api salt-syndic
2、其他软件安装和配置见saltsalt在Ubuntu中的安装
使用 nginx 和 uwsgi 运行 saltshaker
1、pip install uwsgi django-uwsgi
2、https://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
3、yum install nginx
Return Data To Mysql
1. vim /etc/salt/master 在行尾添加如下行 使用MasterJobCache-Master-SideReturner 这中存储模式
mysql.host: '127.0.0.1'
mysql.user: 'root'
mysql.pass: 'sina'
mysql.db: 'saltshaker'
mysql.port: 3306
#### Returner job cache to mysql #####
master_job_cache: mysql
2. service salt-master restart
3. 修改salt mysql.py 文件 /usr/lib/python2.7/dist-packages/salt/returners/mysql.py
默认数据库字段为 fun jid return id success full_ret alter_time 由于return 在python里面是关键字
无法在django的models里面创建此字段 所以修改字段为 fun jid returns minion_id success full_ret alter_time
即修改mysql.py的235行,内容如下
官方建表语句https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html
228 def returner(ret):
229 '''
230 Return data to a mysql server
231 '''
232 try:
233 with _get_serv(ret, commit=True) as cur:
234 sql = '''INSERT INTO `salt_returns`
235 (`fun`, `jid`, `returns`, `minion_id`, `success`, `full_ret` )
236 VALUES (%s, %s, %s, %s, %s, %s)'''
237
238 cur.execute(sql, (ret['fun'], ret['jid'],
239 json.dumps(ret['return']),
240 ret['id'],
241 ret.get('success', False),
242 json.dumps(ret)))
243 except salt.exceptions.SaltMasterError as exc:
244 log.critical(exc)
245 log.critical('Could not store return with MySQL returner. MySQL server unavailable.')
异步请求 Celery
安装 django-celery (3.1.17)
pip install django-celery==3.1.17
安装 celery
pip install celery==3.1.17
安装 rbbitmq
详细安装请产看官方文档 ubuntu 安装http://www.rabbitmq.com/install-debian.html
Centos 安装http://www.rabbitmq.com/install-rpm.html
添加rbbitmq 仓库
echo 'deb http://www.rabbitmq.com/debian/ testing main' >> /etc/apt/sources.list
避免安装时发生警告添加公钥
wget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc
apt-key add rabbitmq-signing-key-public.asc
安装rabbitmq
apt-get install rabbitmq-server
开启rabbitmq-management plugin管理插件
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
配置django setting.py
添加如下行到setting.py
# celery + rabbitmq
platforms.C_FORCE_ROOT = True # Running a worker with superuser privileges
djcelery.setup_loader()
BROKER_HOST = "127.0.0.1"
BROKER_PORT = 5672
BROKER_USER = "guest"
BROKER_PASSWORD = "guest"
BROKER_VHOST = "/"
执行如下命令创建djcelery的相关数据库表
python manage.py makemigrations
python manage.py migrate
启动celery worker
python manage.py celery worker --loglevel=info
ggggg