2020年11月28日 星期六

2020 For Developer Service (Windows OS Base) ELK+Fluent / PVE / Grafana 設定小記

因為目標系統環境並不是 Linux,但也沒關係,以下服務大多也只是在服務公司內部開發者的維運及內部服務,並不強求大型管理規模的配置。


Elasticsearch + Logstash + Kibana


簡稱 ELK,建置原因是內部有需要對多個服務做 Logging,像是 Error Log、Info Log。


安裝順序是 Elastic -> Logstash -> Kibana:

1. Elasticsearch: https://www.elastic.co/downloads/elasticsearch

2. Logstash: https://www.elastic.co/downloads/logstash

3. Kibana: https://www.elastic.co/downloads/kibana


安裝完 Elasticsearch 之後,需要到安裝目錄修改 config,讓伺服器支援公開連線:

1. 打開 elasticsearch.yml

2. 在 Network 新增:

# ---------- Network ----------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#

3. 在 Discovery  新增:

 --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
discovery.zen.ping.unicast.hosts: ["0.0.0.0"]
#


之後, ELK 可以做成快速捷徑啟動:

1. 去 elasticsearch 目錄下把 elasticsearch.bat 加入到捷徑

2. 建立一個 logstash.cmd ,使用以下命令
"C:\logstash-7.10.0\bin\logstash.bat" -f "C:\[選擇 logstash.config 所在的目錄]\logstash.config"

3. 去 kibana 目錄下把 kibana.bat 加入到捷徑


可以用檔名順序 1. xxx 2.xxx 3.xxx ,打開 cmd: shell:startup ,把這些捷徑放到啟動目錄,一開機就會自動啟動。


Fluent Setup (Recommend use Gem to install)


建議使用 Gem 安裝 Fluent [1]:

gem install fluentd --no-doc


然後,找到一個目錄,使用 setup 指令:

fluentd --setup ./fluent


我的 fluent config:

# Input
<source>
    @type http
    port 8888
</source>
<source>
    @type forward
    port 24224
    bind 0.0.0.0
</source>
# Output
<match *.**>
    @type elasticsearch
    host 192.168.50.227
    port 9200
    logstash_format true
    logstash_prefix fluentd-${tag}
    time_key logdate
    <buffer tag>
        flush_interval 5s
    </buffer>
</match>


最後啟動時,使用這個指令:

fluentd -c .\fluent\fluent.conf


可以把這個指令放到 cmd 快速啟動。


最後,在不同的內網上做 log 測試 (node.js):

var logger = require('fluent-logger')
// The 2nd argument can be omitted. Here is a default value for options.
logger.configure('elasticsearch', {
   host: '192.168.50.227',
   port: 24224,
   timeout: 3.0,
   reconnectInterval: 600000 // 10 minutes
});

// send an event record with 'tag.label'
setInterval(()=>{
   logger.emit('label', {record: 'this is a log &&'});
   console.log("emitted");
}, 500)


Drone CI (Runner / Server) 搭配雲端版 Bitbucket


(Server)

在 Windows 直接安裝 docker,然後在指令列輸入:

docker pull drone/drone:1

執行:

docker run
--volume=C:\\Drone\\Server\\data:/data [請自訂一個目錄]
--env=DRONE_BITBUCKET_CLIENT_ID=[Bitbucket OAuthKey]
--env=DRONE_BITBUCKET_CLIENT_SECRET=[Bitbucket OAuthSecret]
--env=DRONE_RPC_SECRET=[自訂的 PRC Secret,可以用 openssl 產生,請先存好等等要用]
--env=DRONE_SERVER_HOST=xxx.xxx.xxx.xxx:2221 [這台 server 對外 ip,也可以用 ngrok]
--env=DRONE_SERVER_PROTO=http
--env=DRONE_AGENTS_ENABLED=true [打開 agent 等等 runner 跑起來比較不會出事]
--publish=2221:80
--publish=443:443
--restart=always
--detach=true
--name=drone drone/drone:1



(Runner)

有點詭異, windows 上的 docker 裝 latest 版的 image 才不會出事:

docker pull drone/drone-runner-docker

docker run -d
-v /var/run/docker.sock:/var/run/docker.sock
-e DRONE_RPC_PROTO=http
-e DRONE_RPC_HOST=[server 的 IP]
-e DRONE_RPC_SECRET=[剛才 server 上的 rpc_secret] 
-e DRONE_RUNNER_CAPACITY=5
-e DRONE_RUNNER_NAME=[自行命名]
-p 1998:3000
--restart always
--name runnerAA
drone/drone-runner-docker [不要貼 :1,直接用 lastest 比較不容易出事 ]


Proxmox VE

直接去官網裝,不過如果要裝在 VirtualBox 上,在網路端的設置要打開混合模式(全部允許)。


電腦系統監控 Monitoring


使用 WinExporter 把資料傳送到 Promethous ,然後再透過 Grafana 去建立可視化的介面。 


Reference:

[1]: https://docs.fluentd.org/installation/install-by-gem

[2]: https://ithelp.ithome.com.tw/articles/10217489

[3]: https://ithelp.ithome.com.tw/users/20118848/ironman/2682

沒有留言:

張貼留言

© Mac Taylor, 歡迎自由轉貼。
Background Email Pattern by Toby Elliott
Since 2014