DDNS & TLS/SSL for MongoDB

閱讀時間約 3 分鐘

DNS

After you set the DNS record on your domain name registrar, change the bindIp from your IP to your domain in mongod.cfg. Then you can access your database by the domain name.

DDNS

About how to set up DDNS, you can check my previous article: https://medium.com/@xdxxxx4713/set-up-ddns-with-ddclient-google-domains-2eee300126d0.

After DDNS setting up, change the bindIp settings to bindIpAll: true .

TLS/SSL

To secure the data when the transmission, we can use TLS/SSL in MongoDB.

raw-image

obtain certificate

I use Let’s Encript to obtain the certificate. You can see the detail in this article: https://medium.com/@xdxxxx4713/lets-encrypt-in-nginx-85866b848c8e.

mongo.pem

We need to cat the private key and the fullchain file into one pem file. Let’s call it mongo.pem .

sudo cat /etc/letsencrypt/archive/’+[db_domain]+’/{fullchain1.pem,privkey1.pem} | sudo tee /etc/letsencrypt/live/’+[db_domain]+’/mongo.pem

mongod.cfg

Since TLS is more secure than SSL, let’s use TLS.

In MongoDB config file, set TLS mode and the certificate file.

auto renew mongo.pem and restart MongoDB

Due to the certificate obtained from Let’s Encript would be expired after 90 days, I write a script to auto renew mongo.pem and restart MongoDB.

client connect

To use URI connect, add ?tls=true&tlsAllowInvalidCertificate=true after your normal URL to connect MongoDB.

mongodump

To bake-up your data, you can use mongodump . Since we use TLS/SSL now, we need to add--ssl --tlsInsecure options for mongodump.

    9會員
    49Content count
    比起詳細教學單一技能,網路上或者市面上整合多項技能的教學相對少很多,但要真的完成一項專案往往不是只靠一項技能便能做到。 而且教科書式的完整教學也比較枯燥乏味,因此我想以自身的經驗為例,以全端開發各項技能中最常用到的部分進行講解,讓讀者能夠快速上手掌握全端技能。
    留言0
    查看全部
    發表第一個留言支持創作者!
    你可能也想看
    Thumbnail
    重點摘要: 1.9 月降息 2 碼、進一步暗示年內還有 50 bp 降息 2.SEP 上修失業率預期,但快速的降息速率將有助失業率觸頂 3.未來幾個月經濟數據將繼續轉弱,經濟復甦的時點或是 1Q25 季底附近
    Thumbnail
    近期的「貼文發佈流程 & 版型大更新」功能大家使用了嗎? 新版式整體視覺上「更加凸顯圖片」,為了搭配這次的更新,我們推出首次貼文策展 ❤️ 使用貼文功能並完成這次的指定任務,還有機會獲得富士即可拍,讓你的美好回憶都可以用即可拍珍藏!
    Thumbnail
    重點摘要: 1.9 月降息 2 碼、進一步暗示年內還有 50 bp 降息 2.SEP 上修失業率預期,但快速的降息速率將有助失業率觸頂 3.未來幾個月經濟數據將繼續轉弱,經濟復甦的時點或是 1Q25 季底附近
    Thumbnail
    近期的「貼文發佈流程 & 版型大更新」功能大家使用了嗎? 新版式整體視覺上「更加凸顯圖片」,為了搭配這次的更新,我們推出首次貼文策展 ❤️ 使用貼文功能並完成這次的指定任務,還有機會獲得富士即可拍,讓你的美好回憶都可以用即可拍珍藏!