- MongoDB Administrator’s Guide
- Cyrus Dasadia
- 190字
- 2021-07-02 15:47:43
How to do it..
- First, let us generate a self-signed certificate using OpenSSL, in the /data directory:
openssl req -x509 -newkey rsa:4096 -nodes -keyout mongo-secure.key -out mongo-secure.crt -days 365
- Combine the key and certificate into a single .pem file:
cat mongo-secure.key mongo-secure.crt > mongo-secure.pem
- Start the mongod daemon, with SSL enabled and listening on the default socket that is, localhost 27017:
mongod --dbpath /data/db --sslMode requireSSL --sslPEMKeyFile /data/mongo-secure.pem
- In another window, connect to this server using a mongo client:
mongo localhost:27017
- You should see a connect failed error on the client Terminal. Switch to the server's console window and you should see a log message indicating that the connection was rejected, something like this:
2017-05-13T16:51:08.031+0000 I NETWORK [thread1] connection accepted from 192.168.200.200:43441 #4 (1 connection now open)
2017-05-13T16:51:08.032+0000 I - [conn4] AssertionException handling request, closing client connection: 17189 The server is configured to only allow SSL connections
2017-05-13T16:51:08.032+0000 I - [conn4] end connection 192.168.200.200:43441 (1 connection now open)
- Now, switch back to the other console window and connect to the server again but this time using SSL:
mongo --ssl --sslAllowInvalidCertificates
- You should be connected to the server and see the mongo shell.
推薦閱讀
- Flask Blueprints
- Power Up Your PowToon Studio Project
- Learn Swift by Building Applications
- Python編程完全入門教程
- WordPress Plugin Development Cookbook(Second Edition)
- SharePoint Development with the SharePoint Framework
- Yocto for Raspberry Pi
- Haxe Game Development Essentials
- Mastering Xamarin.Forms(Second Edition)
- Building Wireless Sensor Networks Using Arduino
- Access 2010中文版項(xiàng)目教程
- 深度學(xué)習(xí)原理與PyTorch實(shí)戰(zhàn)(第2版)
- PrimeFaces Blueprints
- Building Dynamics CRM 2015 Dashboards with Power BI
- 零基礎(chǔ)輕松學(xué)C++:青少年趣味編程(全彩版)