簡介
本文檔介紹如何為ParStream歷史資料庫的init.d或Systemd建立服務檔案。
必要條件
需求
思科建議您應具備Linux相關知識。
採用元件
本文件所述內容不限於特定軟體和硬體版本。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
設定
邊緣霧處理模組(EFM)安裝套件不包含現成的init.d或Systemd服務檔案。
您可以在此處找到建立服務檔案的簡單範例。
對於init.d
[root@cen7 ~]# cat /etc/init.d/parstream
#!/bin/bash
# parstream init script.
export PARSTREAM_HOME=/opt/cisco/kinetic/parstream/
export LD_LIBRARY_PATH=$PARSTREAM_HOME/lib:$LD_LIBRARY_PATH
PARSTREAM_SERVERNAME="parstream1"
PARSTREAM_USER="EFM"
case "$1" in
'start')
echo "Starting ParStream daemon $PARSTREAM_SERVERNAME as $PARSTREAM_USER"
sleep 2
su -c "cd $PARSTREAM_HOME;$PARSTREAM_HOME/bin/start.sh $PARSTREAM_SERVERNAME" $PARSTREAM_USER
;;
'stop')
echo "Stopping ParStream daemons for user $PARSTREAM_USER"
stopstatus=$(pkill -c -U $PARSTREAM_USER -15 parstream-serv)
echo "$stopstatus processes stopped"
;;
*)
# usage
echo "usage: $0 start|stop"
exit 1
;;
esac
確保調整環境變數以符合您的環境:PARSTREAM_HOME、PARSTREAM_SERVERNAME和PARSTREAM_USER。
建立檔案後,請確定檔案已標示為可執行檔。
對於Systemd
root@cen7 ~]# cat /etc/systemd/system/parstream.service
[Unit]
Description=ParStream
After=network.target
[Service]
Type=simple
User=EFM
Environment=LD_LIBRARY_PATH=/opt/cisco/kinetic/parstream/lib:$LD_LIBRARY_PATH
WorkingDirectory=/opt/cisco/kinetic/parstream/
ExecStart=/opt/cisco/kinetic/parstream/bin/parstream-server parstream1 --confdir=/opt/cisco/kinetic/parstream/conf/
Restart=on-failure
[Install]
WantedBy=multi-user.target
確保調整配置變數,以便與ExecStart行上的User=和servername環境相匹配。
建立服務檔案之後,請確定您已更新systemd中的常駐程式檔案:
[root@cen7 ~]# systemctl daemon-reload
驗證
使用本節內容,確認您的組態是否正常運作。
若要驗證指令碼/服務檔案是否如預期般運作,您可以嘗試啟動和停止服務。
對於init.d
[root@cen7 ~]# /etc/init.d/parstream start
Starting ParStream daemon parstream1 as EFM
Server Process ID: 5056
Output is written to: /var/log/parstream/server-5054-20180423-1648.log
[root@cen7 ~]# ps aux |grep 5056
EFM 5056 0.8 0.7 1235292 27200 ? Sl 16:48 0:00 /opt/cisco/kinetic/parstream//bin/parstream-server parstream1
...
[root@cen7 ~]# /etc/init.d/parstream stop
Stopping ParStream daemons for user EFM
1 processes stopped
對於Systemd
[root@cen7 ~]# systemctl start parstream
[root@cen7 ~]# systemctl status parstream
● parstream.service - ParStream
Loaded: loaded (/etc/systemd/system/parstream.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2018-04-23 16:49:30 CEST; 3s ago
Main PID: 5186 (parstream-serve)
CGroup: /system.slice/parstream.service
└─5186 /opt/cisco/kinetic/parstream/bin/parstream-server parstream1 --confdir=/opt/cisco/kinetic/parstream/conf/
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30]:unknown-000000:PROT-77086: **** PID: 5186 (host: cen7)
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30]:unknown-000000:PROT-71005: **** config file: "/opt/cisco/kinetic/parstream/conf/parstream.ini"
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30]:unknown-000000:WARNING-77082: Number of maximum file descriptors (1024) is lower than recommended value 98304
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30]:unknown-000000:WARNING-77113: Maximum number of mmap'ed areas (65530) is lower than recommended value 1966080.
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30.273380]:parstream1-164930:PROT-77045: Source Revision: 717e27f507aab73fdc0c3f9d4377ff658726c270
Apr 23 16:49:30 cen7 parstream-server[5186]: Local Changes:
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30.278632]:parstream1-164930:PROT-77018: cluster node config: ClusterNodeConfig(clusterId = 'localCluster', claimLeadershipInitT...geInterval = 0
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30.280474]:parstream1-164930:PROT-77018: channel instance created for accept on port: 23460
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30.281084]:parstream1-164930:PROT-77134: Entering state ClaimLeadershipState, got event InitialEvent
Apr 23 16:49:30 cen7 parstream-server[5186]: [2018-04-23T16:49:30.281243]:parstream1-164930:PROT-77065: Running cluster leader detection (limited until 2018-Apr-23 16:51:30)
Hint: Some lines were ellipsized, use -l to show in full.
[root@cen7 ~]# systemctl stop parstream
如您所見,ParStream進程在您在服務檔案中定義的使用者下啟動,在您請求停止服務之後,所有內容都將得到清理。
疑難排解
本節提供的資訊可用於對組態進行疑難排解。
如果啟動時遇到問題,請檢查以下項:
- init.d或Systemd服務檔案中的可配置引數(使用者、路徑、ParStream伺服器名稱)
- 檢查ParStream的日誌檔輸出(位於/var/log/parstream)
- 對於SystemD:systemctl status parstream的輸出
- journalctl —unit=parstream的輸出