首页 > 其他分享 >systemd管理常用中间件

systemd管理常用中间件

时间:2023-03-02 10:55:59浏览次数:27  
标签:opt bin systemd ## 中间件 常用 kafka logstash

 使用systemd管理常用中间件(elasticsearch、logstash、kafka和zookeeper), 方便服务启停、开机自启

1.1添加systemd管理脚本

红字配置需要根据实际环境修改路径。若为单节点集群模式需要添加多个管理脚本,分别替换相应配置,以脚本名称区分。

##生成kafka管理脚本
cat > /etc/systemd/system/kafka.service <<EOF
[Unit]
Description=kafka.service
After=network.target


[Service]
Type=forking
Environment=JAVA_HOME=/opt/jdk1.8.0_231
ExecStart=/opt/kafka_2.12-2.5.1/bin/kafka-server-start.sh -daemon /opt/kafka_2.12-2.5.1/config/server.properties
ExecStop=/opt/kafka_2.12-2.5.1/bin/kafka-server-stop.sh
Restart=always
[Install]
WantedBy=multi-user.target
EOF


# #生成zookeeper管理脚本


cat > /etc/systemd/system/zookeeper.service <<EOF
[Unit]
Description=zookeeper.service
After=network.target


[Service]
Type=forking
Environment=JAVA_HOME=/opt/jdk1.8.0_231
ExecStart=/opt/kafka_2.12-2.5.1/bin/zookeeper-server-start.sh -daemon /opt/kafka_2.12-2.5.1/config/zookeeper.properties
ExecStop=/opt/kafka_2.12-2.5.1/bin/zookeeper-server-stop.sh
Restart=always
[Install]
WantedBy=multi-user.target
EOF


##生成es管理脚本
cat > /etc/systemd/system/elasticsearch.service <<EOF
[Unit]
Description=ElasticSearch.service
Requires=network.service
After=network.service


[Service]
User=finance
Group=finance
LimitNOFILE=65536
LimitMEMLOCK=infinity
Environment=JAVA_HOME=/opt/elasticsearch-7.4.2/jdk
ExecStart=/opt/elasticsearch-7.4.2/bin/elasticsearch
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
SuccessExitStatus=143
Restart=on-failure
RestartSec=42s


[Install]
WantedBy=multi-user.target
EOF


##生成logstash管理脚本
cat > /etc/systemd/system/logstash.service <<EOF
[Unit]
Description=Logstash.service
Requires=network.service
After=network.service


[Service]
LimitNOFILE=65536
LimitMEMLOCK=infinity
Environment=JAVA_HOME=/opt/jdk1.8.0_231
Environment=KAFKA_HOST=10.99.73.74:9092
Environment=ELASTICSEARCH_HOST=10.99.73.74:9200
Environment=ELASTICSEARCH_USER=elastic
Environment=ELASTICSEARCH_PASS=changeme
Environment=LOGSTASH_CONFIG_PATH=/opt/logstash-7.4.2/config
Environment=LOGSTASH_PIPELINE_PATH=/opt/logstash-7.4.2/config/pipeline
ExecStart=/opt/logstash-7.4.2/bin/logstash -l "/home/finance/Logs/logstash/" "--path.data" "/opt/logstash-7.4.2/data" "--config.reload.automatic"
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
SuccessExitStatus=143
Restart=on-failure
RestartSec=42s


[Install]
WantedBy=multi-user.target
EOF
##logstash 使用systemd管理后日志名称和原来会有区别,如果启动错误使用 journalctl -ru logstash查看报错信息。


##每次修改后需要重新加载配置文件
systemctl daemon-reload


##若服务已启动先停掉,Es、logsash需要手动杀进程
systemctl stop zookeeper
systemctl stop kafka


##测试启动
systemctl start zookeeper
systemctl start kafka
systemctl start elasticsearch
systemctl start logstash


##查看状态
systemctl status zookeeper
systemctl status kafka
systemctl status elasticsearch
systemctl status logstash


##开机自启
systemctl enable zookeeper
systemctl enable kafka
systemctl enable elasticsearch
systemctl enable logstash

 

 

标签:opt,bin,systemd,##,中间件,常用,kafka,logstash
From: https://www.cnblogs.com/zhongmingke/p/17171047.html

相关文章