面向运维工程师,覆盖学习路线、部署命令、集群拓扑、Kubernetes 示例、巡检清单、故障排查 SOP、应用案例与常用值班命令。
这份文档的目标很直接:
适合人群:
建议环境:
8848建议目录规划:
/data/nacos
/data/logs/nacos
/data/backup/nacos创建目录:
mkdir -p /data/nacos
mkdir -p /data/logs/nacos
mkdirNacos 主要做两件事:
注册中心
配置中心
运维工程师学习它,不是只会打开控制台,而是要做到:
java -versionUbuntu:
apt update
apt install -y openjdk-11-jdkCentOS/Rocky:
yum install -y java-11-openjdk java-11-openjdk-develmysql -uroot -p不同版本 SQL 文件名可能不同,找不到就先
find。
vim /data/nacos/current/conf/application.propertiescd /data/nacos/current/bin
bash startup.sh -m standalone检查:
http://服务器IP:8848/nacos生产建议至少 3 节点,例如:
10.0.0.1110.0.0.1210.0.0.13vim /data/nacos/current/conf/cluster.conf10.0.0.11:8848
10.0.0.12:8848
10.0.0.13:8848cd /data/nacos/current/bin
bash startup.sh检查:
ss -lntp | grep 8848
tail -100 /data/nacos/current/logs/start.out安装:
Ubuntu:
apt install -y nginxCentOS/Rocky:
yum install -y nginx配置:
nginx -t
systemctl restart nginx
systemctl enable nginxfirewalld:
firewall-cmd --permanent --add-port=8848/tcp
firewall-cmd --reload
firewall-cmd --list-portsufw:
ufw allow 8848/tcp
ufw reload
ufw status备份:
恢复:
mysql -unacos -p'Nacos@123456' nacos < /data/backup/nacos/nacos_2026-04-29_21-00-00.sql备份启动脚本:
cp /data/nacos/current/bin/startup.sh /data/backup/nacos/startup.sh.bak_$(date +%F_%H-%M-%S)常见建议:
-Xms2g -Xmx2g -Xmn1g查看 GC:
docker pull nacos/nacos-server:v2.3.2查看日志:
docker logs -f nacos重点掌握:
场景:
实现:
运维收益:
场景:
实现:
运维收益:
排查命令:
常见原因:
排查方向:
排查方向:
排查命令:
常见原因:
自己搭一套单机:
搭 3 节点集群:
cluster.conf故意制造故障练排障:
整理自己的 SOP:
8848 端口是否监听常用命令:
重点检查:
重点检查:
重点检查:
如果你是运维,Nacos 学到位的标志不是“知道它是注册中心和配置中心”,而是:
这才是实战能力。
cd /data/nacos
wget https://github.com/alibaba/nacos/releases/download/2.3.2/nacos-server-2.3.2.tar.gz
tar -xzf nacos-server-2.3.2.tar.gz
mv nacos nacos-2.3.2
ln -sfn /data/nacos/nacos-2.3.2 /data/nacos/currentCREATE DATABASE nacos CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'nacos'@'%' IDENTIFIED BY 'Nacos@123456';
GRANT ALL PRIVILEGES ON nacos.* TO 'nacos'@'%';
FLUSH PRIVILEGES;cd /data/nacos/current
find . -name "*mysql*.sql"
mysql -unacos -p'Nacos@123456' nacos < /data/nacos/current/conf/mysql-schema.sqlserver.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
db.user.0=nacos
db.password.0=Nacos@123456ps -ef | grep nacos
ss -lntp | grep 8848
tail -f /data/nacos/current/logs/start.outcat >/etc/systemd/system/nacos.service <<'EOF'
[Unit]
Description=Nacos Server
After=network.target
[Service]
Type=forking
LimitNOFILE=65535
WorkingDirectory=/data/nacos/current
ExecStart=/data/nacos/current/bin/startup.sh -m standalone
ExecStop=/data/nacos/current/bin/shutdown.sh
Restart=on-failure
RestartSec=10
User=root
[Install]
WantedBy=multi-user.target
EOFsystemctl daemon-reload
systemctl enable nacos
systemctl start nacos
systemctl status nacos
journalctl -u nacos -fserver.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://10.0.0.20:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
db.user.0=nacos
db.password.0=Nacos@123456cat >/etc/nginx/conf.d/nacos.conf <<'EOF'
upstream nacos_cluster {
server 10.0.0.11:8848;
server 10.0.0.12:8848;
server 10.0.0.13:8848;
}
server {
listen 80;
server_name nacos.example.com;
location / {
proxy_pass http://nacos_cluster;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
EOFps -ef | grep nacos
ss -lntp | grep 8848
jcmd -l
tail -f /data/nacos/current/logs/start.out
top
free -h
df -h
iostat -xz 1 3
vmstat 1 5
ss -antp | grep 8848
mysql -h127.0.0.1 -unacos -p'Nacos@123456' -e 'show databases;'mysqldump -unacos -p'Nacos@123456' nacos > /data/backup/nacos/nacos_$(date +%F_%H-%M-%S).sql
cp -a /data/nacos/current/conf /data/backup/nacos/conf_$(date +%F_%H-%M-%S)docker run -d \
--name nacos \
-p 8848:8848 \
-e MODE=standalone \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=127.0.0.1 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e MYSQL_SERVICE_USER=nacos \
-e MYSQL_SERVICE_PASSWORD='Nacos@123456' \
-e JVM_XMS=1g \
-e JVM_XMX=1g \
-e JVM_XMN=512m \
nacos/nacos-server:v2.3.2systemctl status nacos
journalctl -u nacos -n 100 --no-pager
ss -lntp | grep 8848
tail -100 /data/nacos/current/logs/start.outping 10.0.0.12
ping 10.0.0.13
vmstat 1 5
iostat -xz 1 3
free -h +-----------------------+
| 用户/应用客户端 |
+-----------+-----------+
|
v
+-----------------------+
| Nginx / LB / SLB |
| 统一访问入口 |
+-----+-----------+-----+
| |
+------------+-----------+------------+
| | |
v v v
+----------------------+ +----------------------+ +----------------------+
| Nacos Node 1 | | Nacos Node 2 | | Nacos Node 3 |
| 10.0.0.11:8848 | | 10.0.0.12:8848 | | 10.0.0.13:8848 |
+----------+-----------+ +----------+-----------+ +----------+-----------+
\ | /
\ | /
\ | /
+---------------------------------------------+
|
v
+-----------------------+
| MySQL 主库 |
| 10.0.0.20 |
+-----------------------+apiVersion: v1
kind: Secret
metadata:
name: nacos-db-secret
namespace: middleware
type: Opaque
stringData:
MYSQL_SERVICE_PASSWORD: "Nacos@123456"apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-config
namespace: middleware
data:
application.properties: |
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://mysql.middleware.svc.cluster.local:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
db.user.0=nacos
db.password.0=${MYSQL_SERVICE_PASSWORD}apiVersion: v1
kind: Service
metadata:
name: nacos-headless
namespace: middleware
spec:
clusterIP: None
selector:
app: nacos
ports:
- name: server
port: 8848
targetPort: 8848apiVersion: v1
kind: Service
metadata:
name: nacos
namespace: middleware
spec:
selector:
app: nacos
ports:
- name: http
port: 8848
targetPort: 8848
type: ClusterIPapiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos
namespace: middleware
spec:
serviceName: nacos-headless
replicas: 3
selector:
matchLabels:
app: nacos
template:
metadata:
labels:
app: nacos
spec:
containers:
- name: nacos
image: nacos/nacos-server:v2.3.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8848
name: http
env:
- name: MODE
value: "cluster"
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: MYSQL_SERVICE_HOST
value: "mysql.middleware.svc.cluster.local"
- name: MYSQL_SERVICE_PORT
value: "3306"
- name: MYSQL_SERVICE_DB_NAME
value: "nacos"
- name: MYSQL_SERVICE_USER
value: "nacos"
- name: MYSQL_SERVICE_PASSWORD
valueFrom:
secretKeyRef:
name: nacos-db-secret
key: MYSQL_SERVICE_PASSWORD
- name: JVM_XMS
value: "1g"
- name: JVM_XMX
value: "1g"
- name: JVM_XMN
value: "512m"
volumeMounts:
- name: nacos-data
mountPath: /home/nacos/data
- name: nacos-logs
mountPath: /home/nacos/logs
readinessProbe:
tcpSocket:
port: 8848
initialDelaySeconds: 30
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 8848
initialDelaySeconds: 60
periodSeconds: 20
volumeClaimTemplates:
- metadata:
name: nacos-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
- metadata:
name: nacos-logs
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gikubectl create namespace middleware
kubectl apply -f nacos-db-secret.yaml
kubectl apply -f nacos-config.yaml
kubectl apply -f nacos-headless.yaml
kubectl apply -f nacos-service.yaml
kubectl apply -f nacos-statefulset.yamlps -ef | grep nacos
ss -lntp | grep 8848
curl -I http://127.0.0.1:8848/nacos/
free -h
df -h
iostat -xz 1 3
tail -100 /data/nacos/current/logs/start.out收到告警/用户反馈
|
v
先确认现象
|
v
确认影响范围
|
v
检查进程、端口、日志、机器资源、网络、数据库
|
v
按问题类型分流
(启动问题 / 注册发现问题 / 配置推送问题 / 集群抖动问题)
|
v
修复后验证
|
v
记录处理过程和预防措施systemctl status nacos
ss -lntp | grep 8848
tail -100 /data/nacos/current/logs/start.out
curl -I http://127.0.0.1:8848/nacos/
nginx -tping 10.0.0.12
ping 10.0.0.13
free -h
iostat -xz 1 3
vmstat 1 5
date
chronyc sources -vsystemctl status nacos
journalctl -u nacos -f
ps -ef | grep nacos
ss -lntp | grep 8848
tail -100 /data/nacos/current/logs/start.out
free -h
df -h
iostat -xz 1 3
vmstat 1 5
mysql -h127.0.0.1 -unacos -p'Nacos@123456' -e 'show databases;'
curl -I http://127.0.0.1:8848/nacos/