Linux服务启动教程

1. 下载程序

# 下载到 /opt 目录
wget -O /opt/web-ssh-client https://vnc.hlwidc.com/web-ssh-client

# 设置执行权限
chmod +x /opt/web-ssh-client

# 验证文件
ls -lh /opt/web-ssh-client

2. 创建 systemd 服务文件

使用 SQLite 数据库(推荐新手):

# 创建服务文件
sudo nano /etc/systemd/system/web-ssh-client.service

将以下内容写入服务文件:

[Unit]
Description=Web SSH Client Service
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/opt
ExecStart=/opt/web-ssh-client -port 8080 -db-type sqlite
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

使用 MySQL 数据库(推荐生产环境):

[Unit]
Description=Web SSH Client Service
After=network.target mysql.service

[Service]
Type=simple
User=root
WorkingDirectory=/opt
ExecStart=/opt/web-ssh-client \
  -port 8080 \
  -db-type mysql \
  -db-host localhost \
  -db-port 3306 \
  -db-user root \
  -db-password your_password \
  -db-name machine_manage
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

⚠️ 注意:请将 your_password 替换为实际的数据库密码

启用 SSL/TLS(HTTPS):

[Unit]
Description=Web SSH Client Service
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/opt
ExecStart=/opt/web-ssh-client \
  --enable-ssl \
  --server-host example.com \
  --port 80 \
  -db-type sqlite
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

提示:启用 SSL 后,系统会自动生成自签名证书(有效期10年)。如果端口是80,会自动改为443。证书文件保存在 /opt/server.crt/opt/server.key。请将 example.com 替换为您的实际域名或IP地址。

3. 启动服务

# 重新加载 systemd 配置
sudo systemctl daemon-reload

# 启动服务
sudo systemctl start web-ssh-client

# 设置开机自启
sudo systemctl enable web-ssh-client

# 查看服务状态
sudo systemctl status web-ssh-client

4. 服务操作命令

启动服务

sudo systemctl start web-ssh-client

停止服务

sudo systemctl stop web-ssh-client

重启服务

sudo systemctl restart web-ssh-client

查看服务状态

sudo systemctl status web-ssh-client

查看服务日志

# 查看最新日志
sudo journalctl -u web-ssh-client -n 50

# 实时查看日志
sudo journalctl -u web-ssh-client -f

# 查看最近1小时的日志
sudo journalctl -u web-ssh-client --since "1 hour ago"

设置开机自启

sudo systemctl enable web-ssh-client

取消开机自启

sudo systemctl disable web-ssh-client

重新加载服务配置

# 修改服务文件后需要执行
sudo systemctl daemon-reload
sudo systemctl restart web-ssh-client

5. 常见问题

服务启动失败

检查步骤:

  • 查看服务日志:sudo journalctl -u web-ssh-client -n 100
  • 检查文件权限:ls -l /opt/web-ssh-client
  • 检查端口是否被占用:netstat -tlnp | grep 8080
  • 检查服务文件语法:sudo systemctl status web-ssh-client

修改服务配置

  1. 编辑服务文件:sudo nano /etc/systemd/system/web-ssh-client.service
  2. 重新加载配置:sudo systemctl daemon-reload
  3. 重启服务:sudo systemctl restart web-ssh-client

查看服务运行信息

# 查看服务进程
ps aux | grep web-ssh-client

# 查看端口监听
netstat -tlnp | grep 8080
# 或使用 ss 命令
ss -tlnp | grep 8080
需要更多帮助
加微信:88172719
复制成功