Skip to content

Instantly share code, notes, and snippets.

@sahand12
Forked from mahmoud-eskandari/README.md
Created October 17, 2022 12:40
Show Gist options
  • Save sahand12/ac9a0597cd2345b13dd3a82a082ae8cf to your computer and use it in GitHub Desktop.
Save sahand12/ac9a0597cd2345b13dd3a82a082ae8cf to your computer and use it in GitHub Desktop.
Install vmess via docker, docker-compose on (Ubuntu +18, CentOS 7)
#!/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
set -e
rm -f docker-compose.yml
rm -f config.json
rm -rf log
mkdir log
## Get an UUID
UUID=$(curl -s "https://www.uuidgenerator.net/api/version4" )
## Write compose file
cat <<'EOF' > ./docker-compose.yml
version: "3"
services:
v2ray:
image: v2fly/v2fly-core:latest
container_name: v2ray
restart: always
ports:
- ${VMESS_PORT:-2083}:2083
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": 2083,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 10,
"security": "auto"
}
]
}
}
],
"outbound": {
"tag": "proxy",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "$1",
"port": $2,
"users": [
{
"id": "$3",
"alterId": 10,
"security": "none"
}
]
}
]
},
"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"
]
}
]
}
}
}
EOF
docker-compose up -d
IP=$(curl -s "https://api.ipify.org/" )
echo "\n Congrates Your v2ray server is ready:\n"
echo "ip address: $IP \n port: $2 \n id: $UUID \n alterId: 10 \n security: auto \n network: tcp"
#!/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=$(curl -s "https://www.uuidgenerator.net/api/version4" )
## Write compose file
cat <<EOF > ./docker-compose.yml
version: "3"
services:
v2ray:
image: v2fly/v2fly-core:latest
container_name: v2ray
restart: always
ports:
- $1:$1
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"
},
"inbound": {
"listen": "0.0.0.0",
"port": $1,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 10,
"security": "auto"
}
]
},
"streamSettings": {
"network": "ws"
}
},
"outbound": {
"protocol": "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/" )
echo "\n Run this command on your bridge(interanet) server:\n"
echo "curl -s https://gist.githubusercontent.com/mahmoud-eskandari/960899f3494a1bffa1a29631dbaf0aee/raw/2ce51b9b44044d7a692e0710bec0f322921754c4/install-bridge.sh | bash -s $IP $1 $UUID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment