2019独角兽企业重金招聘Python工程师标准>>>
eureka 配置中心,注册中心环境搭建kafka 消息中间件
下载安装 zookeeper, kafka,kafka启动前保证zookeeper启动状态。
①、https://www.apache.org/dyn/closer.cgi/zookeeper/
进入Zookeeper解压目录,E:\WindowsOS_ApacheKafka_20160126\Zookeeper\zookeeper-3.4.6\conf
②、将“zoo_sample.cfg”重命名为“zoo.cfg”。
③、配置启动日记目录,用#注解调 dataDir=/tmp/zookeeper
dataDir=E:\WindowsOS_ApacheKafka_20160126\Zookeeper\data
④、系统环境变量中添加:ZOOKEEPER_HOME = E:\WindowsOS_ApacheKafka_20160126\Zookeeper\zookeeper-3.4.6
⑤、编辑系统变量path,加上: ZOOKEEPER_HOME%\bin; ⑥、确认zoo.cfg文件中默认的Zookeeper端口(默认端口2181)。
打开新的cmd,输入zkserver,运行Zookeeper。
http://archive.apache.org/dist/kafka/1.1.0/ 下载kafka_2.11-0.9.0.0.tgz,解压后重命名为kafka_2.11,进入Kafka配置目录,E:\WindowsOS_ApacheKafka_20160126\Kafka\kafka_2.11\config
编辑文件“server.properties”
找到并用#注解“log.dirs=/tmp/kafka-logs”
添加自己的日记目录:log.dirs=E:\WindowsOS_ApacheKafka_20160126\Kafka\kafka-logs
如果Zookeeper在某些其他的机器或集群上运行,可以将“zookeeper.connect:2181”修改为自定义IP与端口。在这里使用了同一个机器,所以没其他做修改。文件中的Kafka端口和broker.id也是可以配置的。默认设置不变。
机器的localhost也为127.0.0.1,这里我也修改为ipv4的,防止localhost为ipv6时受影响。 afka会按照默认,在9092端口上运行,并连接zookeeper的默认端口:2181。
在zookeeper的基础上,运行Kafka服务
进入Kafka安装目录,E:\WindowsOS_ApacheKafka_20160126\Kafka\kafka_2.11
切换到命令行窗口,运行kafka。
.\bin\windows\kafka-server-start.bat .\config\server.properties
现在创建主题,命名为“test”,replication factor=1(因为只有1个Kafka服务器在运行)。如果集群中所运行的Kafka服务器不止1个,可以相应增加replication-factor,从而提高数据可用性和系统容错性。
2. 在E:\WindowsOS_ApacheKafka_20160126\Kafka\kafka_2.11\bin\windows打开新的命令行。
3. 输入下面的命令,回车:
kafka-topics.bat –create –zookeeper localhost:2181 –replication-factor 1 –partitions 1 –topic test
创建Producer及Consumer来测试服务器。
1.在E:\WindowsOS_ApacheKafka_20160126\Kafka\kafka_2.11\bin\windows打开新的命令行。
2.输入以下命令,启动producer,可以输入消息:
kafka-console-producer.bat –broker-list localhost:9092 –topic test
3.在同样的位置E:\WindowsOS_ApacheKafka_20160126\Kafka\kafka_2.11\bin\windows再次打开新的命令行。
4.现在输入下列命令启动consumer,可以获取消息:
kafka-console-consumer.bat –zookeeper localhost:2181 –topic test
两个命令行窗口,producer可以输入任何消息,consumer可以获取消息
1. eureka-server
1.1 pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1.2 ====== application.yml=======
server:
port: 8761
# 是否要开启基本的鉴权
security:
basic:
enabled: false
user:
name: admin
password: 123456
management:
security:
enabled: false
spring:
profiles:
active: peer2,native
cloud:
config:
server:
native:
search-locations: file:///D:/Users/xuzhi268/zhongchou/config_profiles
eureka:
instance:
hostname: peer1
lease-renewal-interval-in-seconds: 30 #指定续约更新频率,默认是 30s
environment: dev
client:
register-with-eureka: false # 禁用eureka作为客户端注册自己
fetch-registry: false # 表示是否从eureka server获取注册信息,如果是单一节点,不需要同步其他eureka server节点,则可以设置为false,但此处为集群,应该设置为true,默认为true,可不设置
serviceUrl:
defaultZone: http://peer1:8761/eureka/,http://peer2:8766/eureka/
#http://admin:123456@peer1:8761/eureka/,http://admin:123456@peer2:8766/eureka/ #多个用逗号隔开
-------------------------------- server_2 ------------------------------
server:
port: 8766
security:
basic:
enabled: false
user:
name: admin
password: 123456
management:
security:
enabled: false
spring:
application:
name: eureka
profiles:
active: peer1,native
cloud:
config:
server:
native:
search-locations: file:///D:/Users/xuzhi268/zhongchou/config_profiles
stream:
default-binder: kafka
kafka:
binder:
brokers: localhost:9092
zk-nodes: localhost:2181
eureka:
instance:
hostname: peer2
lease-renewal-interval-in-seconds: 30
environment: dev
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://peer1:8761/eureka/,http://peer2:8766/eureka/
#http://admin:123456@peer1:8761/eureka/,http://admin:123456@peer2:8766/eureka/
1.3 ======= eureka-server 启动类 ===========
package org.eureka.server;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
@EnableConfigServer
public class EurekaServerStarter {
public static void main(String[] args) {
new SpringApplicationBuilder(EurekaServerStarter.class).run(args);
}
}
2 ========== ucenter 用户中心 ==========
2.1 pom.xml
2.2 application.yml 和
#server:
#当前服务端口号
# port: 8762
spring:
application:
#当前应用名称
name: ucenter
index: 1
cloud:
stream:
bindings:
springCloudBusInput:
destination: springCloudBus
group: cloud-bus-testgroup:${spring.application.index}
eureka:
client:
serviceUrl:
#注册中心的地址
defaultZone: http://peer1:8761/eureka/,http://peer2:8766/eureka/
------------------------bootstrap.yml---------------------------
#禁用配置中心权限验证
management:
security:
enabled: false
spring:
cloud:
config:
uri: http://localhost:8761/
feign:
httpclient:
enabled: true
max-connections: 200 # 默认值
max-connections-per-route: 50 # 默认值
2.3 启动类
package com.cloud.eureka.client.ucenter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class UcenterApplicationRunner {
public static void main(String[] args) {
new SpringApplicationBuilder(UcenterApplicationRunner.class).properties("server.port=" + 8765).run(args);
}
}