approach to migrate mongodb using mongomirror using 2 GCE only - mongodb

approach to migrate mongodb using mongomirror: Setting up mongodb instace on GCE and then migrate to another on GCE only
setting up 2 GCE on same project
Installed mongodb on both GCE
Installed mongomirror on source vm1
Tried exeuting mongomirror command on source GCE using username and pwd
./mongomirror --host rsMigration/SOURCE_IP --username root --password root123 --destination DESTINATION_IP:27017 --destinationUsername admin --destinationPassword admin123
Output:
mongomirror version: 0.12.2
git version: 9b30f320e44f90afec5c0fa792d4c003b71ead6b
Go version: go1.16.7
os: linux
arch: amd64
compiler: gc
2021-10-27T07:57:03.252+0000 Error initializing mongomirror: could not initialize source connection: could not connect to server: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: 27017:27017, Type: Unknown, Last error: connection() error occured during connection handshake: dial tcp 0.0.105.137:27017: i/o timeout }, ] }

Related

Can't connect to MongoDB running in docker container

I run MongoDB in a docker container like this
docker run --name mongo -d -p 27017:27107 mongo
Check with docker ps shows
77f1a11295c3 mongo "docker-entrypoint.s…" 20 minutes ago Up 20 minutes 27017/tcp, 0.0.0.0:27017->27107/tcp mongo
so it's running with the port mapped correctly.
When I try to setup a connection via Intellij
it fails with
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Exception receiving message}, caused by {java.net.SocketException: Connection reset}}].
When I try to connect to connect from a golang web server
clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
client, err := mongo.Connect(context.TODO(), clientOptions)
I get this error and it shuts down the web server:
server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: connection(localhost:27017[-64]) incomplete read of message header: read tcp 127.0.0.1:40700->127.0.0.1:27017: read: connection reset by peer }, ] }
Is this a bug in the MongoDB docker image, or is there something else I need to do?
I think you have a typo mistake while creating a container. 27017 and 27107
docker run --name mongo -d -p 27017:27017 mongo
This is clearly visible in docker ps command.
Can you try and see if it solves the problem ?
As #fly2matrix said you have a typo, and I believe you have another issue:
you forward the ports 27017:27107, in which the container port is incorrect. Check 27107 instead of 27017
It seems you're connecting to localhost instead of mongo as I see the phrase localhost in your code.

mongos Socket operation timed out

I've got a mongos router running on amazon ECS in an EC2 machine, and also hosted on a route53 hosted zone.
The thing is that I can reach the mongos service via HTTP with the record name:
https://mongos-router.awsqa.xxx.net/
With the response:
It looks like you are trying to access MongoDB over HTTP on the native
driver port.
Which means that mongos is running correctly.
The ecs logs I get shows its running correctly also.
But trying to connect to it via mongo command:
$ mongo --host mongos-router.awsqa.xxx.net
MongoDB shell version v4.4.4
connecting to: mongodb://mongos-router.awsqa.xxx.net:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server mongos-router.awsqa.xxx.net:27017, connection attempt failed: NetworkTimeout: Error connecting to mongos-router.awsqa.xxx.net:27017 (xx.xxx.xx.xx:27017) :: caused by :: Socket operation timed out :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
I've confirmed that the container port is correct also:
"portMappings": [
{
"hostPort": 0,
"protocol": "tcp",
"containerPort": 27017
}
],
a part of mongos.conf file:
net:
bindIp: 0.0.0.0
port: 27017
Dockerfile final command:
CMD [ "mongos", "--config", "/etc/mongos.conf" ]
Any idea at all to what is causing this network timeout error will be helpful

Error when Adding postgresql user named odoo in remote node(docker containner) with ansible

