iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 27
1
DevOps

DevOps with Proxmox系列 第 27

Day 27 - 範例動手做 - Ansible 安裝 Time-series DB

  • 分享至 

  • xImage
  •  

今天是安裝 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

裝到現在,我們總共有三個容器

  • app (放服務的)
  • grafana (跑 Grafana 的)
  • tsdb (放 Time-series DB 的)

明天,我們要把 Agent 塞進 app,讓 TSDB 能吃到系統數據


上一篇
Day 26 - 範例動手做 - Ansible 安裝 Grafana
下一篇
Day 28 - 範例動手做 - 安裝 Monitor Agent
系列文
DevOps with Proxmox30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言