Title

欧拉系统将opengauss数据库制作为开机自启动

创建服务单元文件

vim /etc/systemd/system/opengauss.service

写入服务配置

[Unit]
Description=OpenGauss Database Server
After=syslog.target network.target

[Service]
Type=forking
User=om
Group=dbgroup
Environment="GAUSSHOME=/opt/software/openGauss"
Environment="LD_LIBRARY_PATH=/opt/software/openGauss/lib"
# 启动命令
ExecStart=/opt/software/openGauss/bin/gs_ctl start -D /opt/software/openGauss/data/single_node -Z single_node
ExecStop=/opt/software/openGauss/bin/gs_ctl stop -D /opt/software/openGauss/data/single_node
ExecReload=/opt/software/openGauss/bin/gs_ctl restart -D /opt/software/openGauss/data/single_node -Z single_node

 

# 设置超时时间避免启动失败
TimeoutSec=300
Restart=on-failure
RestartSec=30

[Install]
WantedBy=multi-user.target

 

注意!!!

User和Group 为运行 openGauss 的用户及用户组
直接在 ExecStart 中使用完整路径,不要用变量。 $GAUSSHOME 不会被 systemd 解析,
在 ExecStart 中写$GAUSSHOME会导致运行服务时报错为217/USER错误:

ExecStart=/opt/software/openGauss/bin/gs_ctl start -D $GAUSSHOME/data/single_node -Z single_node
但 systemd 不会自动解析 $GAUSSHOME 环境变量,即使你在 Environment= 中设置了它。

重新加载并启动服务

systemctl daemon-reexec
systemctl daemon-reload
systemctl start opengauss
sudo systemctl enable opengauss
systemctl status opengauss.service

systemctl stop opengauss

 

posted @ 2025-04-30 13:44  Esurts~  阅读(222)  评论(0)    收藏  举报