harbor进程组件化运行及systemd 进程日志分写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了harbor进程组件化运行及systemd 进程日志分写相关的知识,希望对你有一定的参考价值。
目标
由于公司容器化上生产后,需要规范发布流程,而作为容器的基础服务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变量解决
示例
环境变量文件 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服务配置共同处理具体处理如下
示例
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 ~
日志分开写后效果
[[email protected] ~]# 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... [[email protected] ~]# 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
以上是关于harbor进程组件化运行及systemd 进程日志分写的主要内容,如果未能解决你的问题,请参考以下文章
[架构之路-33]:目标系统 - 系统软件 - Linux OS用户空间程序的启动关闭监管 -- systemD进程与作用架构 (Cloud进程管理工具)