Linux环境设置nacos开机自启
Linux环境设置nacos开机自启
·
主要适用于单机版nacos开机自启配置,具体步骤如下。
1.编写Systemd 服务
Systemd 服务的内容主要分为三个部分,控制单元(unit)的定义、服务(service)的定义、以及安装部分。
vim /lib/systemd/system/nacos.service
直接粘贴以下内容,Description为描述,After=network.target表示在网口启动后启动
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/nacos/bin/shutdown.sh
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.修改nacos启动文件
其中的jdk路径以自己实际安装路径为准
vim /usr/local/nacos/bin/startup.sh
#!/bin/bash
# Copyright 1999-2018 Alibaba Group Holding Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cygwin=false
darwin=false
os400=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
esac
error_exit ()
{
echo "ERROR: $1 !!"
exit 1
}
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/local/jdk-18.0.2.1
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/opt/taobao/java
#[ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME
if [ -z "$JAVA_HOME" ]; then
if $darwin; then
if [ -x '/usr/libexec/java_home' ] ; then
"startup.sh" 149L, 5229C
3.设置nacos开机启动
systemctl daemon-reload #重新加载服务配置
systemctl enable nacos.service #设置为开机启动
systemctl start nacos.service #启动nacos服务
systemctl stop nacos.service #停止nacos服务
systemctl stop firewalld.service #停止防火墙
systemctl disable firewalld.service #禁止防火墙开机启动
4.启动效果
更多推荐
已为社区贡献1条内容
所有评论(0)