Skip to content

Instantly share code, notes, and snippets.

@mahmoud-eskandari
Last active August 8, 2024 13:26
Show Gist options
  • Save mahmoud-eskandari/960899f3494a1bffa1a29631dbaf0aee to your computer and use it in GitHub Desktop.
Save mahmoud-eskandari/960899f3494a1bffa1a29631dbaf0aee to your computer and use it in GitHub Desktop.
Install v2ray on Bridge:(Ubuntu +18 via systemd) - Upstream (Ubuntu +18/CentOS +7 via docker)

پنل x-ui

پنل تحت وب مدیریت V2ray و ساخت کاربر و مدیریت سرور

mkdir x-ui && cd x-ui
docker run -itd --network=host \
    -v $PWD/db/:/etc/x-ui/ \
    -v $PWD/cert/:/root/cert/ \
    --name x-ui --restart=unless-stopped \
    enwaiax/x-ui:latest

بعدش بزنید docker logs x-ui

یه پورت نشون میده مثلا: 54321

توی مرورگر بزنید

FOREIGN_IP:PORT

یه پنل وب میده که چینیه میتونید با گوگل ترنزلیت هم ترجمش کنید پسورد پیشفرض admin:admin بعدش حتما عوضش کنید.

میتونید یوزر تعریف کنید دسترسی های جدید و کانکشن جدید بسازید برای کاربرانتون

