Harbor Process component Run and SYSTEMD process log write

Source: Internet
Author: User
Tags syslog rsyslog

Goal

Since the company is containerized on the production, need to standardize the release process, and as a container of basic services Harbor Mirror warehouse, through their own to publish themselves not too, so the image of the harbor component changed to process mode release. Because it has been online for a long time, the configuration of each system such as environment variables, configuration files, log alarms related to a bunch of processes have been configured. Change the code to compile the problem, how to make the original environment variables, configuration files, log files and so on do not change is the problem that needs to be solved at present



Environment

CentOS 7.2

1, harbor Jobserivce UI for a set of code shared base CONFIG service for two service configuration items Config_path point to a different configuration file, mainly related to the separation of port monitoring issues

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



Solve

environment variable problem can be solved by systemd environmentfile variable

Example

     environment variable File     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 configuration file Reference environment variable file     cat /usr/lib/systemd/system/ harbor-jobservice.service     [service]       Environmentfile=/apps/conf/harbor/jobservice/env      execstart=/apps/svr/harbor /jobservice            When you start the service, you perform an export for the process once, Does not affect other system services     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, log problems, process by systemd take over, log write to/var/log/messages, now Jobservice registry UI Three components of the log is written separately, each log monitoring level is different, Registry the error keyword in the log and must be wrong, do not separate write error log alarm problem


Solve

The problem can be combined with the SYSTEMD and Rsyslog service configuration to handle the specific processing as follows

Example

Jobservice Configuration 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.targetui Configuration 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.targetregistry Configuration 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.targetrsyslog Configuration New configuration file/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 ~ 


Log separate Write effect

[[email protected] ~]# tail -f /var/log/messagesnov 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 Log Write reference: Https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file

Harbor Process component Run and SYSTEMD process log write

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.