【问题标题】:Connect mongo db replica set from other server Node js从另一个服务器节点 js 连接 mongodb 副本集
【发布时间】:2021-07-29 10:30:21
【问题描述】:

我有三台服务器的负载平衡,1 是主服务器通过隧道 ssh 使用猫鼬将数据从服务器 2 和 3 存储到数据库中,目前我只有一个端口,比如说 1900,但我想增加副本成员 3 或更多,任何人知道怎么做吗?

抱歉,英文可能不正确,谢谢

const config = {
 username: 'root',
 host: '128.199.xx.xx',
 port: 22,
 agent: 345,
 dstPort: 1900,
 password: 'xxx'
 };
 tunnel(config, function (error, server) {
    mongoose
    .connect("mongodb://localhost:1900/db_name", {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      useFindAndModify: false,
      useCreateIndex: true,
      replicaSet: "rs",
    })
    .then(() => {
      console.log("MongoDB Connected");
    })
   });

【问题讨论】:

    标签: node.js mongodb


    【解决方案1】:

    我通过将主机添加到源机解决了非常感谢。我们不再需要任何 ssh 隧道了

    1.允许您的本地 IP 访问您的服务器

    ufw allow from xx.xx.xx.xx to any port xxxx (database port)
    

    可选:将 IP 添加到本地计算机中的主机文件

    为了更好的安全性,请添加用户名和密码以访问数据库

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多