Use systemd to run frp in the background

To manage FRP services using systemd, you need to create systemd service files. This is a more robust way of managing your services and comes with benefits like auto-restarting on crash and easy log management.

  1. Create a systemd service file for frps (FRP server)

    sudo nano /etc/systemd/system/frps.service
    

    Then paste the following into the file:

    [Unit]
    Description=FRP Server Service
    After=network.target
    
    [Service]
    ExecStart=/path/to/your/frp/frps -c /path/to/your/frp/frps.ini
    Restart=on-failure
    User=nobody
    Group=nobody
    
    [Install]
    WantedBy=multi-user.target
    

    Replace /path/to/your/frp/ with the actual path to your FRP binaries. Save and close the file when you’re done.

  2. Create a systemd service file for frpc (FRP client)

    sudo nano /etc/systemd/system/frpc.service
    

    Then paste the following into the file:

    [Unit]
    Description=FRP Client Service
    After=network.target
    
    [Service]
    ExecStart=/path/to/your/frp/frpc -c /path/to/your/frp/frpc.ini
    Restart=on-failure
    User=nobody
    Group=nobody
    
    [Install]
    WantedBy=multi-user.target
    

    Replace /path/to/your/frp/ with the actual path to your FRP binaries. Save and close the file when you’re done.

  3. Reload the systemd manager configuration

    This will make systemd recognize your new services:

    sudo systemctl daemon-reload
    
  4. Start the services

    sudo systemctl start frps
    sudo systemctl start frpc
    
  5. Enable the services to start at boot

    sudo systemctl enable frps
    sudo systemctl enable frpc
    

    This will make sure the FRP client and server start up automatically when the system boots up.

You can use systemctl status frps and systemctl status frpc to check the status of your services. If you want to see logs, you can use journalctl -u frps and journalctl -u frpc.

Remember to replace the placeholders with actual paths to your FRP binaries and config files. The user and group specified here is nobody, but you might want to change it to a user that suits your security policies better.

猜你喜欢

转载自blog.csdn.net/m0_57236802/article/details/132036661
frp
今日推荐