0

when i write this command sudo service mongod start

that giving me this error Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details. i search on the stackoverflow and found it Mongodb not able to start in Ubuntu 15.04 but this doesn't work for me and this problem asked the 5 years ago and when i write the this command sudo service mongod status

giving me to

Redirecting to /bin/systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2021-07-24 22:49:47 UTC; 3min 49s ago
     Docs: https://docs.mongodb.org/manual
  Process: 4126 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=2)
  Process: 4123 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 4120 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 4119 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: Starting MongoDB Database Server...
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal mongod[4126]: Error parsing YAML config: duplicate key: replication.rep...Name
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal mongod[4126]: try '/usr/bin/mongod --help' for more information
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=2
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: Failed to start MongoDB Database Server.
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: mongod.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

and this command sudo systemctl disable mongod

giving me Removed symlink /etc/systemd/system/multi-user.target.wants/mongod.service.

and i doing the enable happen this sudo systemctl enable mongod

Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.

it's my mongod.conf file

  GNU nano 2.9.8                                                 /etc/mongod.conf                                                            

# mongod.conf# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:  port: 34418
  bindIp: 127.0.0.1,172.31.46.146  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll settin$

#security:
   #authorization: "enabled"

#operationProfiling:

replication:
  replSetName: "rs0"

#sharding:

## Enterprise-Only Options

#auditLog:
Yunus
  • 13
  • 4
  • How your /etc/mongod.conf look like? – R2D2 Jul 25 '21 at 02:40
  • i share only green content systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log storage: dbPath: /var/lib/mongo journal: enabled: true processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo net: port: 34418 bindIp: 127.0.0.1,172.31.46.146 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll settin$ security: authorization: "enabled" @R2D2 – Yunus Jul 25 '21 at 02:47
  • you need to understand in the yaml where this is comming from: duplicate key: replication – R2D2 Jul 25 '21 at 10:30
  • when i disable authorization dis problem is solve but i have to use authorization @R2D2 – Yunus Jul 26 '21 at 13:08
  • add the full conf content so we check where is the issue, but it is definetely in the yaml – R2D2 Jul 26 '21 at 15:27
  • okey but i cant add this here cause max character is full how can i send you my conf and what is the yaml? – Yunus Jul 26 '21 at 18:27
  • i added the my question you can check my conf file @R2D2 – Yunus Jul 26 '21 at 19:35

2 Answers2

0

Based on your conf file to enable simple authentication/authorization you need to do as follow:

  1. start without authorization enabled( you said it is working without authorization) binded to 127.0.0.1 only and create admin user and initialize the repicaSet if it is not initialized yet:

     mongo --port 34418
    
     db.createUser({user:"admin" ,pwd:"someStrongOne" ,roles:[{role:"root",db:"admin" }]})
    
     rs.initiate()
    
  2. Stop the mongod service

  3. Generate key file:

     mkdir /work/dbtest/key
     openssl rand -base64 756 > /work/dbtest/key
    
  4. Change permission for the keyfile to be read only by the mongod user:

     chmod 400 /work/dbtest
    
  5. Uncomment the authorization config and add the key file so it looks as follow:

    security:
     authorization: "enabled"
     keyFile: /work/dbtest/key
    
  6. Start the mongod process

  7. Now you can access as follow:

    mongo --port 34418 admin -u admin -p someStrongOne
    

btw in the pasted conf file there is some new lines that need to be added before "dbPath" and before "port" so it is valid yaml file ... , please, note proposed security configuration it is intended for testing purposes only , if you expose this service over network it is strongly recommended you add transport encryption ( X.509 etc., this is well explained in the official mongodb docs )

R2D2
  • 9,410
  • 2
  • 12
  • 28
  • Still i geting same error. at the 6 step ```Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.``` – Yunus Aug 01 '21 at 16:28
  • you can run and check the mongod process from console as follow: mongod --config xxx.conf – R2D2 Aug 01 '21 at 21:22
0

And still i geting same error and when i write this command sudo systemctl status mongod i geting this

● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2021-08-01 16:24:16 UTC; 3min 52s ago
     Docs: https://docs.mongodb.org/manual
  Process: 32109 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
  Process: 32106 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 32103 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 32101 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 13177 (code=exited, status=0/SUCCESS)

Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: Starting MongoDB Database Server...
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal mongod[32109]: about to fork child process, waiting until server is ready for connections.
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal mongod[32109]: forked process: 32112
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=1
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: Failed to start MongoDB Database Server.
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: mongod.service failed.```
Yunus
  • 13
  • 4