Skip to content

Instantly share code, notes, and snippets.

@jim3333
Last active January 20, 2024 02:49
Show Gist options
  • Save jim3333/5fe260b989def438fb1d87eb3bdcada5 to your computer and use it in GitHub Desktop.
Save jim3333/5fe260b989def438fb1d87eb3bdcada5 to your computer and use it in GitHub Desktop.

批量部署bevm 节点

编辑 /etc/docker/daemon.json 去除docker默认30个桥接限制, 修改完后, 需要重启docker

{
  "default-address-pools": [
    {
      "base": "172.80.0.0/16",
      "size": 24
    },
    {
      "base": "172.90.0.0/16",
      "size": 24
    }
  ]
}

docker-compose.yaml 模板文件

version: '3'

services:
  node:
    image: btclayer2/bevm:v0.1.1
    container_name: test1
    restart: always
    tty: true
    command: bevm "--chain=testnet" "--name=0x00000000" "--pruning=archive" --telemetry-url "wss://telemetry.bevm.io/submit 0"
    volumes:
      - /home/test1/bevm:/root/.local/share/bevm
    ports:
      - "1.1.1.1:30333:30333"
      - "1.1.1.1:8087:8087"
      - "1.1.1.1:9615:9615"

networks:
  default:
    driver: bridge
    driver_opts:
      com.docker.network.host_ipv4: 1.1.1.1

其中需要替换 0x0x00000000 为你的eth地址, test1为docker名, 1.1.1.1为外网IP, 然后生成docker-compose.yaml文件到 '/home/test1' 切换到改目录, 运行 docker-compose up

附带一个Python脚本

import pathlib
import subprocess
import time
import sys


class BevmClient(object):
    HOME = "/opt/"

    def __init__(self, seed, address, ip):
        self.seed, self.address, self.ip = seed, address, ip
        self.bp = f"{self.HOME}/{self.seed}"

    def gen_config(self):
        pathlib.Path(self.bp).mkdir(parents=True, exist_ok=True)
        r = open("docker-compose.yaml").read()
        r = r.replace('1.1.1.1', self.ip)
        r = r.replace('0x00000000', self.address)
        r = r.replace('test1', self.seed)
        open(self.bp + "/docker-compose.yaml", "w").write(r)

    def run(self):
        r = subprocess.run("docker-compose up -d", shell=True, cwd=self.bp)
        if r.returncode != 0:
            subprocess.run("docker-compose down", shell=True, cwd=self.bp)
            subprocess.run("docker-compose up -d", shell=True, cwd=self.bp)


def task1():
    for line in open(sys.argv[1]):
        seed, address, ip = line.strip().split("----")
        print(seed, address, ip)
        bc = BevmClient(seed, address, ip)
        bc.gen_config()
        bc.run()
        time.sleep(10)


if __name__ == '__main__':
    task1()

运行 s.py a.txt, 其中 a.txt 内容如下

a1----0xaaaaa----ip1
a2----0xbbbbb----ip2
@jim3333
Copy link
Author

jim3333 commented Jan 19, 2024

附带 https://t.me/racknerd_promo 官方, 可以在这里买杜甫.

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