- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在遵循本教程(https://github.com/drginm/docker-boilerplates/tree/master/mongodb-replicaset),以便获得三个实例的mongodb副本集,以在docker-compose中工作。
这是我到目前为止已采取的步骤:
1)我已经将setup
和mongo-rs0-1
文件夹复制到了我的根目录中。
2)我已经将三个mongo实例和安装实例添加到我的docker-compose文件中。现在看起来像这样:
version: '3'
services:
mongo-rs0-1:
image: "mongo-start"
build: ./mongo-rs0-1
ports:
- "27017:27017"
volumes:
- ./mongo-rs0-1/data:/data/db
networks:
- app-network
depends_on:
- "mongo-rs0-2"
- "mongo-rs0-3"
mongo-rs0-2:
image: "mongo"
command: --replSet rs0 --smallfiles --oplogSize 128
networks:
- app-network
ports:
- "27018:27017"
volumes:
- ./mongo-rs0-2/data:/data/db
mongo-rs0-3:
image: "mongo"
command: --replSet rs0 --smallfiles --oplogSize 128
networks:
- app-network
ports:
- "27019:27017"
volumes:
- ./mongo-rs0-3/data:/data/db
setup-rs:
image: "setup-rs"
build: ./setup
networks:
- app-network
depends_on:
- "mongo-rs0-1"
nodejs:
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
container_name: nodejs
restart: unless-stopped
networks:
- app-network
depends_on:
- setup-rs
nextjs:
build:
context: ../.
dockerfile: Dockerfile
ports:
- "3000:3000"
container_name: nextjs
restart: unless-stopped
networks:
- app-network
depends_on:
- nodejs
webserver:
image: nginx:mainline-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- ./picFolder:/picFolder
- web-root:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
- certbot-var:/var/lib/letsencrypt
depends_on:
- nodejs
- nextjs
- setup-rs
networks:
- app-network
volumes:
certbot-etc:
certbot-var:
web-root:
driver: local
driver_opts:
type: none
device: /
o: bind
networks:
app-network:
driver: bridge
nginx.conf
文件,但是我已经在这里添加了它来简化:
server {
listen 80;
listen [::]:80;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com localhost;
location /socket.io {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_pass http://nodejs:8000/socket.io/;
}
location /back {
proxy_connect_timeout 75s;
proxy_read_timeout 75s;
proxy_send_timeout 75s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://nodejs:8000/back/;
}
location /staticBack{
alias /picFolder;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
location / {
proxy_pass http://nextjs:3000;
}
location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html;
}
}
'mongodb://mongo-rs0-1,mongo-rs0-2,mongo-rs0-3/test'
,如下所示(
https://github.com/drginm/docker-boilerplates/blob/master/mongodb-replicaset/web-site/database.js)
mongoose.connect("mongodb://mongo-rs0-1,mongo-rs0-2,mongo-rs0-3/test");
MongoDB connection error: { MongoError: no mongos proxy available
at Timeout.<anonymous> (/var/www/back/node_modules/mongodb-core/lib/topologies/mongos.js:757:28)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }
mongo.conf
文件(
https://github.com/drginm/docker-boilerplates/blob/master/mongodb-replicaset/mongo-rs0-1/mongo.conf)似乎表示副本集名称为
rs0
。所以现在我连接:
mongoose.connect("mongodb://mongo-rs0-1,mongo-rs0-2,mongo-rs0-3/test?replicaSet=rs0");
MongoDB connection error: { MongoError: no primary found in replicaset or invalid replica set name
at /var/www/back/node_modules/mongodb-core/lib/topologies/replset.js:636:11
at Server.<anonymous> (/var/www/back/node_modules/mongodb-core/lib/topologies/replset.js:357:9)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Server.emit (events.js:211:7)
at /var/www/back/node_modules/mongodb-core/lib/topologies/server.js:508:16
at /var/www/back/node_modules/mongodb-core/lib/connection/pool.js:532:18
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }
var options = {
native_parser: true,
auto_reconnect: false,
poolSize: 10,
connectWithNoPrimary: true,
sslValidate: false,
socketOptions: {
keepAlive: 1000,
connectTimeoutMS: 30000
}
};
mongoose.connect("mongodb://mongo-rs0-1:27017,mongo-rs0-2:27017,mongo-rs0-3:27017/test?replicaSet=rs0", options);
connectWithNoPrimary: true
似乎特别重要,因为nodejs处于竞争状态,而mongo服务从Docker启动时,它们可能尚未选择主要对象。
MongoDB connection error: { MongoError: no secondary found in replicaset or invalid replica set name
at /var/www/back/node_modules/mongodb-core/lib/topologies/replset.js:649:11
at Server.<anonymous> (/var/www/back/node_modules/mongodb-core/lib/topologies/replset.js:357:9)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Server.emit (events.js:211:7)
at /var/www/back/node_modules/mongodb-core/lib/topologies/server.js:508:16
at /var/www/back/node_modules/mongodb-core/lib/connection/pool.js:532:18
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }
connectwithnosecondary
不会执行任何操作,并且会导致相同的错误-我认为这不是有效的选择。仍然停留,任何帮助将不胜感激。
MongoError: no secondary found in replicaset or invalid replica set name
。因此,我不再认为问题是连接上的竞争条件-至少这似乎不是当前的错误。
var options = {
native_parser: true,
auto_reconnect: false,
poolSize: 10,
connectWithNoPrimary: true,
sslValidate: false
};
// mongoose.connect("mongodb://mongo-rs0-1,mongo-rs0-2,mongo-rs0-3/?replicaSet=rs0", { useNewUrlParser: true, connectWithNoPrimary: true });
const connectFunc = () => {
mongoose.connect("mongodb://mongo-rs0-1:27017,mongo-rs0-2:27017,mongo-rs0-3:27017/test?replicaSet=rs0", options);
mongoose.Promise = global.Promise;
var db = mongoose.connection;
db.on('error', (error)=>{
console.log('MongoDB connection error:', error)
console.log('now calling connectFunc() again');
connectFunc()
});
db.once('open', function() {
// we're connected!
console.log('connected to mongoose db')
});
}
connectFunc()
patientplatypus:~/Documents/patientplatypus.com/forum/back:19:47:11$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d46cfb5e1927 nginx:mainline-alpine "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp webserver
6798fe1f6093 back_nextjs "npm start" 3 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp nextjs
ab6888f703c7 back_nodejs "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:8000->8000/tcp nodejs
48131a82b34e mongo-start "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:27017->27017/tcp mongo1
312772b1b0f1 mongo "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:27019->27017/tcp mongo3
9fe9a16eb20e mongo "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:27018->27017/tcp mongo2
patientplatypus:~/Documents/patientplatypus.com/forum/back:19:48:55$docker logs 9fe9a16eb20e
2019-04-12T00:45:29.689+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-04-12T00:45:29.727+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=9fe9a16eb20e
2019-04-12T00:45:29.728+0000 I CONTROL [initandlisten] db version v4.0.8
2019-04-12T00:45:29.728+0000 I CONTROL [initandlisten] git version: 9b00696ed75f65e1ebc8d635593bed79b290cfbb
2019-04-12T00:45:29.728+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2019-04-12T00:45:29.728+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-12T00:45:29.728+0000 I CONTROL [initandlisten] modules: none
2019-04-12T00:45:29.729+0000 I CONTROL [initandlisten] build environment:
2019-04-12T00:45:29.729+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2019-04-12T00:45:29.729+0000 I CONTROL [initandlisten] distarch: x86_64
2019-04-12T00:45:29.729+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-04-12T00:45:29.729+0000 I CONTROL [initandlisten] options: { net: { bindIpAll: true }, replication: { oplogSizeMB: 128, replSet: "rs" }, storage: { mmapv1: { smallFiles: true } } }
2019-04-12T00:45:29.734+0000 W STORAGE [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2019-04-12T00:45:29.738+0000 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-04-12T00:45:29.741+0000 W STORAGE [initandlisten] Recovering data from the last clean checkpoint.
2019-04-12T00:45:29.742+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1461M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-04-12T00:45:43.165+0000 I STORAGE [initandlisten] WiredTiger message [1555029943:165420][1:0x7f7051ca9a40], txn-recover: Main recovery loop: starting at 7/4608 to 8/256
2019-04-12T00:45:43.214+0000 I STORAGE [initandlisten] WiredTiger message [1555029943:214706][1:0x7f7051ca9a40], txn-recover: Recovering log 7 through 8
2019-04-12T00:45:43.787+0000 I STORAGE [initandlisten] WiredTiger message [1555029943:787329][1:0x7f7051ca9a40], txn-recover: Recovering log 8 through 8
2019-04-12T00:45:43.849+0000 I STORAGE [initandlisten] WiredTiger message [1555029943:849811][1:0x7f7051ca9a40], txn-recover: Set global recovery timestamp: 0
2019-04-12T00:45:43.892+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-04-12T00:45:43.972+0000 W STORAGE [initandlisten] Detected configuration for non-active storage engine mmapv1 when current storage engine is wiredTiger
2019-04-12T00:45:43.972+0000 I CONTROL [initandlisten]
2019-04-12T00:45:43.972+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-04-12T00:45:43.972+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-04-12T00:45:43.973+0000 I CONTROL [initandlisten]
2019-04-12T00:45:44.035+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-04-12T00:45:44.054+0000 I REPL [initandlisten] Did not find local voted for document at startup.
2019-04-12T00:45:44.064+0000 I REPL [initandlisten] Rollback ID is 1
2019-04-12T00:45:44.064+0000 I REPL [initandlisten] Did not find local replica set configuration document at startup; NoMatchingDocument: Did not find replica set configuration document in local.system.replset
2019-04-12T00:45:44.065+0000 I CONTROL [LogicalSessionCacheRefresh] Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured
2019-04-12T00:45:44.065+0000 I NETWORK [initandlisten] waiting for connections on port 27017
2019-04-12T00:45:44.069+0000 I CONTROL [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist
2019-04-12T00:45:45.080+0000 I FTDC [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
Did not find local replica set configuration document at startup; NoMatchingDocument: Did not find replica set configuration document in local.system.replset
docker exec -it mongo1 mongo
,然后再使用
rs.status()
,得到以下输出:
{
"operationTime" : Timestamp(0, 0),
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94,
"codeName" : "NotYetInitialized",
"$clusterTime" : {
"clusterTime" : Timestamp(0, 0),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
2019-04-12T00:45:44.064+0000 I REPL [initandlisten] Did not find local replica set configuration document at startup; NoMatchingDocument: Did not find replica set configuration document in local.system.replset
)中的错误非常相似。有人知道它认为缺失了什么吗?
最佳答案
您需要初始化副本集才能访问它。否则,应用程序将无法连接到本地实例。
理想情况下,您需要在副本集配置(setup-rs
步骤)和下一个副本集配置之间增加一些时间,因为副本集配置所花费的时间可能比应用程序启动时间更长。
如果脚本本身有故障,请修复该脚本。
关于node.js - 连接到副本集时的“MongoError: no mongos proxy available”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55637808/
我用运行 Node node --debug app OR node --debug-brk app 它有反应 debugger listening on port 5858 Express serv
这个问题在这里已经有了答案: What is the difference between (int *i) and (int* i) in context of both C and C++? [
我有一个应用程序,它通过消息队列将数据库写入命令分派(dispatch)给工作人员(数量非常大),因此无法保证它们的接收顺序。 我有两个 Node ,例如“Account”和“Media”。在此假设的
有没有办法在调用 ts-node 时将选项传递给 Node ?我正在尝试在 Node 中使用一个实验性功能,如果它能与 ts-node 一起使用,那就太好了。 这就是我目前正在做的事情: ts-nod
我有一个容器化的Node应用程序,它在DigitalOcean服务器上运行。当我更新服务器上的应用程序时,该应用程序必须关闭一小段时间。为了能够更新应用程序并避免停机,我目前正在阅读零停机时间部署/蓝
我正在编写一个 Node.js 应用程序。我正在使用 request 和 Cheerio 加载一组 URL 并获取该网站的大量信息,现在假设我想要获取的只是标题: var urls = {"url_1
如果不弹出以下错误,我无法安装任何 Node.js 模块。错误代码引用package.json文件。如果知道为什么会发生这种情况,我们将不胜感激。 最佳答案 这些不是错误,它们只是警告。一切都应该如此
如果我运行(从我的项目目录中): supervisor javascripts/index.js 我得到:/usr/bin/env: Node :没有这样的文件或目录 如果我运行: node java
我已遵循使用 Node-Inspector 的所有步骤 但是当我打开应用程序时,我在控制台上看不到任何脚本或日志。 我的应用程序在端口 4000 上运行。我认为唯一可能发生冲突的是端口 8080 上的
我在android中使用rxjava2,有时会遇到这样的问题: Observable.fromArray( // maybe a list about photo url in SD
我目前正在使用 Node 光纤来编写同步服务器端代码。我主要通过 try-catch block 进行错误处理,但外部库或其他小部分异步代码中总是有可能发生错误。我正在考虑使用新的域功能来尝试将这些错
看起来node-debug是node-inspector周围的一个shell?分别什么时候应该使用? 最佳答案 如果您安装node-debug,您只能访问node-debug命令。 如果您安装node
我目前正在代理后面工作,该代理不允许我执行此命令的 HTTP GET 请求阶段: Node node-sass/scripts/build.js 请求阶段: gyp http GET https://
听说node js可以用在服务端。我以前用过jsp。 jsp页面内部的java代码对客户端是不可见的。如果 Node js 只是 javascript,那么它如何对客户端不可见? 最佳答案 首先,No
我正在为 Node native 插件从 node-waf 构建迁移到 node-gyp 构建系统。 node-gyp 说它支持多个目标版本,但我在使用 node-gyp 时找不到如何指定目标 Nod
给定一个 $node ,我正在尝试在以下两种输出该 $node 的方式之间做出决定。 要么 $output = theme('node', $node); 或 node_build_content($
如果package.json中的窗口A打开一个新窗口B,node-main如何访问它?这是我的代码: package.json { "main": "index.html",
我试图在我的 xml 中的特定节点 ( ) 之前插入一个注释节点。这是它的方法: function test(xmlResponse) { var parser = new DOMParse
我正在尝试做npm install wrtc使用 Node 版本 16.14.0 但这还没有完成。它在给npm error code 1所以我试图将 Node 版本更改为以前的 lts 14.19.0
当我在 Visual Studio 中运行 Node.js 应用程序时,我收到以下消息:DeprecationWarning: 'node --debug' 和 'node --debug-brk'
我是一名优秀的程序员,十分优秀!