部署ReBirth 问题

配置情况:

.env (我把DB_PASSWORD 设置成空了)

.env.local

Make up

访问http://localhost:8888/api/blocks 显是的数量是0,应该没有访问到出块信息.

跟Rebirth同一台机器,正常出块应该没问题。

tail -100f log/production.log

如下:

@classicalliu, 帮忙看一下啊。

你可以先看一下下面的这个 talk 对你有没有帮助:

要修改 .env 里面的内容应该在 .env.local 里面覆盖一下原来的值,不要修改源文件(不过不影响这里的问题)。
这里 db 的 username 和 password 应该是 postgres container 的默认 username / password,所以 password 为空能不能连上 postgres 不确定,但是看 log 好像是连上了。
可以先运行 make ps 看一下 containers 的运行状况,看看是不是 sync 的 container 挂了。

bear@localhost:/opt/re-birth$ make ps
docker-compose ps
Name Command State Ports

re-birth_app_1_59bebe672167 bundle exec puma -C config … Up 3000/tcp
re-birth_db_1_60120c2add51 docker-entrypoint.sh postgres Up 5432/tcp
re-birth_redis_1_aab6f78d6741 docker-entrypoint.sh redis … Up 6379/tcp
re- bundle exec sidekiq -C con … Up 3000/tcp
birth_sidekiq_1_be8b840f3ae4
re-birth_sync_1_386b0433ff69 bash -c rails daemons:sync … Up 3000/tcp
re-birth_web_1_56d29a62c0a5 nginx -g daemon off; Up 0.0.0.0:8888->80/tcp

启动状态贴的有点乱,但是看起来应该都是正常的。

我想我应该知道是什么问题了。
re-birth 跑在 docker 里面,CITA 跑在 host 上面,所以 CITA_URL 用 localhost 不能直接访问。
linux 需要 --network=host,mac 和 windows 应该是 host.docker.internal

修改后删除 docker/datadocker/redis 目录,重新运行 make setupmake up

如果是 mac / windows 就在 .env.local 上面写一下 CITA_URL="http://host.docker.internal:1337"
如果是 linux 就改一下 docker-compose.yml ,参照 https://docs.docker.com/compose/compose-file/#network_mode 使用 host mode.

嗯,很有可能是你说的问题,我的环境是ubt16.04,配置到哪个服务中呢?我刚加入到web服务中,重新make setup /make up 访问127.0.0.1:8888 出现拒绝访问。请指导下。.
web:
build:
context: .
dockerfile: ./docker/web/Dockerfile
depends_on:
- app
ports:
- 8888:80
network_mode: "host"

在 app / sync / sidekiq 都加一下试试

上面的三个app / sync / sidekiq增加后make setup 出现
docker-compose run --rm app bundle exec rake db:setup
Starting re-birth_db_1 … done
Starting re-birth_redis_1 … done
could not translate host name “db” to address: Name or service not known
Couldn’t create ‘re-birth_production’ database. Please check your configuration.
rake aborted!
PG::ConnectionBad: could not translate host name “db” to address: Name or service not known
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in initialize' /usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:innew’
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in connect' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:692:inconnect’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in initialize' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:48:innew’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in postgresql_connection' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:innew_connection’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in checkout_new_connection' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:intry_to_checkout_new_connection’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in acquire_connection' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:incheckout’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in connection' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1010:inretrieve_connection’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_handling.rb:118:in retrieve_connection' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/connection_handling.rb:90:inconnection’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in connection' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:21:increate’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/database_tasks.rb:119:in create' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/database_tasks.rb:139:inblock in create_current’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/database_tasks.rb:316:in block in each_current_configuration' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/database_tasks.rb:313:ineach’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/database_tasks.rb:313:in each_current_configuration' /usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/tasks/database_tasks.rb:138:increate_current’
/usr/local/bundle/gems/activerecord-5.2.2.1/lib/active_record/railties/databases.rake:29:in block (2 levels) in <main>' /usr/local/bundle/gems/rake-12.3.2/exe/rake:27:in<top (required)>’
/usr/local/bundle/bin/bundle:23:in load' /usr/local/bundle/bin/bundle:23:in
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create
(See full trace by running task with --trace)
Makefile:3: recipe for target ‘setup’ failed
make: *** [setup] Error 1

