0%

cacti-syslog-docker

這篇文章中的東西都是我之前沒使用過的,用了一個禮拜的時間看 cacti 和 syslog,一個禮拜的時間看 docker。

使用套件

  1. cacti
  2. syslog
  3. rsyslog
  4. syslog-ng
  5. docker

開發環境

MacOS High Sierra 10.13.6

Docker-compose

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
version: '2'
services:

cacti:
image: "smcline06/cacti"
container_name: cacti
hostname: cacti
ports:
- "80:80"
environment:
- DB_NAME=cacti_master
- DB_USER=cactiuser
- DB_PASS=cactipassword
- DB_HOST=db
- DB_PORT=3306
- DB_ROOT_PASS=rootpassword
- INITIALIZE_DB=1
- TZ=Asia/Taipei
volumes:
- cacti-data:/cacti
- cacti-spine:/spine
- cacti-backups:/backups
- ./syslog:/cacti/plugins/syslog
links:
- db

db:
image: maria
container_name: cacti_db
hostname: db
ports:
- "3306:3306"
command:
- mysqld
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --max_connections=200
- --max_heap_table_size=128M
- --max_allowed_packet=32M
- --tmp_table_size=128M
- --join_buffer_size=128M
- --innodb_buffer_pool_size=1G
- --innodb_doublewrite=ON
- --innodb_flush_log_at_timeout=3
- --innodb_read_io_threads=32
- --innodb_write_io_threads=16
- --innodb_buffer_pool_instances=9
- --innodb_file_format=Barracuda
- --innodb_large_prefix=1
- --innodb_io_capacity=5000
- --innodb_io_capacity_max=10000
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- TZ=Asia/Taipei
volumes:
- cacti-db:/var/lib/mysql

syslog_ng:
image: balabit/syslog-ng:3.14.1
command: "--no-caps"
ports:
- "32774:514/udp"
environment:
- DB_NAME=cacti_master
- DB_USER=cactiuser
- DB_PASS=cactipassword
- DB_HOST=db
volumes:
- ./syslog-ng/syslog-ng.conf:/etc/syslog-ng/syslog-ng.conf

volumes:
cacti-db:
cacti-data:
cacti-spine:
cacti-backups:

心得

我一開始先在一個 container 實驗,將 cacti + rsyslog + mariaDB 通通安裝在裡面,並且成功收到外面機器傳入的 syslog。

但是在使用 docker-compose 時遇到許多問題,首先是 rsyslog 無法將接收到的 syslog 寫入到 DB 的 table 中,因此我改用 syslog_ng 來接受傳入的 syslog。然後在 cacti 使用 syslog 插件時出現錯誤,發現是套件自動產生的 table 格式不對,因此我需要先 build 一個已經有建好 table 的 docker image。

我上面的 Docker-compose 就是使用自己 build 好的 maria image,其他要自行設定的還有 syslog-ng 以及自己下載的 syslog 插件。