One-Click Deployment with nacos-setup
This Quick Start Guide helps you quickly deploy Nacos Server on your machine using nacos-setup.
0. Why Use nacos-setup
Compared to manually downloading, extracting, and configuring Nacos, nacos-setup provides a more convenient automated deployment experience:
- Automatically downloads and caches Nacos packages, avoiding repeated downloads.
- Automatically generates JWT Token, Identity Key, and other authentication configurations.
- Intelligently detects port conflicts and assigns available ports.
- Automatically detects Java environment and verifies version compatibility.
- Creates a Nacos cluster with a single command.
1. Prerequisites
Nacos relies on a Java environment to run. Please ensure you have the following environment set up:
- 64-bit OS, supporting Linux/Unix/Mac/Windows. Linux/Unix/Mac is recommended.
- Nacos 3.x requires 64-bit JDK 17+.
- Nacos 2.4.x - 2.5.x requires 64-bit JDK 8+.
Note: nacos-setup automatically detects the system Java version and verifies compatibility with the target Nacos version.
2. Install nacos-setup
2.1. One-Click Online Installation
- Linux/macOS
curl -fsSL https://nacos.io/nacos-installer.sh | sudo bash- Windows (PowerShell)
powershell -NoProfile -ExecutionPolicy Bypass -Command "iwr -UseBasicParsing https://nacos.io/nacos-installer.ps1 | iex"2.2. Verify Installation
nacos-setup --help3. Deploy Nacos
3.1. Standalone Mode
Start command:
nacos-setupNote: By default, Nacos 3.1.1 is installed using the built-in Derby database.
Specify version and port:
# Specify versionnacos-setup -v 2.5.2
# Specify portnacos-setup -p 18848
# Run in backgroundnacos-setup --detach
# Specify installation directorynacos-setup -d /opt/nacos3.2. Cluster Mode
Cluster mode ensures high availability and is recommended for production environments.
Create a cluster:
# Create a 3-node cluster (prod is the cluster ID)nacos-setup -c prod
# Create a 5-node clusternacos-setup -c prod -n 5
# Specify versionnacos-setup -c prod -v 3.2.0 -n 3Note: When using the built-in Derby database, nacos-setup automatically adopts an incremental startup strategy to ensure correct cluster initialization:
- Node 0 starts → cluster.conf = [Node0] → becomes leader, initializes data
- Node 1 starts → cluster.conf = [Node0, Node1] → joins as follower
- Node N starts → cluster.conf = [Node0…Node(N-1), NodeN] → joins as follower
- After all nodes start → automatically updates all nodes’ cluster.conf to include all members
This limitation does not apply when using an external database.
Cluster management:
# Join an existing cluster (add new node)nacos-setup -c prod --join
# Remove a nodenacos-setup -c prod --leave 2
# Clean and rebuild clusternacos-setup -c prod --cleanManual node management:
# View cluster statusls -la ~/ai-infra/nacos/cluster/CLUSTER_ID/
# Manually start a nodecd ~/ai-infra/nacos/cluster/CLUSTER_ID/0-v3.2.0bash bin/startup.sh
# Stop a nodebash bin/shutdown.sh3.3. Configure External Database
The built-in Derby database is used by default. For production environments, configure an external MySQL, PostgreSQL, or Oracle 12c or later database. For more database types and community plugins, see Datasource Plugin.
Run the configuration wizard:
nacos-setup --datasource-confEnter database information as prompted:
- Database type (MySQL/PostgreSQL/Oracle 12c+)
- Host address
- Port
- Database name
- Username and password
After configuration, subsequent deployments will automatically use the external database:
# Standalone modenacos-setup -v 3.2.0
# Cluster modenacos-setup -c prod -n 3Note: Configuration is saved in
~/ai-infra/nacos/default.properties.
3.4. Port Conflict Handling
The script automatically detects port conflicts:
-
Nacos process detected:
- With
--killparameter: stops the existing process - Without
--kill: automatically assigns a new port
- With
-
Non-Nacos process detected:
- Automatically assigns an available port
# Allow stopping Nacos processes occupying portsnacos-setup --kill
# Specify a new portnacos-setup -p 188484. Verify Nacos Service Started Successfully
4.1. Nacos Console Page
Open any browser and enter the address:
- Nacos 3.x: http://127.0.0.1:8080
- Nacos 2.x: http://127.0.0.1:8848/nacos/index.html
Note: The first time you open it, you will be asked to initialize the password for the admin user nacos. The password will be displayed during installation.
4.2. Service Registration
curl -X POST 'http://127.0.0.1:8848/nacos/v3/client/ns/instance?serviceName=quickstart.test.service&ip=127.0.0.1&port=8080'4.3. Service Discovery
curl -X GET 'http://127.0.0.1:8848/nacos/v3/client/ns/instance/list?serviceName=quickstart.test.service'4.4. Publish Configuration
# Login to obtain access tokencurl -X POST 'http://127.0.0.1:8848/nacos/v3/auth/user/login' -d 'username=nacos' -d 'password=${your_password}'
# Use access token to create configurationcurl -X POST 'http://127.0.0.1:8848/nacos/v3/admin/cs/config?dataId=quickstart.test.config&groupName=test&content=HelloWorld' -H "accessToken:${your_access_token}"4.5. Get Configuration
curl -X GET 'http://127.0.0.1:8848/nacos/v3/client/cs/config?dataId=quickstart.test.config&groupName=test'5. Command Options Reference
5.1. General Options
| Option | Description | Default |
|---|---|---|
-v, --version VERSION | Specify Nacos version | 3.2.0 |
-p, --port PORT | Service main port | 8848 |
--no-start | Do not start automatically after installation | - |
--adv | Advanced mode (interactive configuration) | - |
--detach | Run in background mode | - |
--datasource-conf | Configure global datasource | - |
-h, --help | Show help information | - |
5.2. Standalone Mode Options
| Option | Description | Default |
|---|---|---|
-d, --dir DIRECTORY | Installation directory | ~/ai-infra/nacos/standalone/nacos-VERSION |
--kill | Allow stopping Nacos processes occupying ports | - |
5.3. Cluster Mode Options
| Option | Description | Default |
|---|---|---|
-c, --cluster CLUSTER_ID | Cluster identifier (enables cluster mode) | - |
-n, --nodes COUNT | Number of cluster nodes | 3 |
--clean | Clean existing cluster | - |
--join | Join existing cluster | - |
--leave INDEX | Remove specified node from cluster | - |
6. Port Description
A Nacos instance uses multiple ports:
| Port | Offset | Description |
|---|---|---|
| 8848 | 0 | Nacos HTTP API port |
| 9848 | +1000 | Client gRPC port |
| 9849 | +1001 | Server gRPC port |
| 7848 | -1000 | Jraft port |
| 8080 | Independent | Nacos Console port (Nacos 3.x) |
Note: nacos-setup automatically handles port conflicts. If a port is occupied, it will intelligently assign a new port or prompt the user.
7. Directory Structure
7.1. System Installation Location
/usr/local/nacos-setup/├── bin/│ └── nacos-setup # Main command└── lib/ ├── cluster.sh # Cluster mode implementation ├── standalone.sh # Standalone mode implementation ├── common.sh # Common utilities ├── port_manager.sh # Port management ├── download.sh # Download management ├── config_manager.sh # Configuration management ├── java_manager.sh # Java environment management └── process_manager.sh # Process management7.2. User Data Directory
~/ai-infra/nacos/├── standalone/ # Standalone mode installation directory│ └── nacos-VERSION/├── cluster/ # Cluster mode installation directory│ └── CLUSTER_ID/│ ├── 0-vVERSION/ # Node 0│ ├── 1-vVERSION/ # Node 1│ └── cluster.conf # Cluster configuration└── default.properties # Global datasource configuration8. Uninstall nacos-setup
sudo bash nacos-installer.sh uninstall# orsudo bash nacos-installer.sh -uNote: User data at
~/ai-infra/nacos/will not be deleted after uninstallation and needs to be cleaned up manually.
FAQ
Q: Cannot find nacos-setup command after installation?
Ensure /usr/local/bin is in your PATH:
echo $PATH | grep /usr/local/bin
# If not, add to ~/.bashrc or ~/.zshrcexport PATH="/usr/local/bin:$PATH"Q: Java version incompatibility?
Install the corresponding Java version for the Nacos version you want to install:
export JAVA_HOME=/path/to/javaexport PATH=$JAVA_HOME/bin:$PATHQ: How to handle port conflicts?
# Method 1: Use --kill parameter to stop Nacos processes occupying portsnacos-setup --kill
# Method 2: Specify a new portnacos-setup -p 18848Q: How to view Nacos logs?
# Standalone modetail -f ~/ai-infra/nacos/standalone/nacos-*/logs/start.out
# Cluster modetail -f ~/ai-infra/nacos/cluster/CLUSTER_ID/*/logs/start.out