#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root user or run with sudo"
exit
fi
cd /tmp/
rm -rf ./v2ray && mkdir ./v2ray
cd ./v2ray
## x86_64
## Source: https://github.com/v2fly/v2ray-core/releases/tag/v4.31.0
curl -L https://v2rayv2ray.s3.ir-thr-at1.arvanstorage.ir/v2ray-$(uname -m).tar.gz -o v2ray.tar.gz
tar -xvf v2ray.tar.gz
## make directories
rm -rf /var/log/v2ray/ && mkdir -p /var/log/v2ray/
rm -rf /usr/local/share/v2ray/ && mkdir -p /usr/local/share/v2ray/
rm -rf /usr/local/etc/v2ray/ && mkdir -p /usr/local/etc/v2ray/
## Get an UUID
UUID=$(cat /proc/sys/kernel/random/uuid)
if [ $? -ne 0 ]
then
UUID= $(curl -s "https://www.uuidgenerator.net/api/version4" )
fi
SSPASS=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13 )
SOPASS=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 8 )
MTPORTO=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32 | md5sum | head -c 32)
## Write config file
cat <<EOF > /usr/local/etc/v2ray/config.json
{
"log": {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": 9007,
"protocol": "socks",
"settings": {
"auth": "password",
"accounts": [
{
"user": "user",
"pass": "$SOPASS"
}
],
"udp": true
}
},
{
"port": 9006,
"protocol": "mtproto",
"settings": {
"users": [{"secret": "$MTPORTO"}]
}
},
{
"listen": "0.0.0.0",
"port": 9008,
"protocol": "shadowsocks",
"settings": {
"password": "$SSPASS",
"timeout":60,
"method":"chacha20-ietf-poly1305"
}
},
{
"listen": "0.0.0.0",
"port": 9009,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 0,
"security": "auto"
}
]
}
}
],
"outbound": {
"tag": "proxy",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "$1",
"port": $2,
"users": [
{
"id": "$3",
"alterId": 0,
"security": "chacha20-poly1305"
}
]
}
]
},
"streamSettings": {
"network": "ws"
},
"mux": {
"enabled": true
}
},
"inboundDetour": null,
"outboundDetour": [
{
"protocol": "freedom",
"tag": "freedom"
},
{
"protocol": "blackhole",
"tag": "blackhole"
}
],
"dns": {
"servers": [
"8.8.8.8",
"8.8.4.4",
"localhost"
]
},
"routing": {
"domainStrategy": "IPIfNonMatch",
"settings": {
"rules": [
{
"type": "field",
"outboundTag": "blackhole",
"ip": [
"geoip:private"
]
},
{
"type": "field",
"outboundTag": "freedom",
"ip": [
"geoip:ir"
],
"domain": [
"regexp:^*\\\\.ir$",
"iran:ir"
]
}
]
}
}
}}
EOF
cp ./systemd/system/v2ray.service /etc/systemd/system/
cp ./systemd/system/[email protected] /etc/systemd/system/
## create log files
touch /var/log/v2ray/access.log
touch /var/log/v2ray/error.log
## copy binaries
cp ./v2ray /usr/local/bin/v2ray
cp ./v2ctl /usr/local/bin/v2ctl
chmod +x /usr/local/bin/v2ray
chmod +x /usr/local/bin/v2ctl
## copy dat files
cp ./iran.dat /usr/local/share/v2ray/iran.dat
cp ./geosite.dat /usr/local/share/v2ray/geosite.dat
cp ./geoip.dat /usr/local/share/v2ray/geoip.dat
chown -R nobody /usr/local/share/v2ray/
systemctl daemon-reload
systemctl enable v2ray
systemctl restart v2ray
cd /tmp/
rm -rf ./v2ray
IP=$(curl -s "https://api.ipify.org/" )
## Fallback interanet
if [ "$IP" = ""]
then
IP=$(curl -s "https://dzy.ir/ip.txt" )
fi
VMESS=$(echo "{\"add\":\"$IP\",\"aid\":\"0\",\"host\":\"\",\"id\":\"$UUID\",\"net\":\"tcp\",\"path\":\"\",\"port\":\"9009\",\"ps\":\"Iran-$IP\",\"scy\":\"auto\",\"sni\":\"\",\"tls\":\"\",\"type\":\"none\",\"v\":\"2\"}" | base64)
VMESS=$(sed "s/\=//g" <<<"$VMESS")
VMESS=$(sed ':a; N; s/[[:space:]]//g; ta' <<<"$VMESS")
SHADOW=$(echo "chacha20-ietf-poly1305:$SSPASS" | base64)
SHADOW=$(sed "s/\=//g" <<<"$SHADOW")
SHADOW=$(sed ':a; N; s/[[:space:]]//g; ta' <<<"$SHADOW")
cat <<EOF > ./v2ray-install.log
Output saved into >>>
/tmp/v2ray-install.log
Your Internal IP is: $IP , by api.ipify.org
If your ip is not correct (because of proxy affect etc.) change it manualy in connection configs.
===============================
ShadowSoocks Connection:
ss://$SHADOW@$IP:9008#Iran-$IP
Password:$SSPASS
Port:9008
Encryption:"chacha20-ietf-poly1305"
===============================
V2ray vmess Connection:
vmess://$VMESS
ID/UUID: $UUID
Port: 9009
alterId: 0
===============================
Telegram Socks:
https://t.me/socks?server=$IP&port=9007&user=user&pass=$SOPASS
Telegram MtProto:
https://t.me/proxy?server=$IP&port=9006&secret=$MTPORTO
===============================
Socks5:
IP: $IP
Port: 9007
Username: user
Password: $SOPASS
===============================
EOF
cat ./v2ray-install.log
echo "For check v2ray helth run: systemctl status v2ray"
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root user or run with sudo"
exit
fi
## Check for docker
docker --version
if [ $? -ne 0 ]
then
curl -fsSL https://get.docker.com | sh
fi
## Check for docker compose
docker-compose --version
if [ $? -ne 0 ]
then
curl -L "https://github.com/docker/compose/releases/download/$(curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
fi
rm -f docker-compose.yml
rm -f config.json
rm -rf log
mkdir log
## Get an UUID
UUID=$(cat /proc/sys/kernel/random/uuid)
if [ $? -ne 0 ]
then
UUID= $(curl -s "https://www.uuidgenerator.net/api/version4" )
fi
## Write compose file
cat <<EOF > ./docker-compose.yml
version: "3"
services:
v2ray:
image: v2fly/v2fly-core@sha256:51934d93f10451ed416725943e804038fccf18e1756456bacdecdafb3e84486b
container_name: v2ray
restart: always
ports:
- $1:$1
- 8080:8080
volumes:
- ./config.json:/etc/v2ray/config.json
- ./log/:/var/log/v2ray/
EOF
## Write config file
cat <<EOF > ./config.json
{
"log": {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": 8080,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 64,
"security": "chacha20-poly1305"
}
]
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"response": {
"version": "1.1",
"status": "200",
"reason": "OK",
"headers": {
"Content-Type": ["application/octet-stream", "application/x-msdownload", "text/html", "application/x-shockwave-flash"],
"Transfer-Encoding": ["chunked"],
"Connection": ["keep-alive"],
"Pragma": "no-cache"
}
}
}
}
}
},{
"listen": "0.0.0.0",
"port": $1,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 0,
"security": "chacha20-poly1305"
}
]
},
"streamSettings": {
"network": "ws"
}
}],
"outbound": {
"protocol": "freedom",
"tag": "freedom"
},
"inboundDetour": null,
"outboundDetour": [
{
"protocol": "blackhole",
"tag": "blackhole"
}
],
"routing": {
"domainStrategy": "IPIfNonMatch",
"settings": {
"rules": [
{
"type": "field",
"outboundTag": "blackhole",
"ip": [
"geoip:private"
]
}
]
}
}
}
EOF
docker-compose up -d
IP=$(curl -s "https://api.ipify.org/" )
VMESS=$(echo "{\"add\":\"$IP\",\"aid\":\"0\",\"host\":\"digikala.com\",\"id\":\"$UUID\",\"net\":\"ws\",\"path\":\"\",\"port\":\"$1\",\"ps\":\"Foreign-$IP\",\"scy\":\"chacha20-poly1305\",\"sni\":\"\",\"tls\":\"\",\"type\":\"none\",\"v\":\"2\"}" | base64)
VMESS=$(sed "s/\=//g" <<<"$VMESS")
VMESS=$(sed ':a; N; s/[[:space:]]//g; ta' <<<"$VMESS")
VMESSOBFS=$(echo "{\"add\":\"$IP\",\"aid\":\"64\",\"host\":\"\",\"id\":\"$UUID\",\"net\":\"tcp\",\"path\":\"\",\"port\":\"8080\",\"ps\":\"OBFS-Foreign-$IP\",\"scy\":\"auto\",\"sni\":\"\",\"tls\":\"\",\"type\":\"http\",\"v\":\"2\"}" | base64)
VMESSOBFS=$(sed "s/\=//g" <<<"$VMESSOBFS")
VMESSOBFS=$(sed ':a; N; s/[[:space:]]//g; ta' <<<"$VMESSOBFS")
cat <<EOF > ./bridge-install-by-curl.log
## Run this command on your bridge(interanet) server:
sudo curl -s https://gist.githubusercontent.com/mahmoud-eskandari/960899f3494a1bffa1a29631dbaf0aee/raw/f0b012c43e68468e7683c3e4c2a104dd11841eb7/install-bridge.sh | bash -s $IP $1 $UUID
## If your internal server hasn't access to foreign internet you can also use internal mirror:
sudo curl -s https://v2rayv2ray.s3.ir-thr-at1.arvanstorage.ir/run.sh | bash -s $IP $1 $UUID
####### External Vmess connections ######
============ Diffrent vmess for diffrent ISPs.
WS foreign vmess (v2ray):
vmess://$VMESS
Server: $IP
Port: $1
ID: $UUID
alterId: 0
security: chacha20-poly1305
head type: none
network: ws
domain: [An internal website domain like: digikala.com]
======== ======== ======== ========
Obfoscated TCP foreign vmess (v2ray):
vmess://$VMESSOBFS
Server: $IP
Port: 8080
ID: $UUID
alterId: 64
security: chacha20-poly1305
network: tcp
head type: http
domain: [An internal website domain like: digikala.com]
EOF
cat ./bridge-install-by-curl.log

