Linux安装Nacos
一、先来选择SpringCloudAlibaba的版本吗,最终确认了2.2.6的版本对应Nacos版本为1.4.2
二、下载Nacos1.4.2
nacos1.4.2的下载路径:Release 1.4.2 (Apr 29th, 2021) · alibaba/nacos · GitHub
三、上传至服务器(工具:FileZilla),我放的路径为/opt/nacos
四、解压(工具:Xshell)
tar -zxvf nacos-server-1.4.2.tar.gz
五、进入解压后的nacos文件目录下,进入到bin目录下
cd /opt/nacos/nacos/bin
六、编辑 vim startup.sh脚本,修改
1、查看java位置
[root@master ~]# which java
/usr/local/jdk-11/bin/java
2、修改启动脚本(startup.sh)
vim startup.sh
七、进入/opt/nacos/nacos/conf目录下
cd /opt/nacos/nacos/conf
八、执行nacos自带的sql文件
创建数据库,数据库脚本在源码包有,在 nacos/conf/nacos-mysql.sql,把这个导入到数据库中
九、编辑 application.properties 修改如下
vim application.properties
十、单机启动,进入 /opt/nacos/nacos/bin 执行./startup.sh -m standalone
[root@master bin]# ./startup.sh -m standalone
/usr/local/jdk-11/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:gc*:file=/opt/nacos/nacos/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400 -Dloader.path=/opt/nacos/nacos/plugins/health,/opt/nacos/nacos/plugins/cmdb -Dnacos.home=/opt/nacos/nacos -jar /opt/nacos/nacos/target/nacos-server.jar --spring.config.additional-location=file:/opt/nacos/nacos/conf/ --logging.config=/opt/nacos/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
nacos is starting with standalone
nacos is starting,you can check the /opt/nacos/nacos/logs/start.out
十一、查看日志(cat /opt/nacos/nacos/logs/start.out)
可以看见下面的日志中,内网地址:http://192.168.106.141:8848/nacos/index.html
[root@master bin]# cat /opt/nacos/nacos/logs/start.out
/usr/local/jdk-11/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:gc*:file=/opt/nacos/nacos/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400 -Dloader.path=/opt/nacos/nacos/plugins/health,/opt/nacos/nacos/plugins/cmdb -Dnacos.home=/opt/nacos/nacos -jar /opt/nacos/nacos/target/nacos-server.jar --spring.config.additional-location=file:/opt/nacos/nacos/conf/ --logging.config=/opt/nacos/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
,--.
,--.'|
,--,: : | Nacos 1.4.2
,`--.'`|' : ,---. Running in stand alone mode, All function modules
| : : | | ' ,'\ .--.--. Port: 8848
: | \ | : ,--.--. ,---. / / | / / ' Pid: 4575|:' ';| / \ / \. ; ,. :|: /`./ Console: http://192.168.106.141:8848/nacos/index.html
' ';.;.--. .-. | / / ''||::|:;_
|||\|\__\/: ...' / '|.;:\\`. https://nacos.io
' : | ; .' ," .--.;|' ; :__|:|`----. \||'`--' / / ,. |' | '.'|\ \ / / /`--' /
' : | ; : .'\::`----' '--'. /
; |.'| , .-./\\ / `--'---''---'`--`---' `----'2022-09-14 17:38:28,648 INFO Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@73386d72' of type[org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2022-09-14 17:38:28,651 INFO Bean 'methodSecurityMetadataSource' of type[org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2022-09-14 17:38:28,973 INFO Tomcat initialized with port(s): 8848(http)2022-09-14 17:38:29,288 INFO Root WebApplicationContext: initialization completed in2967 ms
2022-09-14 17:38:30,951 INFO Initializing ExecutorService 'applicationTaskExecutor'2022-09-14 17:38:31,072 INFO Adding welcome page: class path resource [static/index.html]2022-09-14 17:38:31,328 INFO Creating filter chain: Ant [pattern='/**'], []2022-09-14 17:38:31,351 INFO Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@20580d4e, org.springframework.security.web.context.SecurityContextPersistenceFilter@3fa21d49, org.springframework.security.web.header.HeaderWriterFilter@91f565d, org.springframework.security.web.csrf.CsrfFilter@4ed5a1b0, org.springframework.security.web.authentication.logout.LogoutFilter@57e388c3, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6e31d989, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@65bb6275, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@21bd128b, org.springframework.security.web.session.SessionManagementFilter@3cd26422, org.springframework.security.web.access.ExceptionTranslationFilter@67b355c8]2022-09-14 17:38:31,413 INFO Initializing ExecutorService 'taskScheduler'2022-09-14 17:38:31,430 INFO Exposing 2 endpoint(s) beneath base path '/actuator'2022-09-14 17:38:31,523 INFO Tomcat started on port(s): 8848(http) with context path '/nacos'2022-09-14 17:38:31,526 INFO Nacos started successfully in stand alone mode. use external storage
十一、默认用户和密码一样:nacos(没关防火墙去关防火墙)
单机部署完成
题外话:设置开机自启动
一、进入/lib/systemd/system目录, 创建nacos.service文件
cd /lib/systemd/system
touch nacos.service
二、编辑nacos.service文件, 增加如下信息 (nacos路径替换成自己的路径即可)
[Unit]Description=nacos
After=network.target
[Service]Type=forking
ExecStart=/usr/nacos-server-1.1.3/nacos/bin/startup.sh -m standalone
ExecReload=/usr/nacos-server-1.1.3/nacos/bin/shutdown.sh
ExecStop=/usr/nacos-server-1.1.3/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]WantedBy=multi-user.target
三、编辑nacos/bin目录下的startup.sh, 增加JAVA_HOME
四、执行以下命令
重新加载所有service服务:
systemctl daemon-reload
开机启动nacos.service:
systemctl enable nacos.service
查看该service是否开机启用:
systemctl is-enabled nacos.service
启动该服务:
systemctl start nacos.service
查看该服务状态:
systemctl status nacos.service
完整的代码展示
[root@master bin]# vim startup.sh[root@master bin]# systemctl daemon-reload[root@master bin]# systemctl enable nacos.service[root@master bin]# systemctl is-enabled nacos.service
enabled
[root@master bin]# systemctl start nacos.service[root@master bin]# systemctl status nacos.service
● nacos.service - nacos
Loaded: loaded (/usr/lib/systemd/system/nacos.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2022-09-15 09:42:39 CST; 5s ago
Process: 1577ExecStart=/opt/nacos/nacos/bin/startup.sh -m standalone (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nacos.service
└─1601 /usr/local/jdk-11/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:gc*:file=/opt/nacos/nacos/...
9月 15 09:42:39 master systemd[1]: Starting nacos...
9月 15 09:42:39 master startup.sh[1577]: /usr/local/jdk-11/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xlog:g...
9月 15 09:42:39 master startup.sh[1577]: nacos is starting with standalone
9月 15 09:42:39 master startup.sh[1577]: nacos is starting,you can check the /opt/nacos/nacos/logs/start.out
9月 15 09:42:39 master systemd[1]: Started nacos.
Hint: Some lines were ellipsized, use -l to show in full.
下面这篇文章有问题,按照他的步骤会报错,我在他基础上改了代码
参考:linux 设置nacos开机启动
本文转载自: https://blog.csdn.net/qq_57581439/article/details/126857742
版权归原作者 我认不到你 所有, 如有侵权,请联系我们删除。
版权归原作者 我认不到你 所有, 如有侵权,请联系我们删除。