1 ubuntu服务器安装v2ray客户端
1.1 fhs-install-v2ray
fhs-install-v2ray是一个bash脚本,用于在支持 systemd 的 Debian / CentOS / Fedora / openSUSE 等作系统上安装 V2Ray。
github仓库地址:https://github.com/v2fly/fhs-install-v2ray
1.2 安装、更新、卸载v2ray
按照fhs-install-v2ray仓库的说明,我们可以使用以下命令安装和更新v2ray
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
可以使用以下命令卸载v2ray
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --remove
安装之后的路径如下
/usr/local/bin/v2ray # v2ray安装路径
/usr/local/etc/v2ray/config.json # config配置文件路径
/usr/local/share/v2ray/geoip.dat # geoip.dat路径
/usr/local/share/v2ray/geosite.dat # geosite.dat路径
/etc/systemd/system/v2ray.service
/etc/systemd/system/v2ray@.service
安装完成之后,我们可以使用以下命令操作v2ray
systemctl start v2ray # 启动v2ray
systemctl status v2ray # 查看服务状态
systemctl restart v2ray # 重启v2ray
systemctl stop v2ray # 停止v2ray
systemctl enable v2ray # v2ray开机自启
systemctl disable v2ray # v2ray取消开机自启
journalctl -u v2ray -f # 查看实时日志
另外我们可以使用以下命令更新geoip.dat和geosite.dat
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh)
1.3 配置config.json
config.json配置文件通常在/usr/local/etc/v2ray/config.json或者/etc/v2ray/config.json,一般需要配置以下信息
{
"inbounds": [
{
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true
}
}
],
"outbounds": [
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "your_server_address",
"port": your_server_port,
"users": [
{
"id": "your_user_id",
"alterId": your_alter_id
}
]
}
]
}
}
]
}
如果我们在Windows上有V2RayN客户端,我们可以将一个可用的服务器节点导出为config.json文件。
然后将这个导出的config.json文件上传到Ubuntu服务器的文件夹中,替换Ubuntu服务器的config.json文件。
我们可以使用以下命令测试配置文件是不是正确:
v2ray test -config /usr/local/etc/v2ray/config.json
如果配置文件正确,则会输出以下信息
V2Ray 5.28.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.23.6 linux/amd64)
A unified platform for anti-censorship.
Configuration OK.
1.4 配置客户端
在配置文件config.json修改完成之后,我们可以使用以下命令启动v2ray客户端
systemctl start v2ray
启动成功之后,我们可以使用以下命令测试是否成功
curl --socks5 127.0.0.1:10810 https://www.google.com
假设客户端的协议为socks,端口为10810。
1.5 配置代理
(1)设置当前终端代理
可以使用以下命令设置当前终端的代理
export http_proxy=socks5://127.0.0.1:10810
export https_proxy=socks5://127.0.0.1:10810
export ftp_proxy=socks5://127.0.0.1:10810
export no_proxy="172.16.x.x"
使代理失效
unset http_proxy
unset https_proxy
unset ftp_proxy
unset no_proxy
(2)单用户代理生效
使用以下命令打开~/.bashrc文件
nano ~/.bashrc
在该文件末尾增加以下内容
# 设置http代理
export http_proxy=socks5://127.0.0.1:10810
# 设置https代理
export https_proxy=socks5://127.0.0.1:10810
# 设置ftp代理
export ftp_proxy=socks5://127.0.0.1:10810
# 配置为no_proxy代表内网传输不走代理
export no_proxy="x.x.x.x"
保存之后,使用以下命令使配置生效
source ~/.bashrc
(3)系统级别生效
使用以下命令打开/etc/profile文件
nano /etc/profile
在该文件末尾增加以下内容
# 设置http代理
export http_proxy=socks5://127.0.0.1:10810
# 设置https代理
export https_proxy=socks5://127.0.0.1:10810
# 设置ftp代理
export ftp_proxy=socks5://127.0.0.1:10810
# 配置为no_proxy代表内网传输不走代理
export no_proxy="x.x.x.x"
保存之后,使用以下命令使配置生效
source /etc/profile
本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:ubuntu服务器配置v2ray客户端
原文链接:https://www.stubbornhuang.com/3148/
发布于:2025年03月27日 23:57:10
修改于:2025年03月27日 23:57:10
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论
56