پنل x-ui

پنل تحت وب مدیریت V2ray و ساخت کاربر و مدیریت سرور

mkdir x-ui && cd x-ui
docker run -itd --network=host \
    -v $PWD/db/:/etc/x-ui/ \
    -v $PWD/cert/:/root/cert/ \
    --name x-ui --restart=unless-stopped \
    enwaiax/x-ui:latest

بعدش بزنید docker logs x-ui

یه پورت نشون میده مثلا: 54321

توی مرورگر بزنید

FOREIGN_IP:PORT

یه پنل وب میده که چینیه میتونید با گوگل ترنزلیت هم ترجمش کنید پسورد پیشفرض admin:admin بعدش حتما عوضش کنید.

میتونید یوزر تعریف کنید دسترسی های جدید و کانکشن جدید بسازید برای کاربرانتون

@hrgh1985
Copy link

سلام
چطوری میتونم خطای
2024/01/15 23:26:36 WARNING - X-UI: access.log doesn't exist in your config.json
را در پنل رفع کنم؟

@hadimousavi79
Copy link

سلام چطوری میتونم خطای 2024/01/15 23:26:36 WARNING - X-UI: access.log doesn't exist in your config.json را در پنل رفع کنم؟

سلام میگه فایل access.log تو فایل config.json نیست ببین اگه این فایل تو مسیر x-ui باشه برو تنظیمات پنل و اونجا access.log رو بهش اضافه کن

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment