CenotOS环境Nacos安装,设置开机自启动
1、下载
nacos下载地址:https://github.com/alibaba/nacos/releases
2、安装
进入nacos所在目录,执行如下命令
tar -zxvf nacos-server-2.0.3.tar.gz -C /usr/local/
3、单机启动
修改/usr/local/nacos/bin目录下startup.sh启动文件设置单机启动,修改export MODE="cluster"值为standalone
export MODE="standalone"
4、启动测试
进入/usr/local/nacos/bin目录下,执行启动命令
./startup.sh
启动失败,查看/usr/local/nacos/logs下start.out日志文件,报错如下:
/usr/local/java/jdk-11.0.10/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:gc*:file=/usr/local/nacos/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400 -Dloader.path=/usr/local/nacos/plugins/health,/usr/local/nacos/plugins/cmdb -Dnacos.home=/usr/local/nacos -jar /usr/local/nacos/target/nacos-server.jar --spring.config.additional-location=file:/usr/local/nacos/conf/ --logging.config=/usr/local/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
Error: Could not find or load main class
Caused by: java.lang.ClassNotFoundException:
5、解决方案
进入/usr/local/nacos/bin/目录,修改启动文件startup.sh,修改内容如下:
x JAVA_OPT_EXT_FIX="-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
√ JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
x echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}"
√ echo "$JAVA ${JAVA_OPT}"
x echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
x nohup "$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
√ echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
√ nohup $JAVA ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
x:表示需要替换的,√:表示修改后的。
6、再次测试
进入/usr/local/nacos/bin目录下,执行启动命令
./startup.sh
输出结果:
/usr/local/java/jdk-11.0.10/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:gc*:file=/usr/local/nacos/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400 -Dloader.path=/usr/local/nacos/plugins/health,/usr/local/nacos/plugins/cmdb -Dnacos.home=/usr/local/nacos -jar /usr/local/nacos/target/nacos-server.jar --spring.config.additional-location=file:/usr/local/nacos/conf/ --logging.config=/usr/local/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
nacos is starting with standalone
nacos is starting,you can check the /usr/local/nacos/logs/start.out
表示之前启动问题解决,启动成功。
7、访问nacos
打开浏览器输入CentOS地址+端口+项目访问,即可看到nacos登录页面。
http://192.168.56.10:8848/nacos
8、随机启动配置
8.1、进入 /lib/systemd/system目录
cd /lib/systemd/system
8.2、在该目录下,创建文件nacos启动文件
vi nacos.service
添加内容如下
[Unit]
Description=nacos
After=network.target
[Service]
Environment="JAVA_HOME=/usr/local/java/jdk-11.0.10"
Type=forking
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/nacos/bin/shutdown.sh
ExecStop=/usr/local/nacos/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
注意:修改自己nacos所在路径
8.3、重载所有服务
systemctl daemon-reload
8.4、设置开机启动
systemctl enable nacos.service
8.5、查看开机启动状态
systemctl is-enabled nacos.service
8.6、查看服务状态
systemctl status nacos
8.7、手动启动 Nacos
systemctl start nacos
8.7、手动停止Nacos
systemctl stop nacos
8.8、手动重启
systemctl restart nacos
9、测试自启动
重启CentOS系统,查看Nacos是否自自动
查看Nacos服务状态
systemctl status nacos
输出结果:
● nacos.service - nacos
Loaded: loaded (/usr/lib/systemd/system/nacos.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2022-10-24 15:15:16 UTC; 1min 7s ago
Process: 707 ExecStart=/usr/local/nacos/bin/startup.sh -m standalone (code=exited, status=0/SUCCESS)
Tasks: 194
Memory: 547.8M
CGroup: /system.slice/nacos.service
└─748 /usr/local/java/jdk-11.0.10/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:gc*:file=/usr/local/nacos/logs/nacos_gc.log:time,tag...
Oct 24 15:15:15 10.0.2.15 systemd[1]: Starting nacos...
Oct 24 15:15:16 10.0.2.15 startup.sh[707]: /usr/local/java/jdk-11.0.10/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:gc*:file=/usr...s.home=/usr/
Oct 24 15:15:16 10.0.2.15 startup.sh[707]: nacos is starting with standalone
Oct 24 15:15:16 10.0.2.15 startup.sh[707]: nacos is starting,you can check the /usr/local/nacos/logs/start.out
Oct 24 15:15:16 10.0.2.15 systemd[1]: Started nacos.
Hint: Some lines were ellipsized, use -l to show in full.
表示已经启动成功。
通过IP+端口+项目访问登录页面测试
http://192.168.56.10:8848/nacos
已经可以成功访问Nacos登录页面了。
评论 (0)