consul

[文章目录]
  1. 搭建 Consul server mode
  2. 搭建 Consul client mode
    1. 模擬 Linux node 環境,進行 Member join 與 Health Checks
      1. 啟用 Consul agent client mode

今日首搭 Consul 服務環境,以下簡單扼要做紀錄
環境說明:

  • Consul server mode: Ubuntu 18.04 192.168.42.12
  • Consul client mode: Vagrant CentOS 7 192.168.42.199

搭建 Consul server mode

在 Docker 環境中,建立 Docker-composer file

1
2
3
4
5
6
7
8
9
10
11
12
version: '3'
services:
Consul:
image: "consul"
ports:
- "8300-8302:8300-8302"
- "8500:8500"
- "8600:8600"
- "8301-8302:8301-8302/udp"
- "8600:8600/udp"
volumes:
- /etc/consul.d:/consul/config

設定配置檔案 server.json

1
2
3
4
5
6
7
8
9
{
"datacenter": "Office-Lab",
"data_dir": "/consul/data",
"bootstrap_expect": 1,
"log_level": "INFO",
"node_name": "Afu-Lab2",
"server": true,
"bind_addr": "0.0.0.0"
}

啟動 consul 服務

1
$ sudo docker-compose -f consul-docker-compose.yml up -d

查看 Consul Web 介面 http://server-ip:8500

啟動 server mode 遇到問題,記錄如下:

  • server agent log 顯示:
    [ERR] agent: failed to sync remote state: No cluster leader
    • 原因:這是環境中第一台 Consul server node,需要藉由 -bootstrap-expect=1 作為初始引導方式。
  • server agent log 顯示:
    Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: -1, DNS: 8600)
    Cluster Addr: 192.168.42.12 (LAN: 8301, WAN: 8302)
    • 原因:agent 預設服務綁定於 localhost 介面上,故需要運用參數 -client=0.0.0.0 進行調整。
  • server agent log 顯示:
    [ERR] memberlist: Failed push/pull merge: Member 'C7-java' part of wrong datacenter 'dc1' from=192.168.42.199:49356
    • 原因:這顯示 Member 'C7-java' 啟動時,採用預設參數 datacenter 'dc1' ,只需在 member 端啟用時新增參數 -datacenter=office-lab 即可。

備註:
如果不選擇 Docker 啟用 Consul server 服務,可以試試指令啟用,方式如下
啟用 Consul agent server

1
sudo consul agent -server -bootstrap-expect=1 -node=Afu-Lab2 -enable-local-script-checks=true -config-dir=/etc/consul.d -data-dir=/tmp/consul -bind=0.0.0.0 -client=0.0.0.0


搭建 Consul client mode

在 CentOS 7 環境下,下載官方 Binary file
解壓縮後,移至 /usr/bin 目錄下

1
2
3
wget https://releases.hashicorp.com/consul/1.4.0/consul_1.4.0_linux_amd64.zip
unzip consul_1.4.0_linux_amd64.zip
sudo mv consul /usr/bin/

驗證執行

1
2
3
$ consul -v
Consul v1.4.0
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

參考網址:
https://www.consul.io/docs/install/index.html#precompiled-binaries

模擬 Linux node 環境,進行 Member join 與 Health Checks

準備設定檔案

ssh.json
官網說明

1
2
3
4
5
6
7
8
9
10
// 定義 SSH TCP check
{
"check": {
"id": "ssh",
"name": "SSH TCP on port 22",
"tcp": "localhost:22",
"interval": "10s",
"timeout": "1s"
}
}

啟用 Consul agent 官方教學網址

啟用 Consul agent client mode

啟用指令:

1
2
3
4
consul agent -client=0.0.0.0 -node=C7-java \
-join=192.168.42.12 -bind=192.168.42.199 \
-enable-local-script-checks=true -data-dir=/tmp/consul \
-config-dir=/etc/consul.d -datacenter=office-lab

啟用後,會有三個新 Listen port:8301、8500、8600

在查看一次 Consul Web 介面 http://server-ip:8500,即可發現 Nodes、Health Checks 的變化。

  • Client agent log 顯示:
    Multiple private IPv4 addresses found. Please configure one with 'bind' and/or 'advertise'.
    • 原因:這是因為 node 網路具備兩個以上的網路IP,故必須配置其中一個網卡 IP。

備註:
以上相關配置參數,可參考官網說明

new-blog

[文章目录]
  1. 12月25日 聖誕節快樂~
    1. 創建紀錄
      1. Github pages 服務註冊與創建
      2. HEXO安裝
      3. Github pages 與 Hexo 整合

12月25日 聖誕節快樂~

也是今日,第一次創建部落格資源天地,其用意是將平時工作小心得、重要記載等等,以文章方式予以記錄下來,呈現於此!

第一篇,就是紀錄此部落格的誕生過程~
在聖誕夜之前,我在 gitbook 記載了 K8s 研讀的過程與心得,也有另一篇關於公司專案 Ceph 的過程記載,但礙於 Gitbook 免付費授權條件下,只能各有一篇 public \ Private 文章,經過長期文章考量,付費條件有點稍貴,故沒選擇採購付費授權,暫且不繼續於 Gitbook 上寫文章。

在聖誕夜之後,開始搜尋部落格有哪些資源可以使用,心想自己想要的條件有:串接 github 版控、支援 Markdown、無需自行架站~
最後選擇了蠻多人使用的 github pages 服務 + Hexo

話說:在 github pages 官網上、在眾多網友上都提到 “Using Jekyll”,但自己發現該服務工具是基於 Ruby 環境上運行,但我對 Ruby 環境印象是,很耗資源,起因於 Gitlab 案例 XDD
在我的小 MacBook 上,希望能簡潔有力就夠~找到 Hexo 服務工具來搭配創建部落格。

創建紀錄

Github pages 服務註冊與創建

首先要有 Github 帳號,沒有的話當要更要先完成註冊囉~
依照 [官方網站](https://pages.github.com/) 依序完成 repo creategit 使用介面git clonehello worldgit push 等基本程序。

這時候可以瀏覽你的網站,舉例我的 tksmisafu.github.io
tksmisafu 即為 github 帳號,目前並不能接受’非同名帳號’。

HEXO安裝

  1. 我選擇在自己的 MacBook 環境下進行安裝。
  2. 參考 Hexo 安裝說明頁,確認安裝需求:Node.js、Git
  3. 先安裝 NVM,再透過 NVM工具進行 Node.js
  4. Hexo 安裝
1
2
# NVM 安裝
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
1
2
# 安裝 Node.js
nvm install stable
1
2
3
4
# 安裝 Hexo
# 一旦所有的必備軟體都安裝完畢後,即可透過 npm 安裝 Hexo:

$ npm install -g hexo-cli

Github pages 與 Hexo 整合

選擇一個目錄下,創建部落格

1
$ hexo init blog

整合 github.io 在部落格目錄下,執行

1
2
3
4
5
6
7
8
9
10
11
# 整合 github.io 在部落格目錄下,執行
npm install hexo-deployer-git --save

# 修改配置 _config.yml,找到deploy之後進行以下修改
deploy:
type: git
repo: https://github.com/<yourAccount>/<repo>
branch: <your-branch>

# 部署與上傳
hexo clean && hexo deploy

再次瀏覽部落格,即可見到首頁成果了 ^.^

Hello World

[文章目录]
  1. Quick Start
    1. Create a new post
    2. Run server
    3. Generate static files
    4. Deploy to remote sites

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment