Day 27 - 范例动手做 - Ansible 安装 Time-series DB

今天是安装 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 能吃到系统数据


<<:  《Day27》Oracle Database 安装

>>:  Day27 机房好狗结果展示(7)

[ Day 03 ] 建立一个 React.js 专案

对 React.js 有基本的概念後,我们就可以继续往下学习该如何建置和使用它罗! 开始环境建置 ...

从 IT 技术面细说 Search Console 的 27 组数字 KPI (2.5) :平均排名的图解

在这系列文的第二篇有提到,SEO 做得越好,平均排名是下降的,很多人都很惊讶,所以我就文章稍作解释:...

[Go mod 起手式] - Golang 套件到底要怎麽用?!

Go mod 是 go 1.11 version 之後出的管理套件的工具,并且Go 1.13 ver...

[30天 Vue学好学满 DAY9] v-if & v-show

v-if 条件式渲染 :true -> 渲染 可使用於template标签中 可进行断判断: ...

【Day30】综合练习:台铁即时时刻表!

本日作品: https://codepen.io/linchinhsuan/pen/KKMpBZb ...