如题,Seata 和 Nacos 的自启问题。
很久之前我提过一个类似的问题,https://www.v2ex.com/t/887703 ,当时就是需要执行 Tomcat 的启动脚本,不过当时用 rc-local 解决了,现在却怎么也启动不了了。
这种基于 tomcat 开发的程序大多是有一个启动脚本,执行该脚本后后会自动在后台启动对应的程序。
现在已经尝试过的方案:
systemd 的 service 文件:
[Unit]
Description = NacOS
After = network.target syslog.target
Wants = network.target
[Service]
Type=forking
Environment = "JAVA_HOME=/usr/local/jdk1.8.0_291"
Environment = "JRE_HOME=/usr/local/jdk1.8.0_291/jre"
Environment = "CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib"
Environment = "PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin"
ExecStart=/opt/nacos/bin/startup.sh -m standalone
#ExecStop=/opt/nacos/bin/shutdown.sh
[Install]
WantedBy = multi-user.target
报错:
● nacos.service - NacOS
Loaded: loaded (/etc/systemd/system/nacos.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2022-12-06 13:35:11 CST; 1min 47s ago
Process: 1048 ExecStart=/opt/nacos/bin/startup.sh -m standalone (code=exited, status=0/SUCCESS)
Main PID: 1278 (code=exited, status=127)
Dec 06 13:35:09 localhost.localdomain systemd[1]: Starting NacOS...
Dec 06 13:35:09 localhost.localdomain startup.sh[1048]: /opt/nacos/bin/startup.sh: line 19: uname: command not found
Dec 06 13:35:09 localhost.localdomain startup.sh[1048]: /opt/nacos/bin/startup.sh: line 108: sed: command not found
Dec 06 13:35:11 localhost.localdomain startup.sh[1048]: /usr/local/jdk1.8.0_291/bin/java -Xms2048m -Xmx2048m -Xmn256m -Dnacos.st...:+Prin
Dec 06 13:35:11 localhost.localdomain startup.sh[1048]: nacos is starting with standalone
Dec 06 13:35:11 localhost.localdomain startup.sh[1048]: nacos is starting ,you can check the /opt/nacos/logs/start.out
Dec 06 13:35:11 localhost.localdomain systemd[1]: Started NacOS.
Dec 06 13:35:11 localhost.localdomain systemd[1]: nacos.service: main process exited, code=exited, status=127/n/a
Dec 06 13:35:11 localhost.localdomain systemd[1]: Unit nacos.service entered failed state.
Dec 06 13:35:11 localhost.localdomain systemd[1]: nacos.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
/opt/nacos/logs/start.out
内容:
/usr/local/jdk1.8.0_291/bin/java -Xms2048m -Xmx2048m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Djava.ext.dirs=/usr/local/jdk1.8.0_291/jre/lib/ext:/usr/local/jdk1.8.0_291/lib/ext -Xloggc:/opt/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/opt/nacos/plugins/health,/opt/nacos/plugins/cmdb -Dnacos.home=/opt/nacos -jar /opt/nacos/target/nacos-server.jar --spring.config.additional-location=file:/opt/nacos/conf/ --logging.config=/opt/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
/opt/nacos/bin/startup.sh: line 142: nohup: command not found
1
vibbow 2022-12-06 15:50:57 +08:00
盲猜是环境变量不对
|
2
roiding 2022-12-06 17:17:59 +08:00
找不到 nohup 哇噢 好神奇
|
3
zbatman 2022-12-06 17:24:03 +08:00
Description = NacOS
看到这句话我还寻思又出什么新 OS 了 |
4
wangyu17455 2022-12-06 19:24:39 +08:00
实在不行塞 docker 里用 docker 的自启?
|
5
tairan2006 2022-12-06 19:54:09 +08:00
应该就是环境变量问题,你手动能启动的话就不需要设置那么多环境变量啊。
|
6
iluolSNS 2022-12-06 23:21:25 +08:00
我是直接 docker 省事
|
7
yso 2022-12-07 00:58:31 +08:00
再写一个 shell 脚本,把环境变量放进去呢?
|
8
ec0 2022-12-07 01:31:34 +08:00
Environment 不支持变量,所以你的 4 个 Environment 只有前两个是正常的,后面两个 Environment 里的变量没有展开
比如 PATH 的内容就是 “$PATH:$JAVA_HOME/bin:$JRE_HOME/bin” ,这会导致命令无法找到,从而报错 所以你可以 1. 不使用变量,手动展开变量,比如 Environment = "CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib" 改成 Environment = "CLASS_PATH=.:/usr/local/jdk1.8.0_291/lib/dt.jar:/usr/local/jdk1.8.0_291/lib/tools.jar:/usr/local/jdk1.8.0_291/jre/lib" 2. 如 7F 所说 ,再写一个 shell 脚本,把环境变量放进去,在新 shell 脚本调用 startup.sh ,或者直接修改 startup.sh ,在 startup.sh 的开头设置环境变量 |
9
ec0 2022-12-07 01:42:10 +08:00
还有,修改 Service 后需要 systemctl daemon-reload
|