categraf支持多種方式進行部署、托管,社區里部署和管理categraf也是五花八門,大家自己使用方便即可。 之前我們覺得大家通過ansible之類的工具批量下發/更新就能很簡單地完成任務,最近很多用戶咨詢我們關于categraf有沒有更方便的升級方式,這也促使 我們思考如何讓用戶更快捷方便地完成服務管理與升級。 這兩天我們發布了一個新版本,這里講一下linux下的推薦方式, 歡迎大家提ISSUE和PR。
systemd
systemd 是一個 Linux 系統下的系統和服務管理工具,它是 Linux 啟動過程的第一個進程(PID=1),它用于管理整個系統的服務狀態,包括進程控制、日志記錄、系統狀態跟蹤等等。它可以在系統啟動時,并行啟動所有系統服務,可以很好地管理守護進程、網絡、時間、安全、日志和其他系統設置,實現了快速啟動,同時也提高了系統資源的利用率和效率。
與傳統的 SysVinit 不同,systemd 采用了各種新的技術來提高系統的可靠性和性能,例如 socket 激活器、并行啟動、單位控制等等。更重要的是,systemd 提供了一個強大的系統統計功能,能夠幫助管理員更好地了解和監控系統狀態。這些統計信息包括 CPU、內存、磁盤、網絡資源使用情況、特定服務的狀態等等。
目前,systemd 已經成為 Linux 系統下最受歡迎和最流行的服務管理工具之一, 我們推薦使用systemd進行categraf托管。
注:centos6等老系統sysvinit也支持
categraf與systemd
為了使用systemd更方便的進行托管,我們設計了以下命令
install
?創建categraf.service文件remove
?刪除categraf.service文件start
?啟動categraf服務 等價于 systemctl start categrafstop
?停止categraf服務 等價于 systemctl stop categrafstatus
?查看categraf運行狀態 等價于 systemctl status categrafupdate
?執行categraf升級,需要指定升級包的url
下面分別介紹一下每個參數及使用方法。
install
舉例,我將?https://download.flashcat.cloud/categraf-v0.3.36-linux-amd64.tar.gz?內容解壓到了 /opt/categraf目錄下, 執行sudo opt/categraf/categraf install
命令,會在/etc/systemd/system/目錄下創建categraf.service文件,文件內容如下
`install`命令會創建categraf.service文件,文件內容如下
```ini
# /etc/systemd/system/categraf.service
[Unit]
Description=Opensource telemetry collector
ConditionFileIsExecutable=/opt/categraf/categrafAfter=network-online.target
Wants=network-online.target[Service]
StandardOutput=journal+console
StandardError=journal+console
StartLimitInterval=3600
StartLimitBurst=10
ExecStart=/opt/categraf/categraf "-configs" "/opt/categraf/conf"WorkingDirectory=/opt/categrafRestart=on-failureRestartSec=120
EnvironmentFile=-/etc/sysconfig/categraf
KillMode=process
[Install]
WantedBy=multi-user.target
其實?install
?會做以下3件事情
- 創建categraf.service文件
- 指定WorkingDirectory 為categraf的目錄
- 通過?
-configs categraf所在目錄的conf
?指定配置目錄 - systemctl daemon-reload
remove
使用示例?sudo /opt/categraf/categraf --remove
remove動作會執行兩個動作
- 停止categraf , 等價于 systemctl stop categraf
- 刪除categraf.service文件
start
使用示例?sudo /opt/categraf/categraf --start
start動作等價?systemctl start categraf
stop
使用示例?sudo /opt/categraf/categraf --stop
stop動作等價?systemctl stop categraf
status
使用示例?sudo /opt/categraf/categraf --status
status動作等價?systemctl status categraf
update
update 動作用于升級categraf,需要指定升級包的url
使用示例?sudo /opt/categraf/categraf --update --update_url https://download.flashcat.cloud/categraf-v0.3.36-linux-amd64.tar.gz
這里有如下前提
- linux系統,systemd(或SysVinit)托管
- update_url 指定的包是?
tar.gz
?格式 ,包里包含一個categraf 可執行文件
下載包之后,categraf會進行解壓,替換二進制文件,清理臨時目錄和文件,重啟服務。
替換動作,使用壓縮包里的categraf替換執行命令的二進制 ,示例中是?/opt/categraf/categraf
, 如果你執行的是?/home/flashcat/categraf --update --update_url https://download.flashcat.cloud/categraf-v0.3.36-linux-amd64.tar.gz
?那么被替換的就是?/home/flashcat/categraf
二進制升級成功之后,日志會輸出?I! update categraf success
。