目前找到的方案是

修改 docker-compose.yml

version: '3'
services:
  db:
    image: postgres:10.5
    volumes:
      - ./docker/data:/var/lib/postgresql/data
    network_mode: host

  app: &app_base
    network_mode: host
    build:
      context: .
      dockerfile: ./docker/app/Dockerfile
    volumes:
      - .:/app
    command: bundle exec puma -C config/puma.docker.rb
    depends_on:
      - db
      - redis
  sync:
    network_mode: host
    build:
      context: .
      dockerfile: ./docker/app/Dockerfile
    volumes:
      - .:/app
    command: bash -c "rails daemons:sync:start && tail -f /app/log/production.log"
    depends_on:
      - db

  web:
    build:
      context: .
      dockerfile: ./docker/web/Dockerfile
    depends_on:
      - app
    ports:
      - 8888:80

  redis:
    network_mode: host
    image: redis:5.0.1
    volumes:
      - ./docker/redis:/data


  sidekiq:
    <<: *app_base
    ports: []
    command: bundle exec sidekiq -C config/sidekiq.yml

修改 .env.local

DB_HOST="localhost"
REDIS_URL="redis://localhost:6379/8"

之后删除 docker/data, docker/redis 然后重新执行 make setupmake up

不过这样 web 容器会不可用,可以访问 3000 端口代替原来的 8888,或者在外面架一层 nginx

