跳到主要內容

Streamlining Docker Logging with Logspout and Syslog

Streamlining Docker Logging with Logspout and Syslog

Introduction

In the realm of containerized applications, efficient logging is paramount for maintaining system health and diagnosing issues effectively. Docker, renowned for its versatile ecosystem, offers numerous logging solutions tailored to container environments. Among these, Logspout stands out as a lightweight log router specifically designed for Docker. Paired with syslog, the standard logging protocol, Logspout simplifies the collection and forwarding of logs from Docker containers to external destinations. This blog post delves into configuring Logspout to seamlessly integrate with syslog, facilitating efficient logging for Dockerized applications.


Understanding the Components

Before delving into the setup process, let's briefly review the core components:

- Docker: A leading containerization platform empowering developers to package, distribute, and run applications and dependencies within isolated containers.

- Logspout: A versatile log router dedicated to gathering logs from Docker containers and efficiently forwarding them to various output destinations, offering a lightweight and flexible logging solution.

- Syslog: A standard logging protocol widely employed in Unix and Linux systems, facilitating centralized logging by defining a standardized message format and supporting various transport protocols for transmitting logs to remote servers.

Setting Up Logspout with Syslog

Now, let's outline the steps to configure Logspout to forward Docker container logs to a syslog server:

1. Stop Rsyslog Service: Halt the existing syslog service, if running on the same host as Logspout, to prevent conflicts with Logspout's syslog forwarding.

2. Configure Firewall Rules: Ensure the firewall settings permit incoming connections on the syslog port (typically port 514) to enable communication between Logspout and the syslog server.

3. Start Logspout Container: Deploy Logspout as a Docker container, ensuring to mount the Docker socket (/var/run/docker.sock) to grant Logspout access to container logs.

4. Specify Syslog Endpoint: When initiating the Logspout container, specify the syslog endpoint to which logs should be forwarded, including the IP address, port, and desired protocol (e.g., syslog+tcp).

5. Monitor Incoming Logs: Once Logspout is operational, monitor incoming logs using tools like netcat (nc) to verify successful forwarding to the syslog server.


Benefits of Using Logspout with Syslog

Integrating Logspout with syslog offers several benefits:

- Centralized Logging: Syslog facilitates centralized logging, enabling organizations to aggregate logs from multiple Docker containers in a unified location for seamless monitoring and analysis.

- Scalability: Logspout's lightweight architecture and Docker-native design ensure scalability, enabling it to handle large volumes of log data across distributed container environments efficiently.

- Flexibility: Syslog supports various transport protocols, providing flexibility in log transmission and storage methods, ensuring compatibility with existing logging infrastructure and tools.



Command Line Integration:
```bash
dmin@avaserver:~$ sudo service rsyslog stop
dmin@avaserver:~$ sudo ufw allow 514
Rules updated
Rules updated (v6)
dmin@avaserver:~$ sudo sh -c "while true; do { nc -vl 514; } done"

dmin@avaserver:~$ sudo docker run --volume=/var/run/docker.sock:/var/run/docker.sock gliderlabs/logspout syslog+tcp://10.36.172.152:514
# logspout v3.2.6 by gliderlabs
# adapters: udp tls raw syslog multiline tcp
# options : persist:/mnt/routes
# jobs : http[logs,routes,health]:80 pump routes
# routes :
# ADAPTER ADDRESS
```

留言

這個網誌中的熱門文章

[解決方法] docker: permission denied

前言 當我們執行docker 指令時若出現以下錯誤訊息 docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/create: dial unix /var/run/docker.sock: connect: permission denied. See 'docker run --help'. 表示目前的使用者身分沒有權限去存取docker engine, 因為docker的服務基本上都是以root的身分在執行的, 所以在指令前加sudo就能成功執行指令 但每次實行docker指令(就連docker ps)都還要加sudo實在有點麻煩, 正確的解法是 我們可以把目前使用者加到docker群組裡面, 當docker service 起來時, 會以這個群組的成員來初始化相關服務 sudo groupadd docker sudo usermod -aG docker $USER 需要退出重新登錄後才會生效 Workaround 因為問題是出在權限不足, 如果以上方法都不管用的話, 可以手動修改權限來解決這個問題 sudo chmod 777 /var/run/docker.sock https://docs.docker.com/install/linux/linux-postinstall/

[C#] Visual Studio, 如何在10分鐘內快速更改命名專案名稱

前言: 由於工作需要, 而且懶得再重寫類似的專案, 所以常常將之前寫的專案複製一份加料後, 再重新命名編譯 假設今天我有一個專案HolyUWP, 我想把它重新命名成 BestUWP 時該怎麼做? 以下是幾個簡單的的步驟 使用Visual Studio 2017 備份原來專案 更改Solution名稱 更改Assembly name, Default namespce 更改每支程式碼的Namespace 更改專案資料夾名稱 備份原來專案 由於怕改壞掉, 所以在改之前先備份 更改Solution名稱 更改sln的名稱, 這邊我改成BestUWP.sln 使用Visual Studio打開你的.sln, 右鍵點擊Solution後選擇Rename, 這邊我把它重新命名成BestUWP(跟檔案名稱一致) 必要的話可以順便修改Porject名稱 更改Assembly name, Default namespce 進入 Project > OOXX Properties    修改Assembly Name, Default namesapce 更改每支程式碼的Namespace 基本上隨便挑一支有用到預設Namesapce(HolyUWP)的程式碼來改就好了 重新命名後點擊Apply,  這個動作做完後所有用到舊Namespace的程式碼都會被改成新的 更改專案資料夾名稱 以上動作做完後, 基本上就可以把專案編譯出來測看看了~

[解決方法] mac 作業系統上無法使用 docker

  錯誤訊息 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 原因 因為 docker 的設計是走 client-server 的架構,  如果少裝了 server 的部分就會出現以上的錯誤訊息 解決方法 因為 docker daemon 需要使用 linux kernel 上的某些功能, 所以若想要在 mac 的 OS X 上使用 docker 必須額外起一台 linux VM 給 docker daemon 用  Step 1. 安裝 virtual box $ brew install virtualbox --cask   Step 2. 安裝 docker machine $ brew install docker-machine --cask   Step 3. 設定 使用 docker-machine 建立 VM 跑容器 $docker-machine create --driver virtualbox default $docker-machine restart   輸出環境變數 $docker-machine env default 如果執行以上的指令出現錯誤訊息 Error checking TLS connection: ...  可以執行以下指令重新產生憑證 $docker-machine regenerate-certs 最後套用環境變數, 讓 docker 知道要怎麼去跟這台 VM 溝通  $eval $(docker-machine env default)   測試 若做完以上的步驟沒噴錯誤訊息的話, 可以跑個 hello-world 看看 docker daemon 有沒有起來 $docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:95ddb6c31407e84e91a986b004aee40975cb0