今天是安裝 Time-series DB,我們要安裝的 DB 是我們先前示範過的 InfluxDB 和 Prometheus
InfluxDB 因為有提供 deb 所以安裝起來比較簡單,但 Prometheus 安裝就稍微複雜了點,因為要手動複製檔案進系統
我們一樣拿之前寫好的 Terraform 和 Ansible 檔案來改,目錄結構大概如下
.
├── ansible.cfg
├── deploy.yml
├── lxc.tf
├── main.tf
├── roles
│ ├── apt_upgrade
│ │ └── tasks
│ │ └── main.yml
│ ├── install_influxdb
│ │ └── tasks
│ │ └── main.yml
│ └── install_prometheus
│ ├── files
│ │ ├── prometheus
│ │ │ ├── console_libraries
│ │ │ │ ├── menu.lib
│ │ │ │ └── prom.lib
│ │ │ ├── consoles
│ │ │ │ ├── index.html.example
│ │ │ │ ├── node-cpu.html
│ │ │ │ ├── node-disk.html
│ │ │ │ ├── node.html
│ │ │ │ ├── node-overview.html
│ │ │ │ ├── prometheus.html
│ │ │ │ └── prometheus-overview.html
│ │ │ ├── LICENSE
│ │ │ ├── NOTICE
│ │ │ ├── prometheus
│ │ │ ├── prometheus.yml
│ │ │ └── promtool
│ │ └── prometheus.service
│ └── tasks
│ └── main.yml
└── terraform.tfvars
11 directories, 26 files
這裡我們用的方式是在 Ansible 裡放好 Prometheus 的檔案,然後再透過 Ansible 複製進系統
此外我們在安裝 InfluxDB 時也開了一個 Database,讓 Telegraf 等等能寫進 InfluxDB
# roles/install_influxdb/tasks/main.yml
---
- name: Install InfluxDB
apt:
deb: https://dl.influxdata.com/influxdb/releases/influxdb_1.8.2_amd64.deb
tags:
- influxdb
- name: Enable and start InfluxDB
systemd:
name: influxdb
enabled: yes
state: started
tags:
- influxdb
- name: Create database telegraf
command: influx -execute 'CREATE DATABASE telegraf'
tags:
- influxdb
# roles/install_prometheus/tasks/main.yml
---
- name: Copy prometheus to /usr/local/bin
copy:
src: prometheus/prometheus
dest: /usr/local/bin/prometheus
owner: root
group: root
mode: '0755'
tags:
- prometheus
- name: Copy promtool to /usr/local/bin
copy:
src: prometheus/promtool
dest: /usr/local/bin/promtool
owner: root
group: root
mode: '0755'
tags:
- prometheus
- name: Create folder /etc/prometheus
file:
path: /etc/prometheus
owner: root
group: root
mode: '0755'
state: directory
tags:
- prometheus
- name: Copy console_libraries to /etc/prometheus
copy:
src: prometheus/console_libraries
dest: /etc/prometheus
owner: root
group: root
tags:
- prometheus
- name: Copy consoles to /etc/prometheus
copy:
src: prometheus/consoles
dest: /etc/prometheus
owner: root
group: root
tags:
- prometheus
- name: Copy prometheus.yml to /etc/prometheus
copy:
src: prometheus/prometheus.yml
dest: /etc/prometheus
owner: root
group: root
tags:
- prometheus
- name: Copy prometheus.service
copy:
src: prometheus.service
dest: /etc/systemd/system/prometheus.service
owner: root
group: root
mode: '0644'
tags:
- prometheus
- name: Systemd daemon-reload
systemd:
daemon_reload: yes
tags:
- prometheus
- name: Enable and start prometheus
systemd:
name: prometheus
enabled: yes
state: started
tags:
- prometheus
大概像這樣,接下來一樣是 terraform apply
裝到現在,我們總共有三個容器
明天,我們要把 Agent 塞進 app,讓 TSDB 能吃到系統數據