apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.

Home Page:https://seata.apache.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker同时运行consul和seata, 配置seata application.yml的consul注册中心时, 总是报找不到ip和端口

98549844 opened this issue · comments

image

seata v2.0 application.yml配置文件内容, 请问哪里配置出错了 ?
image

docker consul cluster 已经运行成功并可以服务发现
image
image

I've done some testing locally and was unable to reproduce the problem described in your issue. One possible reason is that your configuration file might not have been correctly mounted into the container.

I've done some testing locally and was unable to reproduce the problem described in your issue. One possible reason is that your configuration file might not have been correctly mounted into the container.

i think midified application.yml are copy into docker seata server, because i using orignal application.yml to config. when i modified and copy into seata container and re-run container. the seata container fail to start

贴上我的docker-compose

version: '3.8'
networks:
ace-network: # 网络名
name: ace-network
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16

services:
consul-1:
image: consul:1.15.4 #应该是consul 最新的docker版本
container_name: consul-1
hostname: consul-1
restart: always
ports:
- 8500:8500
environment:
CONSUL_BIND_INTERFACE: eth0
command: >
agent
--server=true
--bootstrap-expect=3
--client=0.0.0.0
--ui
--node=consul-1
networks:
ace-network:
ipv4_address: 172.20.0.2

consul-2:
image: consul:1.15.4
container_name: consul-2
hostname: consul-2
restart: always
ports:
- 8501:8500
environment:
CONSUL_BIND_INTERFACE: eth0
command: >
agent
--server=true
--bootstrap-expect=3
--client=0.0.0.0
--join consul-1
--ui
--node=consul-2
depends_on:
- consul-1
networks:
ace-network:
ipv4_address: 172.20.0.3

consul-3:
image: consul:1.15.4
container_name: consul-3
hostname: consul-3
restart: always
ports:
- 8502:8500
environment:
CONSUL_BIND_INTERFACE: eth0
command: >
agent
--server=true
--bootstrap-expect=3
--client=0.0.0.0
--join consul-1
--ui
--node=consul-3
depends_on:
- consul-2
networks:
ace-network:
ipv4_address: 172.20.0.4

seata2:
image: seataio/seata-server:latest
container_name: seata2
hostname: seata2
ports:
- "7091:7091"
- "8091:8091"
environment:
- SEATA_PORT=8091
- STORE_MODE=file # 事后需要到seata2: application.yml修改
depends_on:
- consul-1
- consul-2
- consul-3
- mysql8
networks:
ace-network:
ipv4_address: 172.20.0.6

mysql8:
image: mysql:latest
container_name: mysql8
hostname: mysql8
restart: always
environment:
MYSQL_DATABASE: ace
MYSQL_USER: garlam
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
depends_on:
- consul-1
- consul-2
- consul-3
networks:
- ace-network

1. copy from container to host

docker cp
seata2:/seata-server/resources/
/host-path

2. modify application.yml

原文在下一个贴

3. copy updated application.yml from host to container

docker cp
/host-path
seata2:/seata-server/resources/

#seata container's application.yml

server:
port: 7091

spring:
application:
name: seata2

logging:
config: classpath:logback-spring.xml
file:
path: ${log.home:${user.home}/logs/seata}
extend:
logstash-appender:
destination: 127.0.0.1:4560
kafka-appender:
bootstrap-servers: 127.0.0.1:9092
topic: logback_to_logstash

console:
user:
username: seata
password: seata
seata:
config: #配置
# support: nacos, consul, apollo, zk, etcd3
type: consul
server-addr: 172.21.0.2:8500
acl-token:
key: seata.properties
registry: #注册
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: consul
cluster: seata2
server-addr: 172.21.0.2:8500
acl-token:
#172.21.0.2

#172.21.0.6

store:
mode: db
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://172.21.0.6:3306/seata?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
user: root
password: root
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 1000
max-wait: 5000

#server:
#service-port: 8091 #If not configured, the default is '${server.port} + 1000'
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,//*.css,//.js,/**/.html,//*.map,//.svg,/**/.png,//*.jpeg,//*.ico,/api/v1/auth/login,/version.json

config: 
  type: consul
  consul:
    server-addr: 172.21.0.2:8500
    acl-token:
    key: seata.properties
config: 
  type: consul
  consul:
    server-addr: 172.21.0.2:8500
    acl-token:
    key: seata.properties

谢谢, 根据你的代码, 修改了application, 好像读到ip和端口了
但它弹出
java.lang.ExceptionInInitializerError: null
Caused by: java.lang.NullPointerException: null
image

