[LINUX] I made a ready-to-use syslog server with Play with Docker

I want to create a server for verification with Docker

So I played with Play with Docker!

● What you need docker account Browser (Chrome recommended)

● What I made https://hub.docker.com/r/tt15/centos-syslog

Play with Docker operation

https://labs.play-with-docker.com

Log in to Play with Docker with a Docker account (like Chrome recommends) Press ** + ADD NEW INSTANCE ** to launch the Docker environment (IP address is automatically assigned, and instances can be pinged to the Internet) Type the Docker command on the screen on the right to build the environment.

docker.test


$ docker pull centos:centos7

centos7: Pulling from library/centos
ab5ef0e58194: Pull complete 
Digest: sha256:4a701376d03f6b39b8c2a8f4a8e499441b0d567f9ab9d58e4991de4472fb813c
Status: Downloaded newer image for centos:centos7
docker.io/library/centos:centos7

You can download the image on Docker Hub with docker pull.

▼▼▼▼▼▼▼▼▼

docker.test


$ docker run -it -d --privileged --name centos -p 514:514/udp centos:centos7 /sbin/init

484bc681a2d879c94ecabc8401756fee3828f5d16c9ed8dfffb3937d91506100

Launch the pulled image with docker run. By the way, you can check the image that is currently running with docker ps.

▼▼▼▼▼▼▼▼▼

docker.test


$ docker exec -it centos /bin/bash

[root@484bc681a2d8 /]# 

You can execute commands on the image you are running with docker exec.

CentOS operation

bash.rx


[root@484bc681a2d8 /]# yum -y install rsyslog
[root@484bc681a2d8 /]# yum -y install net-tools

After each execution, the state of dobadoba and download will appear. Install the required packages for syslogd. Also installed a command package to display CentOS network information. Used for later operation check. The rest is completed with minimal rsyslog settings.

rsyslog.conf operation

bash.test


[root@484bc681a2d8 /]# vi /etc/rsyslog.conf

rsyslog.conf


# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514

Since you have installed rsyslog, you should have rsyslog.conf. Since all the settings are commented out with #, delete the # in the above 4 places. In terms of vi, you can delete the character to the right of the cursor with x. To save, press the exc key, press:, and enter wq !.

▼▼▼▼▼▼▼▼▼

bash.rx



[root@484bc681a2d8 /]# systemctl restart rsyslog
[root@484bc681a2d8 /]# netstat -antup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address   Foreign Address State PID/Program name    
tcp     0      0 0.0.0.0:514        0.0.0.0:*      LISTEN   879/rsyslogd        
tcp6    0      0 :::514             :::*           LISTEN   879/rsyslogd        
udp     0      0 0.0.0.0:514        0.0.0.0:*               879/rsyslogd        
udp6    0      0 :::514             :::*                    879/rsyslogd    

Restarting rsyslog will load the modified rsyslog.conf. You can display the TCP and UDP connection status with netstat -antup. You can see that rsyslog is running on port 514.

The receiver of rsyslog is now ready!

Verification

In the same flow as before, do another ** + ADD NEW INSTANCE ** and start rsyslog. Only the setting part of rsyslog.conf is different when starting up the sender!

bash.tx


[root@484bc681a2d8 /]# vi /etc/rsyslog.conf
*.info;mail.none;authpriv.none;cron.none* @192.168.0.1:514
*.info;mail.none;authpriv.none;cron.none* @@192.168.0.1:514

Add these two lines at the very end of rsyslog.conf. Don't forget to change the IP address to that of the real environment. Also restart after setting!

▼▼▼▼▼▼▼▼▼

bash.tx


[root@484bc681a2d8 /]# logger
test1
test2
test3

It seems that the sender can send the log with the logger command. It will be sent to / var / log / messages on the receiving side, so let's take a look.

bash.rx


[root@484bc681a2d8 /]# tail /var/log/messages
Mar 15 07:05:43 484bc681a2d8 root: test1
Mar 15 07:05:45 484bc681a2d8 root: test2
Mar 15 07:05:46 484bc681a2d8 root: test3

tail is a command to display from the last line of the text file. I can send it properly! !!

Impressions

With Play with Docker, it was easy because the sender and receiver could be created quickly! I'm grateful that it can be completed with just a browser. Even after 4 hours, you can pull docker from anywhere by pushing the image created on Docker Hub. (You can use docker login, docker tag, docker push)

Recommended Posts

I made a ready-to-use syslog server with Play with Docker
Creating a Flask server with Docker
I made a fortune with Python.
I made a daemon with Python
Set up a Samba server with Docker
I made a character counter with Python
I made a web server with Raspberry Pi to watch anime
I made a development environment for Django 3.0 with Docker, Docker-compose, Poetry
I made a Hex map with Python
I made a life game with Numpy
I made a stamp generator with GAN
I made a poker game server chat-holdem using websocket with python
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a WEB application with Django
I made a neuron simulator with Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
Start a simple Python web server with Docker
[Python] I made a Youtube Downloader with Tkinter.
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I made a random number graph with Numpy
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a QR code image with CuteR
Tftp server with Docker
〇✕ I made a game
Proxy server with Docker
[AWS] I made a reminder BOT with LINE WORKS
I made a household account book bot with LINE Bot
I made a Christmas tree lighting game with Python
I made a vim learning game "PacVim" with Go
I made a window for Log output with Tkinter
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I made a falling block game with Sense HAT
I made blackjack with python!
I made an Xubuntu server.
I made a python text
I made a discord bot
I made COVID19_simulator with JupyterLab
I made Word2Vec with Pytorch
I made blackjack with Python.
I made wordcloud with Python.
I made a LINE BOT that returns parrots with Go
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
I made a resource monitor for Raspberry Pi with a spreadsheet
I made a puzzle game (like) with Tkinter in Python
I made a rigid Pomodoro timer that works with CUI
I made a surveillance camera with my first Raspberry PI.
I made a plug-in that can "Daruma-san fell" with Minecraft
[AWS] I made a reminder BOT with LINE WORKS (implementation)
I made a server with Python socket and ssl and tried to access it from a browser
I made a C ++ learning site
I made a simple circuit with Python (AND, OR, NOR, etc.)