-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpage.deployment.svn.xml
341 lines (323 loc) · 12.8 KB
/
webpage.deployment.svn.xml
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE webpage SYSTEM "/usr/share/xml/docbook/custom/website/2.5.0/schema/dtd/website.dtd">
<webpage id="deployment.svn">
<config param="desc" value="Article" />
<config param="rcsdate" value="$Date: 2013-01-15 14:34:09 +0800 (Tue, 15 Jan 2013) $" />
<head>
<title>Deployment SVN</title>
<titleabbrev>Deployment SVN</titleabbrev>
<summary></summary>
</head>
<webtoc />
<section>
<title>Installation</title>
<ulink url="https://github.com/netkiller/deployment.git" />
<screen>
$ git clone https://github.com/netkiller/deployment.git
$ chmod 755 -R deployment
$ export DEPLOY_HOME=~/deployment
</screen>
<para></para>
<screen>
export DEPLOY_HOME=/home/user/deployment
</screen>
</section>
<webtoc />
<section>
<title>使用说明</title>
<screen>
<![CDATA[
neo@ubuntu:~/deployment$ bin/deploy
Usage: bin/deploy [OPTION] <server-id> <directory/timepoint>
OPTION:
stage {development|testing|production}
deploy <domain> <host>
revert <domain> <host> <revision>
backup <domain> <host> <directory>
release <domain> <host> <tags> <message>
list
list <domain> <host>
import <domain> <host> <dir>
export <domain> <host> <dir>
clean <domain> <host>
log <project> <line>
CONFIG:
conf list
conf new <project>
conf remove <project>
conf show <project>
conf edit <project>
cron show
cron setup
cron edit
]]>
</screen>
</section>
<section>
<title>模拟演示</title>
<orderedlist>
<title>环境说明</title>
<listitem>
<para>development 开发环境</para>
</listitem>
<listitem>
<para>testing 测试环境,代码来自开发环境的合并</para>
</listitem>
<listitem>
<para>production 生产环境,当testing环境通过测试后,将testing 合并到 主干 即成为生产环境的代码 </para>
<para>另外我们可以通过release功能将主干的代码复制到tags中,命名采用版本号</para>
</listitem>
</orderedlist>
</section>
<section>
<title>创建配置文件</title>
<section>
<title>development</title>
<para>部署开发代码到开发环境</para>
<para>cat deployment/conf/development/mydomain.com/www.conf </para>
<screen>
REPOSITORIES=svn://192.168.2.1/mydomain.com/www.mydomain.com
TRUNK=${REPOSITORIES}/trunk
BRANCHES=${REPOSITORIES}/branches
TAGS=${REPOSITORIES}/tags
REPOSITORY=${BRANCHES}/development
MODE=RSYNC
OPTION="--delete --password-file=$PREFIX/conf/development/passwd"
REMOTE="[email protected]"
DESTINATION=mydomain.com/www.mydomain.com
</screen>
<para>创建密码文件</para>
<screen>
$ cat deployment/conf/development/passwd
eF9nJCcGKJPsiqZsfjGXxwfF41cLibTo
</screen>
</section>
<section>
<title>testing</title>
<para>部署测试分支到测试环境</para>
<para>cat deployment/conf/testing/mydomain.com/www.conf </para>
<screen>
REPOSITORIES=svn://192.168.2.1/mydomain.com/www.mydomain.com
TRUNK=${REPOSITORIES}/trunk
BRANCHES=${REPOSITORIES}/branches
TAGS=${REPOSITORIES}/tags
REPOSITORY=${BRANCHES}/testing
MODE=RSYNC
OPTION="--delete --password-file=$PREFIX/conf/testing/passwd"
REMOTE="[email protected]"
DESTINATION=mydomain.com/www.mydomain.com
</screen>
<para>创建密码文件</para>
<screen>
$ cat deployment/conf/testing/passwd
eF9nJCcGKJPsiqZsfjGXxwfF41cLibTo
</screen>
</section>
<section>
<title>production</title>
<para>部署主干代码到远程主机</para>
<para>cat deployment/conf/production/mydomain.com/www.conf </para>
<screen>
REPOSITORIES=svn://192.168.2.1/mydomain.com/www.mydomain.com
TRUNK=${REPOSITORIES}/trunk
BRANCHES=${REPOSITORIES}/branches
TAGS=${REPOSITORIES}/tags
REPOSITORY=${TRUNK}
MODE=RSYNC
OPTION="--delete --password-file=$PREFIX/conf/production/passwd"
REMOTE="[email protected]"
DESTINATION=mydomain.com/www.mydomain.com
</screen>
<para>创建密码文件</para>
<screen>
$ cat deployment/conf/production/passwd
eF9nJCcGKJPsiqZsfjGXxwfF41cLibTo
</screen>
</section>
<section>
<title>配置排出列表</title>
<para>有时我们不希望某些文件被上传到服务器上。我们可以通过排除列表来排除上传</para>
<screen>
cat exclude/mydomain.com/www.lst
/test/phpinfo.php
/config/database.php
/backup/*.sql
</screen>
</section>
<section>
<title>配置文件管理</title>
<para>生产环境的安全问题,例如数据库联接信息,开发环境与测试环境的数据库是可以供发人员和测试人员随意操作的,损坏之后恢复即可,但生产环境的数据库是不能随便操作的,除运维人员其他人是不应该有权限的, 我们希望部署到生产环境的时候使用另一个配置文件,并且这个配置文件只有运维人员才能编辑。</para>
<para>config/database.php 将覆盖原有的配置文件,然后上传到生产环境</para>
<screen>
vim share/production/mydomain.com/www/config/database.php
...
你的数据库连接信息
...
</screen>
</section>
<section>
<title>部署前/后脚本</title>
<para>部署前需要做什么</para>
<screen>
$ cat libexec/mydomain.com/www/before
rsync -au $DEPLOY_HOME/src/production/mydomain.com/www.mydomain.com/cn/* $DEPLOY_HOME/src/production/mydomain.com/www.mydomain.com/news/
rsync -au $DEPLOY_HOME/src/production/mydomain.com/www.mydomain.com/images/* $DEPLOY_HOME/src/production/mydomain.com/www.mydomain.com/bbs/images/
rsync -au $DEPLOY_HOME/src/production/mydomain.com/www.mydomain.com/css/* $DEPLOY_HOME/src/production/mydomain.com/www.mydomain.com/news/css
</screen>
<para>部署后需要做什么</para>
<screen>
cat libexec/mydomain.com/www/after
ssh [email protected] "chown www:www -R /www/mydomain.com"
ssh [email protected] "chown 700 -R /www/mydomain.com"
ssh [email protected] "chown 777 -R /www/mydomain.com/www.mydomain.com/images/upload"
</screen>
</section>
</section>
<section>
<title>配置部署节点</title>
<para>在需要部署的节点上安装rsync</para>
<screen>
<![CDATA[
yum install xinetd rsync -y
vim /etc/xinetd.d/rsync <<VIM > /dev/null 2>&1
:%s/yes/no/
:wq
VIM
# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
]]>
</screen>
<para>/etc/rsyncd.conf 配置文件</para>
<screen>
<![CDATA[
# cat /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 8
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
hosts deny=*
hosts allow=192.168.2.0/255.255.255.0
[www]
uid = www
gid = www
path = /www
ignore errors
read only = no
list = no
auth users = www
secrets file = /etc/rsyncd.passwd
[mydomain.com]
uid = www
gid = www
path = /www/mydomain.com
ignore errors
read only = no
list = no
auth users = mydomain
secrets file = /etc/rsyncd.passwd
[example.com]
uid = www
gid = www
path = /www/example.com
ignore errors
read only = no
list = no
auth users = example
secrets file = /etc/rsyncd.passwd
]]>
</screen>
<para>创建密码</para>
<screen>
<![CDATA[
cat > /etc/rsyncd.passwd <<EOD
www:eF9nJCcGKJPsiqZsfjGXxwfF41cLibTo
mydomain:eF9nJCcGKJPsiqZsfjGXxwfF41cLibTo
example:eF9nJCcGKJPsiqZsfjGXxwfF41cLibTo
EOD
]]>
</screen>
</section>
<section>
<title>部署代码</title>
<para>开发环境部署</para>
<screen>
$ ~/deployment/bin/deploy development mydomain.com myid
</screen>
<para>测试环境部署</para>
<screen>
$ ~/deployment/bin/deploy testing mydomain.com myid
</screen>
<para>生产环境部署</para>
<screen>
$ ~/deployment/bin/deploy production mydomain.com myid
</screen>
<para>每次部署都会在服务器 /www/mydomain.com/backup/ 下备份更改的文件</para>
<para>release 升级你的版本</para>
<screen>
$ ~/deployment/bin/deploy release mydomain.com www 2.0
</screen>
</section>
<section>
<title>日志</title>
<para>部署日志 deploy.YYYY-MM-DD.log, 记录部署时间与动态</para>
<screen>
$ cat log/deploy.2012-08-03.log
[2012-08-03_10:46:32] [update] /home/www/deployment/src/development/mydomain.com/info.mydomain.com
[2012-08-03_10:46:33] [deploy] /home/www/deployment/src/development/mydomain.com/info.mydomain.com => [email protected]:mydomain.com/infoadmin.mydomain.com
[2012-08-03_10:46:47] [update] /home/www/deployment/src/development/mydomain.com/info.mydomain.com
[2012-08-03_10:46:48] [deploy] /home/www/deployment/src/development/mydomain.com/info.mydomain.com => [email protected]:mydomain.com/infoadmin.mydomain.com
[2012-08-03_10:55:27] [update] /home/www/deployment/src/development/mydomain.com/myid.mydomain.com
[2012-08-03_10:55:28] [deploy] /home/www/deployment/src/development/mydomain.com/myid.mydomain.com => [email protected]:mydomain.com/myid.mydomain.com
[2012-08-03_10:56:21] [update] /home/www/deployment/src/development/example.com/ad.example.com
[2012-08-03_10:56:22] [deploy] /home/www/deployment/src/development/example.com/ad.example.com => [email protected]:example.com/ad.example.com
[2012-08-03_10:56:23] [update] /home/www/deployment/src/development/example.com/admin.example.com
[2012-08-03_10:56:24] [deploy] /home/www/deployment/src/development/example.com/admin.example.com => [email protected]:example.com/admin.example.com
[2012-08-03_10:56:27] [update] /home/www/deployment/src/development/example.com/images.example.com
[2012-08-03_10:56:28] [deploy] /home/www/deployment/src/development/example.com/images.example.com => [email protected]:example.com/images.example.com
[2012-08-03_10:56:30] [update] /home/www/deployment/src/development/example.com/info.example.com
[2012-08-03_10:56:31] [deploy] /home/www/deployment/src/development/example.com/info.example.com => [email protected]:example.com/info.example.com
[2012-08-03_10:56:33] [update] /home/www/deployment/src/development/example.com/myid.example.com
[2012-08-03_10:56:34] [deploy] /home/www/deployment/src/development/example.com/myid.example.com => [email protected]:example.com/myid.example.com
[2012-08-03_10:56:36] [update] /home/www/deployment/src/development/example.com/pic-load.example.com
[2012-08-03_10:56:36] [deploy] /home/www/deployment/src/development/example.com/pic-load.example.com => [email protected]:example.com/pic-load.example.com
[2012-08-03_10:56:39] [update] /home/www/deployment/src/development/example.com/pic-post.example.com
[2012-08-03_10:56:39] [deploy] /home/www/deployment/src/development/example.com/pic-post.example.com => [email protected]:example.com/pic-post.example.com
[2012-08-03_10:56:41] [update] /home/www/deployment/src/development/example.com/www.example.com
[2012-08-03_10:56:42] [deploy] /home/www/deployment/src/development/example.com/www.example.com => [email protected]:example.com/www.example.com
[2012-08-03_11:33:24] [update] /home/www/deployment/src/development/mydomain.com/info.mydomain.com
[2012-08-03_11:33:30] [deploy] /home/www/deployment/src/development/mydomain.com/info.mydomain.com => [email protected]:mydomain.com/infoadmin.mydomain.com
</screen>
<para>项目日志 www.example.com.log 记录项目有哪些更新, 上传的细节, 你能通过日志看到那些文件被上传</para>
<screen>
<![CDATA[
$ cat log/www.example.com.log
A /srv/deploy/src/example.com/www.example.com/index.html
Checked out revision 5.
At revision 5.
2012/05/08 19:19:08 [30062] building file list
2012/05/08 19:19:08 [30062] sent 46 bytes received 12 bytes 16.57 bytes/sec
2012/05/08 19:19:08 [30062] total size is 13 speedup is 0.22
2012/05/08 19:19:17 [30081] building file list
2012/05/08 19:19:17 [30081] sent 46 bytes received 12 bytes 6.11 bytes/sec
2012/05/08 19:19:17 [30081] total size is 13 speedup is 0.22
/usr/bin/svn copy svn://192.168.2.1/example.com/www.example.com/trunk svn://192.168.2.1/example.com/www.example.com/tags/2.0
2012/06/25 13:44:26 [3000] <f+++++++++ cn/download.html
2012/07/18 17:04:37 [12782] building file list
2012/07/18 17:04:37 [12782] .d..t...... ad/inc/
2012/07/18 17:04:37 [12782] <f..t...... ad/inc/config.html
2012/07/18 17:04:37 [12782] .d..t...... cn/inc/
2012/07/18 17:04:37 [12782] .d..t...... cn/news/inc/
2012/07/18 17:04:37 [12782] <f..t...... cn/news/inc/config.html
2012/07/18 17:04:37 [12782] .d..t...... tw/inc/
2012/07/18 17:04:37 [12782] .d..t...... tw/news/inc/
2012/07/18 17:04:37 [12782] <f..t...... tw/news/inc/config.html
2012/07/18 17:04:37 [12782] sent 12151 bytes received 156 bytes 8204.67 bytes/sec
2012/07/18 17:04:37 [12782] total size is 5009355 speedup is 407.03
]]>
</screen>
</section>
</webpage>