惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
量子位
宝玉的分享
宝玉的分享
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
Apple Machine Learning Research
Apple Machine Learning Research
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
aimingoo的专栏
aimingoo的专栏
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
Latest news
Latest news
S
Security @ Cisco Blogs
Last Week in AI
Last Week in AI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
W
WeLiveSecurity
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
P
Proofpoint News Feed
P
Palo Alto Networks Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
The Blog of Author Tim Ferriss
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
美团技术团队
博客园 - 【当耐特】
D
DataBreaches.Net
I
InfoQ
G
GRAHAM CLULEY
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2023-03-13 · via 轶哥博客

以下是实现自动安装frpc的Shell脚本,实现ssh的22端口内网穿透,注册systemd服务开机自动启动。

直接使用线上地址快速下载并执行Shell脚本一件部署可以使用以下命令:

使用curl:

curl -sSL https://openapi.site/install_frpc.sh | bash -s 端口号 token server_addr [server_port=7000]

使用wget:

wget -qO- https://openapi.site/install_frpc.sh | bash -s 端口号 token server_addr [server_port=7000]

其中端口号、token、server_addr为必须传入的参数,server_port为可选参数,如果没有传入则默认为7000。请根据自己的需要替换相应的参数值。

如果执行成功,将会输出“Successfully started frpc”,否则会输出失败信息。

附:

install_frpc.sh文件内容:

#!/bin/bash

# 获取参数
if [ $# -lt 3 ]; then
    echo "Usage: $0 port token server_addr [server_port=7000]"
    exit 1
fi
port=$1
token=$2
server_addr=$3
server_port=${4:-7000}

# 获取操作系统类型和架构
case $(uname -m) in
    x86_64)
        arch="amd64"
        ;;
    i386 | i686)
        arch="386"
        ;;
    armv6l | armv7l | armv7hl)
        arch="arm"
        ;;
    aarch64 | arm64)
        arch="arm64"
        ;;
    mips*)
        if [ "$(uname -m)" = "mips64" ]; then
            arch="mips64"
        elif [ "$(uname -m)" = "mips64el" ]; then
            arch="mips64le"
        elif [ "$(uname -m)" = "mips" ]; then
            arch="mips"
        else
            arch="mipsle"
        fi
        ;;
    riscv64)
        arch="riscv64"
        ;;
    *)
        echo "Unsupported architecture $(uname -m)"
        exit 1
esac

case $(uname -s) in
    Linux)
        os_type="linux"
        ;;
    Darwin)
        os_type="darwin"
        ;;
    *)
        echo "Unsupported operating system $(uname -s)"
        exit 1
esac

# 下载最新版frp压缩文件
wget -O frp.tar.gz "https://nat.openapi.site/frp/download?os_type=${os_type}&arch=${arch}"
if [ $? -ne 0 ]; then
    echo "Failed to download frp"
    exit 1
fi

# 解压文件并拷贝可执行文件到/usr/bin/frpc目录下
tar -zxvf frp.tar.gz
if [ $? -ne 0 ]; then
    echo "Failed to extract frp"
    exit 1
fi
sudo mv frp*/frpc /usr/bin/frpc

# 创建/etc/frp/目录和配置文件
sudo mkdir -p /etc/frp/
if [ ! -f /etc/frp/frpc.ini ]; then
cat > frpc.ini << EOF
[common]
token = ${token}
server_addr = ${server_addr}
server_port = ${server_port}

[ssh-${os_type}-${arch}-${port}]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = ${port}
EOF
fi
sudo mv frpc.ini /etc/frp/frpc.ini

# 创建service配置文件
cat > 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
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
EOF

# 根据操作系统类型放置service配置文件到对应的systemd目录下
if [[ "$(uname -s)" == "Linux" ]]; then
    if [[ -d "/lib/systemd/system" ]]; then
        sudo mv frpc.service /lib/systemd/system/frpc.service
    elif [[ -d "/usr/lib/systemd/system" ]]; then
        sudo mv frpc.service /usr/lib/systemd/system/frpc.service
    else
        echo "Failed to find systemd directory"
        exit 1
    fi
else
    echo "Unsupported operating system"
    exit 1
fi

rm -rf frp*

# 启动frpc
sudo systemctl enable frpc --now
if [ $? -eq 0 ]; then
    echo "Successfully started frpc"
else
    echo "Failed to start frpc"
    exit 1
fi

echo -e "\n"
systemctl status frpc

使用方式:

bash install_frpc.sh 端口号 token server_addr [server_port=7000]

其中端口号、token、server_addr为必须传入的参数,server_port为可选参数,如果没有传入则默认为7000。

shell中下载最新版frp压缩文件的中转站请参考《frp更新中心API》