由于发现schema registry相关资料较少,主要在此介绍其口令认证配置方式。
1. 安装包
在 schema registry安装包下载 下载需要的版本,并解压。
2. 配置
配置文件位于etc/schema-registry目录下,口令认证的话首先需要创建文件记录账号用户名密码及对应的角色。
文件schema-registry-password-file:
然后需要创建jaas文件schema-registry-jaas-config.conf,读取用户名密码配置:
1 2 3 4 5
| SchemaRegistry-Props { org.eclipse.jetty.jaas.spi.PropertyFileLoginModule required file="{addr}/schema-registry-password-file" debug="false"; };
|
最后就是schema-registry.properties的配置。
1
| listeners=http://{ip}:8081
|
配置url和port。
1 2 3 4 5 6 7 8 9
| authentication.method=BASIC authentication.roles=admin,user authentication.realm=SchemaRegistry-Props
basic.auth.credentials.source=USER_INFO basic.auth.user.info=user:password
mode.mutability=true
|
如果kafka有口令认证的话,要注意加上对应的配置:
1 2 3 4 5 6
| kafkastore.bootstrap.servers=SASL_PLAINTEXT://{ip}:9092
kafkastore.security.protocol=SASL_PLAINTEXT kafkastore.sasl.mechanism=PLAIN kafkastore.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="password";
|
3. 启动
启动脚本在bin目录下。
由于需要导入参数和后台启动,建议写个脚本。
1 2
| export SCHEMA_REGISTRY_OPTS=-Djava.security.auth.login.config={addr}/schema-registry-jaas-config.conf /usr/local/schema-registry/bin/schema-registry-start /usr/local/schema-registry/etc/schema-registry/schema-registry.properties >> {log file} 2>&1 &
|
将{log file}替换为实际输出日志的位置。
4. 验证
1
| curl http://{ip}:8081/subjects
|
会响应
1
| {"error_code":401,"message":"Unauthorized"}
|
因为需要加上用户名密码:
1
| curl -u user:password http://{ip}:8081/subjects
|
得到的响应是一个列表就证明成功啦!