会不会是application.yml的宿进问题引起 ???
application.txt

If the configuration center is specified as consul, has a configuration named seata.properties been added on consul?

https://seata.apache.org/zh-cn/docs/user/configuration/consul#%E6%8F%90%E4%BA%A4-key-value-%E9%85%8D%E7%BD%AE%E8%87%B3-consul

https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt

好像我没有配置, 有没有更多资料参考??? 没太看得明白那两个link的要求

If the configuration center is specified as consul, has a configuration named seata.properties been added on consul?
https://seata.apache.org/zh-cn/docs/user/configuration/consul#%E6%8F%90%E4%BA%A4-key-value-%E9%85%8D%E7%BD%AE%E8%87%B3-consul
https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt

好像我没有配置, 有没有更多资料参考??? 没太看得明白那两个link的要求

Use this script: https://github.com/apache/incubator-seata/blob/2.x/script/config-center/consul/consul-config.sh to upload the https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt and upload the contents of the configuration file (which can be adjusted as needed) to the console.

seata是在docker里运行的一个container, 要把这段.sh copy到container里执行吗,
image

然后.txt upload去consul 容器内? 是在localhost:8500页面上传? 怎样上传, 如果通过docker cp 上传, 放在容器哪里 ?
image

docker 运行的consul是一个集群, 每个consul容器, 都要上传一份?

If the configuration center is specified as consul, has a configuration named seata.properties been added on consul?
https://seata.apache.org/zh-cn/docs/user/configuration/consul#%E6%8F%90%E4%BA%A4-key-value-%E9%85%8D%E7%BD%AE%E8%87%B3-consul
https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt

好像我没有配置, 有没有更多资料参考??? 没太看得明白那两个link的要求

意思就是需要将config.txt文件中的内容配置到consul上名为 seata.properties 的key下。官网提供的几种方式任选一种都可以。

It means that you need to configure the contents of the config.txt file under the key named seata.properties on the consul. You can do this in any of the ways provided on the official website.

If the configuration center is specified as consul, has a configuration named seata.properties been added on consul?
https://seata.apache.org/zh-cn/docs/user/configuration/consul#%E6%8F%90%E4%BA%A4-key-value-%E9%85%8D%E7%BD%AE%E8%87%B3-consul
https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt

好像我没有配置, 有没有更多资料参考??? 没太看得明白那两个link的要求

Use this script: https://github.com/apache/incubator-seata/blob/2.x/script/config-center/consul/consul-config.sh to upload the https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt and upload the contents of the configuration file (which can be adjusted as needed) to the console.

seata是在docker里运行的一个container, 要把这段.sh copy到container里执行吗, image

然后.txt upload去consul 容器内? 是在localhost:8500页面上传? 怎样上传, 如果通过docker cp 上传, 放在容器哪里 ? image

docker 运行的consul是一个集群, 每个consul容器, 都要上传一份?

不要求在seata容器里执行,在任何能连上consul的机器上都可以执行此脚本。或者从consul控制台添加也可以。
如果consul是一个集群,那他们的配置不应该是共享的吗?

It is not required to be executed in the seata container, this script can be executed on any machine that can connect to consul. Or adding it from the consul console is fine. If consul is a cluster, shouldn't their configuration be shared?

If the configuration center is specified as consul, has a configuration named seata.properties been added on consul?
https://seata.apache.org/zh-cn/docs/user/configuration/consul#%E6%8F%90%E4%BA%A4-key-value-%E9%85%8D%E7%BD%AE%E8%87%B3-consul
https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt

好像我没有配置, 有没有更多资料参考??? 没太看得明白那两个link的要求

意思就是需要将config.txt文件中的内容配置到consul上名为 seata.properties 的key下。官网提供的几种方式任选一种都可以。

It means that you need to configure the contents of the config.txt file under the key named seata.properties on the consul. You can do this in any of the ways provided on the official website.

like this ? 选YMAL correct ?
image

image

最后, 我在consul配了seata.properties, 然后保存,
删除seata容器, 再docker run一个新seata容器,
consul已经服务发现到seata容器了,
意思是, application.yml根本不用动它 ?

这个格式应该是JSON吧,我对consul不是很了解,选择配置对应的格式即可。

consul作为注册中心,受application.yml中的registry配置控制。
作为配置中心,则受config配置控制。

This format should be JSON, I don't know much about consul, just choose to configure the corresponding format.

As a registry, consul is controlled by the registry configuration in application.yml. As a configuration center, it is controlled by the config configuration.

The application.yml is a metadata configuration, and config.$type.key refers to the transaction rule configuration.