Ubuntu虚拟机部署Corda 3+1节点及配套Spring Boot API技术咨询
Hey there! Let's walk through exactly how to deploy your 3 regular Corda nodes + 1 notary node to Ubuntu VMs, along with your Spring Boot RPC REST server. I'll break this down into actionable, step-by-step sections so you can follow along easily.
First, make sure your Ubuntu VMs are ready:
- Java Version: Install the correct Java version matching your Corda release (most Corda versions use Java 8 or 11). Run
sudo apt install openjdk-11-jdk(adjust version as needed) and verify withjava -version. - Network Connectivity: Ensure all VMs can communicate with each other. Open these ports in Ubuntu's firewall (
sudo ufw allow <port>/tcp):- Corda P2P port (default: 10002)
- Corda RPC port (default: 10003)
- Spring Boot port (default: 8080)
- User Permissions: Create dedicated users for Corda and Spring Boot (e.g.,
cordaandspring) to run services securely, instead of using root.
You're already using the deployNodes Gradle task locally—here's how to take those generated nodes to your Ubuntu VMs:
Step 2.1: Generate Nodes Locally
Run the Gradle task as usual to generate all node folders:
./gradlew deployNodes
This creates a build/nodes directory containing subfolders for each node (e.g., PartyA, PartyB, PartyC, Notary).
Step 2.2: Package & Transfer Nodes to VMs
For each node:
- Package the node folder into a compressed archive (tar.gz works well for Linux):
cd build/nodes tar -czf partya-node.tar.gz PartyA/ - Transfer the archive to your target Ubuntu VM using
scp:scp partya-node.tar.gz corda@<vm-ip-address>:/opt/corda/nodes/
Repeat this for all 4 nodes, sending each to its respective VM (or same VM if you're colocating nodes—just use separate directories).
Step 2.3: Configure Nodes on Ubuntu
On each VM:
- Unpack the node archive:
cd /opt/corda/nodes tar -xzf partya-node.tar.gz - Edit the
node.conffile (in the node's root directory) to update network settings:- Set the
p2pAddressto the VM's public/private IP and P2P port:p2pAddress="192.168.1.101:10002" - Update the
rpcSettings.addressto the VM's IP and RPC port:rpcSettings { address="192.168.1.101:10003" adminAddress="192.168.1.101:10043" } - Set
networkMapAddressto the IP/P2P port of one of your nodes (usually the node you want acting as the network map—e.g., PartyA):networkMapAddress="192.168.1.101:10002" - Verify the
rpcUserssection matches the credentials you'll use in your Spring Boot app.
- Set the
Step 2.4: Start Corda Nodes
You can start nodes directly or set them up as system services for reliability:
Option A: Manual Start (for testing)
cd /opt/corda/nodes/PartyA nohup ./runnode &
Check logs to confirm the node started successfully:
tail -f logs/node-PartyA.log
Look for messages indicating the node connected to the network map and other peers.
Option B: Systemd Service (for production)
Create a systemd service file (e.g., /etc/systemd/system/corda-partya.service):
[Unit] Description=Corda PartyA Node After=network.target [Service] User=corda WorkingDirectory=/opt/corda/nodes/PartyA ExecStart=/opt/corda/nodes/PartyA/runnode Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable corda-partya sudo systemctl start corda-partya
Repeat this for all nodes.
Now let's get your Spring Boot app up and running on Ubuntu:
Step 3.1: Prepare the Spring Boot JAR
Locally, build your Spring Boot project to generate an executable JAR:
./gradlew bootJar
The JAR will be in build/libs/ (e.g., corda-rpc-server-0.0.1-SNAPSHOT.jar).
Step 3.2: Transfer & Run the JAR
- Copy the JAR to your Ubuntu VM (can be the same VM as one of the Corda nodes or a separate VM):
scp build/libs/corda-rpc-server-0.0.1-SNAPSHOT.jar spring@<vm-ip-address>:/opt/spring-boot/ - Run the JAR (manual test first):
cd /opt/spring-boot nohup java -jar corda-rpc-server-0.0.1-SNAPSHOT.jar &
Check logs with tail -f nohup.out to confirm the server started and connected to the Corda node's RPC endpoint.
Step 3.3: Systemd Service for Spring Boot (production)
Create a service file (e.g., /etc/systemd/system/spring-corda-rpc.service):
[Unit] Description=Corda Spring Boot RPC Server After=network.target corda-partya.service [Service] User=spring WorkingDirectory=/opt/spring-boot ExecStart=/usr/bin/java -jar corda-rpc-server-0.0.1-SNAPSHOT.jar Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable spring-corda-rpc sudo systemctl start spring-corda-rpc
Step 3.4: Optional: Reverse Proxy with Nginx
To make your Spring Boot API accessible on standard ports (e.g., 80/443), set up Nginx:
- Install Nginx:
sudo apt install nginx - Create a config file (e.g.,
/etc/nginx/sites-available/corda-rpc):server { listen 80; server_name your-domain-or-ip; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } - Enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/corda-rpc /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
- Check Corda Node Health: Use the Corda shell to connect to a node and verify peer connectivity:
You should see all 4 nodes listed.cd /opt/corda/nodes/PartyA ./cordash # Run command: run networkMapSnapshot - Test Spring Boot API: Use
curlor Postman to hit your API endpoints:
Confirm you get valid responses from the Corda ledger.curl http://<spring-boot-vm-ip>:8080/api/your-endpoint
- Version Consistency: Ensure your Spring Boot app's Corda RPC client version matches the Corda node version—mismatches cause compatibility issues.
- Security: In production, enable SSL for Corda RPC and Spring Boot, use strong credentials for RPC users, and restrict firewall access to trusted IPs only.
- Logging: For easier monitoring, configure both Corda nodes and Spring Boot to write logs to dedicated files (instead of nohup.out) and set up log rotation.
内容的提问来源于stack exchange,提问作者SrikanthVarma A

