这类教程网上很多,写此教程是作为自己的笔记,方便查看
服务端
安装frps文件
进入安装目录,这里以
/mnt
为例
cd /mnt
下载
frp
wget https://github.com/fatedier/frp/releases/download/v0.44.0/frp_0.44.0_linux_amd64.tar.gz
软件是会更新的,这里获取最新下载链接,选择
linux_amd64.tar.gz
结尾的
解压文件夹
tar -xzvf frp_0.44.0_linux_amd64.tar.gz
创建
frps
文件夹
mkdir frps
拷贝下载的服务器端文件到
frps
文件夹
cd frp_0.44.0_linux_amd64
cp frps frps_full.ini frps.ini ../frps
删除压缩包和无用文件
cd /mnt
rm -rf frp_0.44.0_linux_amd64 frp_0.44.0_linux_amd64.tar.gz
然后试着运行一下
frps
,看看是否能正常运行
cd /mnt/frps
./frps --help
正常显示如下:
root@aliyun:/mnt/frps# ./frps --help
frps is the server of frp (https://github.com/fatedier/frp)
Usage:
frps [flags]
frps [command]
Available Commands:
help Help about any command
verify Verify that the configures is valid
Flags:
--allow_ports string allow ports
--bind_addr string bind address (default "0.0.0.0")
-p, --bind_port int bind port (default 7000)
--bind_udp_port int bind udp port
-c, --config string config file of frps
--dashboard_addr string dasboard address (default "0.0.0.0")
--dashboard_port int dashboard port
--dashboard_pwd string dashboard password (default "admin")
--dashboard_tls_cert_file string dashboard tls cert file
--dashboard_tls_key_file string dashboard tls key file
--dashboard_tls_mode dashboard tls mode
--dashboard_user string dashboard user (default "admin")
--disable_log_color disable log color in console
--enable_prometheus enable prometheus dashboard
-h, --help help for frps
--kcp_bind_port int kcp bind udp port
--log_file string log file (default "console")
--log_level string log level (default "info")
--log_max_days int log max days (default 3)
--max_ports_per_client int max ports per client
--proxy_bind_addr string proxy bind address (default "0.0.0.0")
--subdomain_host string subdomain host
--tls_only frps tls only
-t, --token string auth token
-v, --version version of frps
--vhost_http_port int vhost http port
--vhost_http_timeout int vhost http response header timeout (default 60)
--vhost_https_port int vhost https port
Use "frps [command] --help" for more information about a command.
如果提示 -bash: ./frps: cannot execute binary file: Exec format error
就说明你下错版本了
配置frps
编辑
frps.ini
文件
vi frps.ini
修改参照
参考以下配置说明来书写配置文件frps.ini
,你可以先在电脑上打一份草稿
//下面这句开头必须要有,表示配置的开始
[common]
//frp 服务端端口(必须)
bind_port = 7000
//frp 服务端密码(必须)
token = 12345678
//认证超时时间,由于时间戳会被用于加密认证,防止报文劫持后被他人利用
//因此服务端与客户端所在机器的时间差不能超过这个时间(秒)
//默认为900秒,即15分钟,如果设置成0就不会对报文时间戳进行超时验证
authentication_timeout = 900
//仪表盘端口,只有设置了才能使用仪表盘(即后台)
dashboard_port = 7500
//仪表盘访问的用户名密码,如果不设置,则默认都是 admin
dashboard_user = admin
dashboard_pwd = admin
//如果你想要用 frp 穿透访问内网中的网站(例如路由器设置页面)
//则必须要设置以下两个监听端口,不设置则不会开启这项功能
vhost_http_port = 10080
vhost_https_port = 10443
#日志路径
#日志记录级别
#日志保留天数
log_file = /mnt/frps/frps.log
log_level = debug
log_max_days = 7
//此设置需要配合客户端设置,仅在穿透到内网中的 http 或 https 时有用(可选)
//假设此项设置为 example.com,客户端配置 http 时将 subdomain 设置为 test,
//则你将 test.example.com 解析到服务端后,可以使用此域名来访问客户端对应的 http
subdomain_host = example.com
也不是全部参数都需要,根据自身需求,修改好后
Esc
退出,:wq
保存
启动frps
首先要确保你在
/mnt/frps
目录里,按照我的流程是在的
启动frps
命令
./frps -c ./frps.ini
保持后台运行
frps
命令
nohup ./frps -c ./frps.ini &
配置systemctl来控制frps,让服务器开机自动运行frps
创建
frps.service
sudo vim /lib/systemd/system/frps.service
在
frps.service
里添加以下内容
[Unit]
Description=frps service
After=network.target syslog.target
Wants=network.target
[Service]
Type=simple
ExecStart=/mnt/frps/frps -c /mnt/frps/frps.ini //启动服务的命令(此处写你的frps的实际安装目录)
[Install]
WantedBy=multi-user.target
修改好后
Esc
退出,:wq
保存
使用systemctl命令来控制frps
启动
frps
sudo systemctl start frps
服务器开机自动启动
frps
sudo systemctl enable frps
重启
frps
sudo systemctl restart frps
停止
frps
sudo systemctl stop frps
查看日志
sudo systemctl status frps
检查服务器端安装情况
浏览器输入服务器IP访问
http://xxx.xxx.xxx.xxx:7500
来查看frps
服务状态
客户端
安装方式一样,删除的是
frps
文件,保留frpc
文件
编辑frpc.ini
[common] //基础设置
server_addr = x.x.x.x //此处填写你服务器的公网IP
server_port = 7000 //此处填写你服务器上frp服务端设定的端口,默认7000
token = 12345678 //此处填写和你服务器上token一样,验证用
[ssh] //此处填写你需要添加的映射的名称(自定义,123、qwe之类的都可以)
type = tcp //此处填写该映射的协议类型
local_ip = 127.0.0.1 //本地IP,不做任何更改
local_port = 22 //需要映射的本地端口
remote_port = 6000 //需要映射到服务器的端口,注意不得与服务器上的端口重复
//映射web网页时,这样填,https根据个人需求
[halo_https]
type = https
local_port = 443
custom_domains = www.3qd.net //填写你的网址
use_encryption = false
use_compression = true
[halo_http]
type = http
local_port = 80
custom_domains = www.3qd.net
use_encryption = false
use_compression = true
启动
fpsc
./frpc -c ./frpc.ini
运行命令与服务端一样,注意把
frps
改成frpc
就行
评论区