官术网_书友最值得收藏!

Getting ready

The following are the initial setup verification steps to be taken before the recipe can be executed:

  1. Create or select a GCP project.
  2. Enable billing and enable the default APIs (some APIs such as BigQuery, storage, monitoring, and a few others are enabled automatically).
  3. Verify that Google Cloud SDK is installed on your development machine.
  4. Verify that the default project is set properly:
$ gcloud config list 
  1. The VM which runs MongoDB from our first recipe allows connections only from the localhost. We'll have to modify the configuration to allow connections from the external world.
  2. SSH into the VM from the Console:
  1. Navigate to the MongoDB's configuration file, /etc/mongod.conf, and update the bindIp value to include 0.0.0.0:
   # network interfaces
    net:
      port: 27017
      bindIp: [127.0.0.1,0.0.0.0] 
In a few versions of Mongo, it is just enough to comment our the bind_ip line in the mongodb config to allow access from outside the instance.
  1. Reboot the machine and verify that the MongoDB service is up and running.
  2. We'll also create a new firewall rule to allow access to port 27017 from anywhere:
$ gcloud compute firewall-rules \
create default-allow-mongo-27017 \ --allow tcp:27017 \ --source-ranges 0.0.0.0/0 \ --target-tags mysite-server \ --description "Allow port 27017 access to mysite-server"

The following screenshot shows the details of the firewall rule:

The MongoDB instance is now open to the world without any login credentials. So for production systems, make sure you secure the MongoDB instance with an admin user and run the mongod process using the --auth option.

  1. Connect to the MongoDB instance running on the VM from your development machine:
$ mongo mongodb://<External IP>:27017
主站蜘蛛池模板: 贡嘎县| 东方市| 留坝县| 承德市| 盐城市| 湘西| 甘孜| 叶城县| 竹溪县| 福州市| 鄂伦春自治旗| 都昌县| 龙江县| 洛川县| 湖口县| 巴塘县| 万安县| 荥经县| 牙克石市| 宣武区| 呈贡县| 洪洞县| 安义县| 天峨县| 徐汇区| 仁化县| 赣榆县| 德庆县| 新民市| 兴山县| 仁寿县| 青海省| 文水县| 兴隆县| 望江县| 汪清县| 徐闻县| 莫力| 兴化市| 会泽县| 邯郸市|