frp内网穿透
最近在弄远程访问串口以及一些项目, 很早前就知道有frp这个东西, 但是一直没用过.
主要是centos7安装部署, debian安装过程差不多,稍微变通一下.
frp分为公网端(frps)和内网端(frpc), 桌面端通过公网端的IP进入内网.
由于一般只运行一个端, 所以下面的配置全表以frp进行命名.
centos安装
yum install epel-release -y -q yum install golang git wget -y -q git clone https://github.com/fatedier/frp cd frp export GO111MODULE=on export GOPROXY=https://goproxy.io make #由于一般只运行一个端, 下面的配置全表以frp进行命名, 所以此处的install根据情况选择一个进行使用. #install bin/frps /usr/bin/frp #install bin/frpc /usr/bin/frp
公网服务端配置
cat >/etc/frp.conf<<EOF [common] bind_addr = 0.0.0.0 bind_port = 7000 vhost_http_port = 8000 vhost_https_port = 8001 dashboard_port = 7500 privilege_token = 123456 dashboard_user = ubuntu dashboard_pwd = 123 log_file = /var/log/frps.log log_level = info log_max_days = 3 max_pool_count = 5 authentication_timeout = 900 tcp_mux = true EOF
内网端配置内容
cat >/etc/frp.conf<<EOF [common] server_addr = 服务器域名 server_port = 7000 # for authentication privilege_token = 12345678 #if you want to connect frps by http proxy or socks5 proxy, you can set http_proxy here or in global environment variables # it only works when protocol is tcp # http_proxy = http://user:[email protected]:8080 # http_proxy = socks5://user:[email protected]:1080 # console or real logFile path like ./frpc.log #log_file = /var/log/frpc.log # trace, debug, info, warn, error log_level = debug log_max_days = 3 #启用压缩 use_compression = true login_fail_exit = false [ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 2200 #http代理 [HTTP] type = http local_ip = 127.0.0.1 local_port = 8080 #自己的域名 custom_domains = xxxx remote_port = 800 EOF
手动启动命令
frps -c /etc/frp.conf #启动公网服务端 frpc -c /etc/frc.conf #启动内网端
配置系统服务管理
cat>/lib/systemd/system/frp.service<<EOF [Unit] Description=fraps service After=network.target syslog.target Wants=network.target [Service] Type=simple ExecStart=/usr/bin/frp -c /etc/frp.conf [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable frps systemctl start frps
=============================
debian配置守护进程启动
apt install supervisor -y cat>/etc/supervisor/conf.d/frp.conf<<EOF [program:frp] command = /usr/bin/frp -c /etc/frp.conf autostart = true EOF systemctl restart supervisor
systemctl services 配置文件
cat>/usr/lib/systemd/system/frpc.service<<EOF
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frpc -c /etc/frp/frpc.ini
ExecReload=/usr/bin/frpc reload -c /etc/frp/frpc.ini
[Install]
WantedBy=multi-user.target
EOF
cat>/usr/lib/systemd/system/[email protected]<<EOF
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=idle
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frpc -c /etc/frp/%i.ini
ExecReload=/usr/bin/frpc reload -c /etc/frp/%i.ini
[Install]
WantedBy=multi-user.target
cat> /usr/lib/systemd/system/[email protected]
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/%i.ini
[Install]
WantedBy=multi-user.target
EOF
cat>/usr/lib/systemd/system/frps.service<<EOF
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini
[Install]
WantedBy=multi-user.target
EOF
none