请参阅下面的编辑以获得更多的信息.
长话短说,我试图让Unifi控制器在我的家Kubernetes集群上运行。在这样做时,我需要分散MongoDB数据库,因为将MongoDB实例与Kubernetes上的每个副本捆绑在一起会导致数据库崩溃。以下是我的项目:控制器
在此过程中,我编写了以下脚本,该脚本在为MongoDB容器提供服务时运行
mongo \
--username ubnt \
--password "{{ mongodb_password }}" \
--authenticationDatabase admin \
--eval 'db.getSiblingDB("unifi").createUser({user: "ubnt", pwd: "{{ mongodb_password }}", roles: [{role: "readWrite", db: "unifi"}]})'
mongo \
--username ubnt \
--password "{{ mongodb_password }}" \
--authenticationDatabase admin \
--eval 'db.getSiblingDB("unifi_stat").createUser({user: "ubnt", pwd: "{{ mongodb_password }}", roles: [{role: "readWrite", db: "unifi_stat"}]})'然后,我将Unifi配置为通过配置如下的卷挂载system.properties文件与数据库对话:
# Inform IP Address
system_ip={{ load_balancer_ip }}
# Autobackup directory
autobackup.dir=/backups
# External MongoDB information
db.mongo.local=false
db.mongo.uri=mongodb://ubnt:{{ mongodb_password }}@unifi-controller-mongodb:27017/unifi
statdb.mongo.uri=mongodb://ubnt:{{ mongodb_password }}@unifi-controller-mongodb:27017/unifi_stat
unifi.db.name=unifi这被配置为由乌比基提指示。
这一切都能工作,当Kubernetes部署启动时,我看到Unifi连接到日志中的MongoDB实例。此外,如果我手动连接到MongoDB数据库并运行一个show collections,我可以看到已经创建了许多新的集合。但是,Unifi Controller在这里停止生成日志。
如果我在容器的后台手动停止运行Unifi的jar文件,然后重新启动它,则会生成以下堆栈跟踪:
$> s6-setuidgid abc java -Xmx1024M -jar /usr/lib/unifi/lib/ace.jar start
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter INFO: destroy called
Exception in thread "launcher" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Ò00000' defined in class com.ubnt.service.AppContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [com.ubnt.service.P.D com.ubnt.service.AppContext.Ò00000()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbService' defined in class com.ubnt.service.AppContext: Invocation of init method failed; nested exception is com.mongodb.CommandFailureException: { "serverUsed" : "unifi-controller-mongodb:27017" , "ok" : 0.0 , "errmsg" : "not authorized on unifi to execute command { dropDatabase: 1 }" , "code" : 13 , "codeName" : "Unauthorized"}这里的关键要素是
未授权在unifi上执行命令{ dropDatabase: 1 }“
这就是我对MongoDB的理解到此为止的地方。我的问题开始了。我认为,Unifi在连接到数据库和创建集合后不继续启动或记录任何附加消息的原因是它没有在MongoDB数据库上执行操作。它没有必要的权限来执行的操作。
当我提供MongoDB Docker容器时,我指定了MONGO_INITDB_ROOT_USERNAME & MONGO_INITDB_ROOT_PASSWORD环境变量。我相信,这会打开auth模式。我可以通过我为这些变量提供的用户名和密码连接到MongoDB的admin身份验证数据库,这一事实重申了这一信念。
但是,基于我上面发布的创建我的数据库并将角色readWrite分配给ubnt用户的脚本,我很好奇该如何为ubnt用户提供删除数据库所需的必要权限。如果我将readWrite替换为其他角色(如root和dbAdminAnyDatabase ),则命令将失败。
为了使我的ubnt用户能够删除unifi和unifi_stat数据库,我必须做些什么?或者,为了防止这种情况发生,我必须对连接字符串进行哪些更改?我有点像个数据库管理员。
延拓编辑:
我已经将ubnt用户在unifi和unifi_stat上的角色更新为dbAdmin而不是readWrite。再往前走一点。
#!/bin/bash
mongo \
--username ubnt \
--password "{{ mongodb_password }}" \
--authenticationDatabase admin \
--eval 'db.createUser({user: "ubnt", pwd: "{{ mongodb_password }}", roles: [{role: "dbAdmin", db: "unifi"}]})'
mongo \
--username ubnt \
--password "{{ mongodb_password }}" \
--authenticationDatabase admin \
--eval 'db.createUser({user: "ubnt", pwd: "{{ mongodb_password }}", roles: [{role: "dbAdmin", db: "unifi_stat"}]})'然而,Unifi控制器的行为仍然很奇怪。它现在只是简单地在日志文件中循环:
2019-02-10 22:33:45,449] <launcher> INFO system - ======================================================================
[2019-02-10 22:33:45,450] <launcher> INFO system - UniFi 5.6.40 (build atag_5.6.40_10370 - release) is started
[2019-02-10 22:33:45,450] <launcher> INFO system - ======================================================================
[2019-02-10 22:33:45,457] <launcher> INFO system - BASE dir:/usr/lib/unifi
[2019-02-10 22:33:45,464] <launcher> INFO system - Current System IP: 192.168.0.1
[2019-02-10 22:33:45,465] <launcher> INFO system - Hostname: unifi-controller-5bb95c7688-bzp4z
[2019-02-10 22:33:48,635] <launcher> INFO db - waiting for db connection...
[2019-02-10 22:33:49,173] <launcher> INFO db - Connecting to mongodb://ubnt:PASSWORD@unifi-controller-mongodb:27017/unifi
[2019-02-10 22:33:49,526] <launcher> DEBUG db - db connected (3.4.19@unifi-controller-mongodb:27017)
[2019-02-10 22:33:49,534] <launcher> INFO db - *** Factory Default *** Database exists. Drop it
[2019-02-10 22:33:52,391] <launcher> INFO db - waiting for db connection...
[2019-02-10 22:33:52,896] <launcher> DEBUG db - db connected (3.4.19@unifi-controller-mongodb:27017)
[2019-02-10 22:34:13,292] <launcher> INFO system - ======================================================================
[2019-02-10 22:34:13,295] <launcher> INFO system - UniFi 5.6.40 (build atag_5.6.40_10370 - release) is started
[2019-02-10 22:34:13,295] <launcher> INFO system - ======================================================================
[2019-02-10 22:34:13,303] <launcher> INFO system - BASE dir:/usr/lib/unifi
[2019-02-10 22:34:13,312] <launcher> INFO system - Current System IP: 192.168.0.1
[2019-02-10 22:34:13,313] <launcher> INFO system - Hostname: unifi-controller-5bb95c7688-bzp4z
[2019-02-10 22:34:16,781] <launcher> INFO db - waiting for db connection...
[2019-02-10 22:34:17,300] <launcher> INFO db - Connecting to mongodb://ubnt:PASSWORD@unifi-controller-mongodb:27017/unifi
[2019-02-10 22:34:17,640] <launcher> DEBUG db - db connected (3.4.19@unifi-controller-mongodb:27017)
[2019-02-10 22:34:17,656] <launcher> INFO db - *** Factory Default *** Database exists. Drop it
[2019-02-10 22:34:20,463] <launcher> INFO db - waiting for db connection...
[2019-02-10 22:34:20,969] <launcher> DEBUG db - db connected (3.4.19@unifi-controller-mongodb:27017)所以我在这里不知所措。不知道它为什么要删除数据库?Unifi是否试图从零开始在MongoDB实例上创建数据库?
unifi和unifi_stat数据库的时候创建MongoDB数据库,那么Unifi就无法连接到它们,日志就会停滞在那里。ubnt用户dbAdmin,那么Unifi似乎只是一次又一次地将它们丢弃。如上所示。ubnt用户的readWrite分配给它们,那么Unifi只会连接到数据库,创建集合,并在没有明显原因的情况下静默停止。如果我尝试手动执行上面提到的jar文件,那么它将留下堆栈跟踪,描述删除数据库所需的权限不足。如果有人能提供一些关于如何准备外部MongoDB数据库以便Unifi使用的文档,这将对我非常有益。我只找到了一个论坛帖子,一个雇员讨论了如何将控制器的system.properties配置为指向外部实例。
发布于 2019-02-11 03:22:10
结果发现,这是MetalLB中的一个bug,我用该服务向我的网络公开了我的裸金属kubernetes服务。
https://github.com/google/metallb/issues/399
现在一切都正常了。但不幸的是,分散化MongoDB对解决多个副本带来的问题没有多大帮助。
但是,我仍然认为容器中有些地方不对劲,因为它报告说service unifi status是unifi is not running。尽管它实际上在运行。
https://stackoverflow.com/questions/54620708
复制相似问题