I'm working to add postgresql user named odoo in remote node (docker container) with ansible knowing that I'm trying to follow the manual installation:
$sudo apt-get install postgresql-9.6
$sudo su postgres
$cd
$createuser -s odoo
and this is my code
- name: Instalation of postgresql-9.6 server
apt:
name: postgresql-9.6
state: latest
- name: Ensure the PostgreSQL service is running
service: name=postgresql state=started enabled=yes
- name: Create odoo user
become_user: postgres
postgresql_user:
state: present
login_user: postgres
name: odoo
password: odoo
role_attr_flags: "SUPERUSER,CREATEDB"
priv: "CONNECT/products:ALL"
after running i faced this error
PLAY [My Odoo] ***************************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************
ok: [172.17.0.5]
TASK [Postgresql : Instalation of postgresql-9.6 server] *********************************************************************************************
ok: [172.17.0.5]
TASK [Postgresql : Ensure the PostgreSQL service is running] *****************************************************************************************
ok: [172.17.0.5]
TASK [Postgresql : Create odoo user] *****************************************************************************************************************
fatal: [172.17.0.5]: FAILED! => {"changed": false, "msg": "privileges require a database to be specified"}
to retry, use: --limit #/home/fedora/Desktop/ansible-test/playbook.retry
PLAY RECAP *******************************************************************************************************************************************
172.17.0.5 : ok=3 changed=0 unreachable=0 failed=1
Can you help me resolving this?
You've specified a priv option, but haven't specified a database, which should be affected by your config. In your specific case, since you just want to create a user you should omit priv: to have something like
- name: Create odoo user
become_user: postgres
postgresql_user:
state: present
login_user: postgres
name: odoo
password: odoo
role_attr_flags: "SUPERUSER,CREATEDB"

Couldn't connect to server apollo.modulusmongo.net

I'm trying to connect MongoDB database on modulus.io by referencing [this][1] tutorial.
I've registered with modules .io and received the database url. (Modulus provides the database URL you need and you can use mongoose.connect to connect to it)
i.e.
MONGO URI
mongodb://<user>:<pass>#apollo.modulusmongo.net:27017/wIp4otyd
MONGO CONSOLE
mongo apollo.modulusmongo.net:27017/wIp4otyd -u <user> -p <pass>
But when I'm trying to connect it through both node.js and console its showing me following error:
C:\mongodb\bin>mongo apollo.modulusmongo.net:27017/wIp4otyd -u <my_uname> -p <my_pwd>
2016-02-04T12:01:07.097+0530 I CONTROL [main] Hotfix KB2731284 or later update is installed, no need to zero-out data files
MongoDB shell version: 3.2.1
connecting to: apollo.modulusmongo.net:27017/wIp4otyd
2016-02-04T12:01:09.455+0530 W NETWORK [thread1] Failed to connect to 52.6.181.208:27017, reason: errno:10061 No connection could be made because the target ma
chine actively refused it.
2016-02-04T12:01:09.457+0530 E QUERY [thread1] Error: couldn't connect to server apollo.modulusmongo.net:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
Its connecting to local perfectly (mongoose.connect('mongodb://localhost/news');)
but refusing to modulus.io (mongoose.connect('mongodb://<my_uname>:<my_pwd>#apollo.modulusmongo.net:27017/wIp4otyd');)

how do I create a collection in mongoDB using an Ansible playbook?

I'm using Ansible to configure a Vagrant VM that, on vagrant up, starts mongoDB and creates a database and collection ready to receive data. Another process will write data to the mongoDB collection. Here's a snippet from the playbook:
- hosts: all
user: vagrant
sudo: True
tasks:
- name: install packages
action: apt update_cache=yes pkg={{item}} state=installed
with_items:
- mongodb
- service: name=mongodb state=started
- shell: mongo mydb --eval "db.createCollection('mycollection')"
The playbook installs and starts the mongoDB service. However, it doesn't create the database/collection. There's something wrong with the "- shell: mongo ..." line. It returns:
TASK: [shell mongo mydb --eval "db.createCollection('mycollection')"] ****
failed: [default] => {"changed": true, "cmd": "mongo mydb --eval\"db.createCollection('mycollection')\" ", "delta": "0:00:00.084196", "end": "2014-08-29 04:48:40.333460", "rc": 255, "start": "2014-08-29 04:48:40.249264"}
stderr: exception: connect failed
stdout: MongoDB shell version: 2.0.4
connecting to: mydb
Fri Aug 29 04:48:40 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
Can you see what I did wrong?
Your approach should be correct. I just tested your mongo line on a vagrant booted instance with mongo installed and it worked fine.
Can you check the mongo logs to see what it is complaining about? If you can't connect, it could be that the mongo service is binding to ipv6 addr, binding to wrong port (should be 27017), or their are some authentication issues.
After checking that, can you boot the machine, get on the shell, then execute this bit:
mongo mydb --eval "db.createCollection('mycollection')"
Does it work from the shell? (run as same user as Ansible).