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
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.
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.
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!
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! !!
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