目标
由于公司容器化上生产后,需要规范发布流程,而作为容器的基础服务harbor镜像仓库,通过自己来发布自己不太理,于是将镜像方式的harbor组件变更为进程方式发布。由于已经上线较长时间,各系统的配置诸如环境变量、配置文件、日志告警相关的一堆流程已配置过。改代码编译问题好办,如何让原来的环境变量、配置文件、日志文件等均不变化是目前需要解决的问题
环境
centos 7.2
1、harbor jobserivce ui为一套代码共用base config服务对于两服务的配置项CONFIG_PATH指向的配置文件不同,主要涉及分离端口监听问题
CONFIG_PATH=/apps/conf/harbor/jobservice/app.conf
CONFIG_PATH=/apps/conf/harbor/ui/app.conf
/apps/conf/harbor/jobservice/app.conf
httpport = 8080
/apps/conf/harbor/ui/app.conf
httpport = 8088
解决
环境变量问题可以通过systemd的EnvironmentFile变量解决
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
环境变量文件
cat
/apps/conf/harbor/jobservice/env
HARBOR_DB_HOST=
'192.168.1.23'
HARBOR_DB_PORT=3306
HARBOR_DB_USER=
'root'
HARBOR_DB_PASSWORD=
'1xxxv'
CONFIG_PATH=
/apps/conf/harbor/jobservice/app
.conf
systemd配置文件引用环境变量文件
cat
/usr/lib/systemd/system/harbor-jobservice
.service
[Service]
EnvironmentFile=
/apps/conf/harbor/jobservice/env
ExecStart=
/apps/svr/harbor/jobservice
启动该服务时相当于为该进程执行过一次
export
,不影响其他系统服务
export
VIP_HARBOR_DB_HOST=
'192.168.1.23'
export
VIP_HARBOR_DB_PORT=3306
export
VIP_HARBOR_DB_USER=
'root'
export
VIP_HARBOR_DB_PASSWORD=
'1xxxv'
export
CONFIG_PATH=
/apps/conf/harbor/jobservice/app
.conf
|
2、日志问题,进程由systemd接管后,日志写入到/var/log/messages里,现要将jobservice registry ui三个组件的日志分开写,每个日志的监控级别不同,registry日志里的error关键字并一定是错误,不分开写会错误日志报警问题
解决
该问题可以结合systemd与rsyslog服务配置共同处理具体处理如下
示例
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
|
jobservice配置
cat
/usr/lib/systemd/system/harbor-jobservice
.service
[Unit]
Description=Harbor Jobservice
After=network.target
[Service]
EnvironmentFile=
/apps/conf/harbor/jobservice/env
ExecStart=
/apps/svr/harbor/jobservice
ExecReload=
/bin/kill
-HUP $MAINPID
KillMode=process
StandardOutput=syslog
#日志采用syslog
StandardError=syslog
#日志采用syslog
SyslogIdentifier=jobservice
#日志标签
[Install]
WantedBy=multi-user.target
ui配置
cat
/usr/lib/systemd/system/harbor-ui
.service
[Unit]
Description=Harbor UI
After=network.target
[Service]
EnvironmentFile=
/apps/conf/harbor/ui/env
ExecStart=
/apps/svr/harbor/ui
ExecReload=
/bin/kill
-HUP $MAINPID
KillMode=process
StandardOutput=syslog
#日志采用syslog
StandardError=syslog
#日志采用syslog
SyslogIdentifier=ui
#日志标签
[Install]
WantedBy=multi-user.target
registry配置
cat
/usr/lib/systemd/system/registry
.service
[Unit]
Description=Harbor Registry
After=network.target
[Service]
ExecStart=
/apps/svr/harbor/registry
serve
/apps/conf/harbor/registry/config
.yml
ExecReload=
/bin/kill
-HUP $MAINPID
KillMode=process
StandardOutput=syslog
#日志采用syslog
StandardError=syslog
#日志采用syslog
SyslogIdentifier=registry
#日志标签
[Install]
WantedBy=multi-user.target
rsyslog配置
新增配置文件
/etc/rsyslog
.d
/harbor
.conf
if
$programname ==
'jobservice'
then
/apps/logs/harbor/jobservice/jobservice
.
test
.com.log
if
$programname ==
'jobservice'
then
~
if
$programname ==
'ui'
then
/apps/logs/harbor/ui/ui
.
test
.com.log
if
$programname ==
'ui'
then
~
if
$programname ==
'registry'
then
/apps/logs/harbor/registry/registry
.
test
.com.log
if
$programname ==
'registry'
then
~
|
日志分开写后效果
1
2
3
4
5
6
7
8
9
10
11
|
[root@harborB ~]
# tail -f /var/log/messages
Nov 14 15:21:10 harborB systemd: Stopping Harbor Registry...
Nov 14 15:21:10 harborB systemd: Started Harbor Registry.
Nov 14 15:21:10 harborB systemd: Starting Harbor Registry...
[root@harborB ~]
# tailf /apps/logs/harbor/registry/registry.test.com.log
Nov 14 15:21:10 harborB registry:
time
=
"2017-11-14T15:21:10.679673744+08:00"
level=info msg=
"redis not configured"
go.version=go1.8.3 instance.
id
=ece5a83c-6359-476e-8358-49bbb33ed441 service=registry version=
"v2.6.0+unknown"
Nov 14 15:21:10 harborB registry:
time
=
"2017-11-14T15:21:10.699754153+08:00"
level=info msg=
"using inmemory blob descriptor cache"
go.version=go1.8.3 instance.
id
=ece5a83c-6359-476e-8358-49bbb33ed441 service=registry version=
"v2.6.0+unknown"
Nov 14 15:21:10 harborB registry:
time
=
"2017-11-14T15:21:10.699862266+08:00"
level=info msg=
"listening on [::]:5000"
go.version=go1.8.3 instance.
id
=ece5a83c-6359-476e-8358-49bbb33ed441 service=registry version=
"v2.6.0+unknown"
|
systemd日志写入参考:https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file
本文转自 qwjhq 51CTO博客,原文链接:http://blog.51cto.com/bingdian/1981701