bear@localhost:/opt/re-birth$ make setup
docker-compose build
db uses an image, skipping
redis uses an image, skipping
Building sync
Step 1/19 : FROM ruby:2.5.3
—> 72aaaee1eea4
Step 2/19 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs git autoconf locales locales-all && apt-get clean && rm -rf /var/lib/apt/lists/*
—> Using cache
—> 4944def3be58
Step 3/19 : RUN locale-gen en_US.UTF-8
—> Using cache
—> 36a9867f9b80
Step 4/19 : ENV LANG en_US.UTF-8
—> Using cache
—> cfbda6fe2196
Step 5/19 : ENV LANGUAGE en_US.UTF-8
—> Using cache
—> d4e32c6eaae9
Step 6/19 : ENV LC_ALL en_US.UTF-8
—> Using cache
—> 760c9c90e471
Step 7/19 : RUN mkdir /secp256k1
—> Using cache
—> 72069ab7264d
Step 8/19 : WORKDIR /secp256k1
—> Using cache
—> 9188e07a1971
Step 9/19 : RUN git clone https://github.com/bitcoin-core/secp256k1.git . && ./autogen.sh && ./configure --enable-module-recovery && make && make install
—> Using cache
—> ba5047ae1300
Step 10/19 : RUN echo ‘gem: --no-document’ >> /usr/local/etc/gemrc
—> Using cache
—> 4f78506d2e6c
Step 11/19 : RUN gem install bundler
—> Using cache
—> 3e64e52d9acc
Step 12/19 : RUN mkdir /app
—> Using cache
—> ef3845503e9d
Step 13/19 : WORKDIR /app
—> Using cache
—> ae575602ca93
Step 14/19 : COPY Gemfile Gemfile
—> Using cache
—> bc4df2c826c5
Step 15/19 : COPY Gemfile.lock Gemfile.lock
—> Using cache
—> bf4b576c15ad
Step 16/19 : RUN bundle install --jobs 20 --retry 5 --without development test
—> Using cache
—> 8ac57189603e
Step 17/19 : COPY . /app
—> 80b00848f9ec
Step 18/19 : ENV RAILS_ENV production
—> Running in 53ec1de47937
Removing intermediate container 53ec1de47937
—> 347603d63d13
Step 19/19 : EXPOSE 3000
—> Running in 4b10535088eb
Removing intermediate container 4b10535088eb
—> 0611d84840b5
Successfully built 0611d84840b5
Successfully tagged re-birth_sync:latest
Building app
Step 1/19 : FROM ruby:2.5.3
—> 72aaaee1eea4
Step 2/19 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs git autoconf locales locales-all && apt-get clean && rm -rf /var/lib/apt/lists/*
—> Using cache
—> 4944def3be58
Step 3/19 : RUN locale-gen en_US.UTF-8
—> Using cache
—> 36a9867f9b80
Step 4/19 : ENV LANG en_US.UTF-8
—> Using cache
—> cfbda6fe2196
Step 5/19 : ENV LANGUAGE en_US.UTF-8
—> Using cache
—> d4e32c6eaae9
Step 6/19 : ENV LC_ALL en_US.UTF-8
—> Using cache
—> 760c9c90e471
Step 7/19 : RUN mkdir /secp256k1
—> Using cache
—> 72069ab7264d
Step 8/19 : WORKDIR /secp256k1
—> Using cache
—> 9188e07a1971
Step 9/19 : RUN git clone https://github.com/bitcoin-core/secp256k1.git . && ./autogen.sh && ./configure --enable-module-recovery && make && make install
—> Using cache
—> ba5047ae1300
Step 10/19 : RUN echo ‘gem: --no-document’ >> /usr/local/etc/gemrc
—> Using cache
—> 4f78506d2e6c
Step 11/19 : RUN gem install bundler
—> Using cache
—> 3e64e52d9acc
Step 12/19 : RUN mkdir /app
—> Using cache
—> ef3845503e9d
Step 13/19 : WORKDIR /app
—> Using cache
—> ae575602ca93
Step 14/19 : COPY Gemfile Gemfile
—> Using cache
—> bc4df2c826c5
Step 15/19 : COPY Gemfile.lock Gemfile.lock
—> Using cache
—> bf4b576c15ad
Step 16/19 : RUN bundle install --jobs 20 --retry 5 --without development test
—> Using cache
—> 8ac57189603e
Step 17/19 : COPY . /app
—> Using cache
—> 80b00848f9ec
Step 18/19 : ENV RAILS_ENV production
—> Using cache
—> 347603d63d13
Step 19/19 : EXPOSE 3000
—> Using cache
—> 0611d84840b5
Successfully built 0611d84840b5
Successfully tagged re-birth_app:latest
Building web
Step 1/10 : FROM nginx:1.15.2
—> c82521676580
Step 2/10 : RUN apt-get update -qq && apt-get -y install apache2-utils
—> Using cache
—> 01f84cf67a13
Step 3/10 : ENV RAILS_ROOT /app
—> Using cache
—> 0cc9082f3536
Step 4/10 : WORKDIR $RAILS_ROOT
—> Using cache
—> a4dd1cd492ae
Step 5/10 : RUN mkdir log
—> Using cache
—> 736cce10011c
Step 6/10 : COPY public public/
—> Using cache
—> 95dfaef8b810
Step 7/10 : COPY docker/web/nginx.conf /tmp/docker.nginx
—> Using cache
—> a20814aa6940
Step 8/10 : RUN envsubst ‘$RAILS_ROOT’ < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf
—> Using cache
—> 67aa6c31e19c
Step 9/10 : EXPOSE 80
—> Using cache
—> c9c23c98503d
Step 10/10 : CMD [ “nginx”, “-g”, “daemon off;” ]
—> Using cache
—> 2aca80fb16a1
Successfully built 2aca80fb16a1
Successfully tagged re-birth_web:latest
Building sidekiq
Step 1/19 : FROM ruby:2.5.3
—> 72aaaee1eea4
Step 2/19 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs git autoconf locales locales-all && apt-get clean && rm -rf /var/lib/apt/lists/*
—> Using cache
—> 4944def3be58
Step 3/19 : RUN locale-gen en_US.UTF-8
—> Using cache
—> 36a9867f9b80
Step 4/19 : ENV LANG en_US.UTF-8
—> Using cache
—> cfbda6fe2196
Step 5/19 : ENV LANGUAGE en_US.UTF-8
—> Using cache
—> d4e32c6eaae9
Step 6/19 : ENV LC_ALL en_US.UTF-8
—> Using cache
—> 760c9c90e471
Step 7/19 : RUN mkdir /secp256k1
—> Using cache
—> 72069ab7264d
Step 8/19 : WORKDIR /secp256k1
—> Using cache
—> 9188e07a1971
Step 9/19 : RUN git clone https://github.com/bitcoin-core/secp256k1.git . && ./autogen.sh && ./configure --enable-module-recovery && make && make install
—> Using cache
—> ba5047ae1300
Step 10/19 : RUN echo ‘gem: --no-document’ >> /usr/local/etc/gemrc
—> Using cache
—> 4f78506d2e6c
Step 11/19 : RUN gem install bundler
—> Using cache
—> 3e64e52d9acc
Step 12/19 : RUN mkdir /app
—> Using cache
—> ef3845503e9d
Step 13/19 : WORKDIR /app
—> Using cache
—> ae575602ca93
Step 14/19 : COPY Gemfile Gemfile
—> Using cache
—> bc4df2c826c5
Step 15/19 : COPY Gemfile.lock Gemfile.lock
—> Using cache
—> bf4b576c15ad
Step 16/19 : RUN bundle install --jobs 20 --retry 5 --without development test
—> Using cache
—> 8ac57189603e
Step 17/19 : COPY . /app
—> Using cache
—> 80b00848f9ec
Step 18/19 : ENV RAILS_ENV production
—> Using cache
—> 347603d63d13
Step 19/19 : EXPOSE 3000
—> Using cache
—> 0611d84840b5
Successfully built 0611d84840b5
Successfully tagged re-birth_sidekiq:latest
docker-compose run --rm app bundle exec rake db:setup
Starting re-birth_db_1 … done
Starting re-birth_redis_1 … done
ERROR: Cannot create container for service app: conflicting options: host type networking can’t be used with links. This would result in undefined behavior
Makefile:3: recipe for target ‘setup’ failed
make: *** [setup] Error 1

.env.local

DB_PASSWORD=""
DB_HOST=“localhost”
REDIS_URL=“redis://localhost:6379/8”
SECRET_KEY_BASE=“df30f0082c9ade324744113ec7b5423d7b7b87c8ff757580d0b571369ccf8fd8de3ba8203172f4d9ba0b13a9c148d331eb4379d75c79fde5c37b099cd60a3516”

如果只是docker中的rebirth CITA_URL 用 localhost 连不上CITA ,可以将这里改成宿主机的内网IP

重新进行部署OK了,CITA服务和Rebirth服务进行了分离,.evn.local 中直接配IP地址CITA_URL=“http://192.168.0.174:1337/” 。另外提示下:DB_PASSWORD="" 配置默认为空。

curl -v http://192.168.0.175:8888/api/blocks

  • Trying 192.168.0.175…
  • Connected to 192.168.0.175 (192.168.0.175) port 8888 (#0)

GET /api/blocks HTTP/1.1
Host: 192.168.0.175:8888
User-Agent: curl/7.47.0
Accept: /

< HTTP/1.1 200 OK
< Server: nginx/1.15.2
< Date: Fri, 26 Jul 2019 01:13:37 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< ETag: W/“450fac38f717aa2199e0a075113024b2”
< Cache-Control: max-age=0, private, must-revalidate
< X-Request-Id: d2fe81ba-2c6a-43d9-8368-305a3bd9b56e
< X-Runtime: 0.018291
< Vary: Origin
<
{“result”:{“count”:866,“blocks”:[{“version”:2,“header”:{“proof”:{“Bft”:{“round”:0,“height”:864,“commits”:{“0x098ed89588ab1d4090e1f8b85eb2b7ad75ee372e”:"0x151cbbdc …

其中192.168.0.174是CITA服务地址;175是Rebirth缓存服务IP。
谢谢支持!

1赞

你好,请问我这边也出现这个问题,cita_url时配置成公网ip,但是还是没有数据


image

没看出有什么问题, logs/production.log 里有什么信息么

好像没什么问题。。

好像看起来也是正常的
在这台机器上执行 curl -X POST --data '{"jsonrpc":"2.0","method":"blockNumber","params":[],"id":83}' http://172.17.135.104:1340 试一下,看能不能正常访问到数据。

可以访问数据,所以应该是rebirth的问题
image
我的配置文件配置在.env.local


docker都启动了,所以很疑惑