DDNS & TLS/SSL for MongoDB

更新於 2022/08/31閱讀時間約 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.

    avatar-img
    9會員
    49內容數
    比起詳細教學單一技能,網路上或者市面上整合多項技能的教學相對少很多,但要真的完成一項專案往往不是只靠一項技能便能做到。 而且教科書式的完整教學也比較枯燥乏味,因此我想以自身的經驗為例,以全端開發各項技能中最常用到的部分進行講解,讓讀者能夠快速上手掌握全端技能。
    留言0
    查看全部
    avatar-img
    發表第一個留言支持創作者!
    你可能也想看
    Google News 追蹤
    Thumbnail
    *合作聲明與警語: 本文係由國泰世華銀行邀稿。 證券服務係由國泰世華銀行辦理共同行銷證券經紀開戶業務,定期定額(股)服務由國泰綜合證券提供。   剛出社會的時候,很常在各種 Podcast 或 YouTube 甚至是在朋友間聊天,都會聽到各種市場動態、理財話題,像是:聯準會降息或是近期哪些科
    Thumbnail
    *合作聲明與警語: 本文係由國泰世華銀行邀稿。 證券服務係由國泰世華銀行辦理共同行銷證券經紀開戶業務,定期定額(股)服務由國泰綜合證券提供。   剛出社會的時候,很常在各種 Podcast 或 YouTube 甚至是在朋友間聊天,都會聽到各種市場動態、理財話題,像是:聯準會降息或是近期哪些科