Docker centos 安裝syslog

來源:互聯網
上載者:User

標籤:

  在通常的Linux伺服器中,有一些服務本身沒有日誌,只能通過 tail -f /var/log/messages來查看其作業記錄,比如nrpe server。但是,如果想在docker容器中實現這個功能就需要費點事了。具體步驟如下:

  1、安裝rsyslog

# yum -y install rsyslog

 

  2、啟動syslog服務

# rsyslogd


  3、測試是否在messages中組建記錄檔

# logger "Hello World"


  結果發現,在messages中只有一下一行:"Aug  1 11:31:37 f2570fed2149 rsyslogd: [origin software="rsyslogd" swVersion="7.4.7" x-pid="73" x-info="http://www.rsyslog.com"] start",故可認定其未工作。原因是:“The problem was that in RHEL7 and Fedora we now use journald, which listens on /dev/log for incoming messages. In RHEL7 and Fedora, rsyslog actually reads messages from the journal via its API by default.But not all docker containers run systemd and journald. (Most don’t). In order to get the rsyslogd to work the way the user wanted, he would have to modify the configuration file, /etc/rsyslog.conf”。

  解決辦法如下:

  1、修改syslog配置——  # vi /etc/rsyslog.conf

1、注釋掉 $ModLoad imjournal 2、設定 $OmitLocalLogging 為 off3、注釋掉 $IMJournalStateFile imjournal.state

 

  2、提交容器至鏡像,重新建立容器

[[email protected] home]# docker commit f2570fed2149 centos_with_syslog:v1.0830e298b4c103f70154ec9c8ceae44ec4602ed22063dae8e13a3f9aff4c3260a[[email protected] home]# docker run -d -p 223:222 -v /dev/log:/dev/log -ti centos_with_syslog:v1.0 /run.shdc2eb83e80ced6f553eb1dd7032489d37b4d934a9126f61dfbd4d6a2243e98f1


  3、測實驗證

[[email protected] home]# docker exec -ti dc2eb83e80ced6f553eb1dd7032489d37b4d934a9126f61dfbd4d6a2243e98f1 /bin/bash[[email protected] /]# logger "hello everyone"[[email protected] /]# exitexit[[email protected] home]# tail -f /var/log/messages   (注意實在宿主機上的messages檔案中查看日誌)Aug  1 19:57:51 localhost docker: time="2015-08-01T19:57:51+08:00" level=info msg="-job log(exec_start: /bin/bash , dc2eb83e80ced6f553eb1dd7032489d37b4d934a9126f61dfbd4d6a2243e98f1, centos_with_syslog:v1.0) = OK (0)"Aug  1 19:57:51 localhost docker: time="2015-08-01T19:57:51+08:00" level=info msg="POST /v1.18/exec/9ae97d0666bf5abcd8d95eb87d10c5d013a0f006c2cb1adc7ff8f7baaacf14fc/resize?h=37&w=191"Aug  1 19:57:51 localhost docker: time="2015-08-01T19:57:51+08:00" level=info msg="+job execResize(9ae97d0666bf5abcd8d95eb87d10c5d013a0f006c2cb1adc7ff8f7baaacf14fc, 37, 191)"Aug  1 19:57:51 localhost docker: time="2015-08-01T19:57:51+08:00" level=info msg="-job execResize(9ae97d0666bf5abcd8d95eb87d10c5d013a0f006c2cb1adc7ff8f7baaacf14fc, 37, 191) = OK (0)"Aug  1 19:58:09 localhost logger: hello everyone

 

Docker centos 安裝syslog

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.