You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Debian 8服务器部署并启动Go语言二进制程序?

Hey there! Let's get your Go program up and running smoothly on your Debian 8 server. Here's a step-by-step breakdown tailored to your setup:

1. Fix the executable permission first

Right now, your hello binary has permissions set to 0644, which only allows reading/writing—it doesn't have execute permission, so the system can't run it. Let's fix that:

chmod +x /Go/hello

You can also set it to 755 (read/write/execute for owner, read/execute for group/others) with chmod 755 /Go/hello if you want a more standard permission set for executable files.

2. Test a manual start to confirm it works

First, run the binary directly to make sure it launches without errors:

/Go/hello

Now, test if it's accessible. If your program listens on a port (say, 8080 is common for dev setups), you can either:

  • Run curl http://localhost:[your-port] directly on the server to check for the "Hi there, I love hello!" output
  • Or from your local machine, open Safari and visit http://[your-server-ip]:[your-port]

Important: If you can't access it from your local browser, check if Debian's firewall (iptables) is blocking the port. To open it:

iptables -A INPUT -p tcp --dport [your-port] -j ACCEPT
# Save the rule so it persists after reboot
iptables-save > /etc/iptables/rules.v4
3. Keep the program running in the background (and on reboot)

If you just run the binary in your terminal, it'll stop as soon as you close the terminal. We have two solid options here:

Debian 8 uses systemd, so we can create a service file to manage your program—this will let it run in the background, restart automatically if it crashes, and start on server boot.

  1. Create a service file:
nano /etc/systemd/system/hello.service
  1. Paste this content (adjust paths or port-related configs if needed):
[Unit]
Description=Hello Go Web Service
After=network.target

[Service]
ExecStart=/Go/hello
Restart=always
User=root
WorkingDirectory=/Go

[Install]
WantedBy=multi-user.target
  1. Save and exit nano (press Ctrl+O, then Ctrl+X).
  2. Reload systemd to pick up the new service:
systemctl daemon-reload
  1. Start the service:
systemctl start hello.service
  1. Set it to start automatically on server boot:
systemctl enable hello.service

You can check the service status anytime with:

systemctl status hello.service

Option B: Use nohup (quick and simple)

If you don't need auto-restart or boot functionality right now, nohup will let you run the program in the background easily:

nohup /Go/hello > /Go/hello.log 2>&1 &

This redirects all program output to hello.log in the Go folder, and the program keeps running even after you close your terminal session.

4. Verify everything is working

After setting up either option, double-check:

  • The program process is running with ps aux | grep hello
  • You can access the "Hi there, I love hello!" message from your browser using the server's IP and port

内容的提问来源于stack exchange,提问作者sibert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:53:45