internal/website/docs/deployment.md
This guide covers deploying go-micro services to a Linux server using systemd.
go-micro provides a clear workflow from development to production:
| Stage | Command | Purpose |
|---|---|---|
| Develop | micro run | Local dev with hot reload and API gateway |
| Build | micro build | Compile production binaries for any target OS |
| Deploy | micro deploy | Push binaries to a remote Linux server via SSH + systemd |
| Dashboard | micro server | Optional production web UI with JWT auth and user management |
Each command has a distinct role — they don't overlap:
micro run builds, runs, and watches services locally. It includes a lightweight gateway. Use it for development.micro build compiles binaries without running them. Use it to prepare release artifacts.micro deploy sends binaries to a remote server and manages them with systemd. It builds automatically if needed.micro server provides an authenticated web dashboard for services that are already running. It does NOT build or run services.On your server (Ubuntu, Debian, or any systemd-based Linux):
# Install micro
curl -fsSL https://go-micro.dev/install.sh | sh
# Initialize for deployment
sudo micro init --server
This creates:
/opt/micro/bin/ - where service binaries live/opt/micro/data/ - persistent data directory/opt/micro/config/ - environment files# From your project directory
micro deploy user@your-server
That's it! The deploy command:
# Basic setup (creates 'micro' user)
sudo micro init --server
# Custom installation path
sudo micro init --server --path /home/deploy/micro
# Run services as existing user
sudo micro init --server --user deploy
# Initialize remotely (from your laptop)
micro init --server --remote user@your-server
Directories:
/opt/micro/
├── bin/ # Service binaries
├── data/ # Persistent data (databases, files)
└── config/ # Environment files (*.env)
Systemd Template (/etc/systemd/system/[email protected]):
[Unit]
Description=Micro service: %i
After=network.target
[Service]
Type=simple
User=micro
WorkingDirectory=/opt/micro
ExecStart=/opt/micro/bin/%i
Restart=on-failure
RestartSec=5
EnvironmentFile=-/opt/micro/config/%i.env
[Install]
WantedBy=multi-user.target
The %i is replaced with the service name. So [email protected] runs /opt/micro/bin/users.
micro deploy user@server
micro deploy user@server --service users
micro deploy user@server --build
Add to your micro.mu:
service users
path ./users
port 8081
service web
path ./web
port 8080
deploy prod
ssh [email protected]
deploy staging
ssh [email protected]
Then:
micro deploy prod # deploys to prod.example.com
micro deploy staging # deploys to staging.example.com
# Local services
micro status
# Remote services
micro status --remote user@server
Output:
server.example.com
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
users ● running pid 1234
posts ● running pid 1235
web ● running pid 1236
# All services
micro logs --remote user@server
# Specific service
micro logs users --remote user@server
# Follow logs
micro logs users --remote user@server -f
micro stop users --remote user@server
You can also manage services directly on the server:
# Status
sudo systemctl status micro@users
# Restart
sudo systemctl restart micro@users
# Stop
sudo systemctl stop micro@users
# Logs
journalctl -u micro@users -f
Create environment files at /opt/micro/config/<service>.env:
# /opt/micro/config/users.env
DATABASE_URL=postgres://localhost/users
REDIS_URL=redis://localhost:6379
LOG_LEVEL=info
These are automatically loaded by systemd when the service starts.
# Generate key (if you don't have one)
ssh-keygen -t ed25519
# Copy to server
ssh-copy-id user@server
Add to ~/.ssh/config:
Host prod
HostName prod.example.com
User deploy
IdentityFile ~/.ssh/deploy_key
Host staging
HostName staging.example.com
User deploy
IdentityFile ~/.ssh/deploy_key
Then deploy with:
micro deploy prod
✗ Cannot connect to myserver
SSH connection failed. Check that:
• The server is reachable: ping myserver
• SSH is configured: ssh user@myserver
• Your key is added: ssh-add -l
Fix:
# Test SSH connection
ssh user@server
# Add SSH key
ssh-copy-id user@server
# Check SSH agent
eval $(ssh-agent)
ssh-add
✗ Server not initialized
micro is not set up on myserver.
Fix:
ssh user@server 'sudo micro init --server'
Check the logs:
micro logs myservice --remote user@server
# Or on the server:
journalctl -u micro@myservice -n 50
Common causes:
Ensure your user can write to /opt/micro/bin/:
# On server
sudo chown -R deploy:deploy /opt/micro
# Or add user to micro group
sudo usermod -aG micro deploy
Add to /etc/sudoers.d/micro:
deploy ALL=(ALL) NOPASSWD: /bin/systemctl daemon-reload
deploy ALL=(ALL) NOPASSWD: /bin/systemctl enable micro@*
deploy ALL=(ALL) NOPASSWD: /bin/systemctl restart micro@*
deploy ALL=(ALL) NOPASSWD: /bin/systemctl stop micro@*
deploy ALL=(ALL) NOPASSWD: /bin/systemctl status micro@*
Once services are deployed and managed by systemd, you can optionally run micro server on the same machine to get a full web dashboard with authentication:
# On your server
micro server
This gives you:
The server discovers services via the registry automatically. Default login: admin / micro.
See the micro server documentation for details.