Ubuntu 22.04 安装 Nacos 记录
Ubuntu 22.04 安装 Nacos 记录
本文记录了在 Ubuntu 22.04 系统上安装 Nacos 的完整过程,适用于本地测试或生产部署的基础搭建。
一、官方资源
- 官网下载地址:https://nacos.io/download/nacos-server/
- 官网文档:https://nacos.io/docs/latest/overview/
二、下载和解压
wget https://github.com/alibaba/nacos/releases/download/2.3.2/nacos-server-2.3.2.zip -O nacos-server.zipmkdir -p /opt/nacos# 解压 zip 文件(需要 unzip 工具)
sudo apt update && sudo apt install unzip -y
unzip nacos-server.zip -d /opt/nacos
如果下载的是 .tar.gz 格式,可使用 tar 命令解压:
tar -zxvf nacos-server-2.3.2.tar.gz -C /opt/nacos --strip-components=1
wget https://github.com/alibaba/nacos/releases/download/2.3.2/nacos-server-2.3.2.tar.gzmkdir -p /opt/nacostar -zxvf nacos-server-2.3.2.tar.gz -C /opt/nacos --strip-components=1
三、配置 Nacos 核心配置
编辑 /opt/nacos/conf/application.properties
,添加下列参数:
# 身份证书
nacos.core.auth.server.identity.key=username
nacos.core.auth.server.identity.value=password# 秘钥:使用 base64 编码,且解码后长度不小于 32 个 byte
nacos.core.auth.plugin.nacos.token.secret.key=qPZgGVv/Nn/7KMw61GV45GHv3PIY2qKzCu0FjG1z9x8=
如果未指定外部数据库,初始化时会使用内置 Derby 数据库
四、启动 Nacos
cd /opt/nacos/binbash startup.sh -m standalone
进入 Web 界面: http://<server_ip>:8848
默认账号:
nacos
默认密码:
nacos
五、配置systemd,支持开机启动
创建服务文件:
sudo nano /etc/systemd/system/nacos.service
内容:
[Unit]
Description=Nacos Server (Standalone)
After=network.target[Service]
Type=forking
User=root
ExecStart=/opt/nacos/bin/startup.sh -m standalone
ExecStop=/opt/nacos/bin/shutdown.sh
Restart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target
生效并启动服务:
sudo systemctl daemon-reload
sudo systemctl enable nacos
sudo systemctl start nacos
查看状态:
systemctl status nacos
附录:常用 systemctl 操作
# 启动
sudo systemctl start nacos# 停止
sudo systemctl stop nacos# 重启
sudo systemctl restart nacos# 查看状态
sudo systemctl status nacos
至此,你已在 Ubuntu 22.04 环境上成功安装并启动了 Nacos,并通过 systemd 实现了服务化管理。