无法在AWS Ubuntu上运行Mongod作为服务



我在Linux上部署Mongo时遇到了问题,在AWS上运行。

vim /etc/yum.repos.d/mongodb-org-3.0.repo
sudo yum install -y mongodb-org
Error: Package: mongodb-org-tools-3.0.12-1.amzn1.x86_64 (Mongodb-org-3.0)
       Requires: libgcc_s.so.1(GCC_3.0)(64bit)
Error: Package: mongodb-org-mongos-3.0.12-1.amzn1.x86_64 (Mongodb-org-3.0)
       Requires: /bin/bash
Error: Package: mongodb-org-server-3.0.12-1.amzn1.x86_64 (Mongodb-org-3.0)
       Requires: openssl

因此,我使用

下载了MongoDB和UNTAR的TAR文件
tar -xvzf mongodb-linux-x86_64-amazon-3.2.7.tgz 

当我进入bin目录并使用mongod或mongo命令时,它起作用,但是尝试用作服务时,它会产生错误。

    cd mongodb-linux-x86_64-amazon-3.2.7/bin
    root@ip-172-31-43-40:/mongodb-linux-x86_64-amazon-3.2.7/bin# service mongod start
    mongod: unrecognized service
    root@ip-172-31-43-40:/mongodb-linux-x86_64-amazon-3.2.7/bin#export PATH=$PATH:/mongodb-linux-x86_64-ubuntu1404-3.2.7/bin/
    root@ip-172-31-43-40:/mongodb-linux-x86_64-ubuntu1404-3.2.7/bin# mongod
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] MongoDB starting : pid=21208 port=27017 dbpath=/data/db 64-bit host=ip-172-31-43-40
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] db version v3.2.7
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] modules: none
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] build environment:
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten]     distmod: ubuntu1404
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten]     distarch: x86_64
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2016-06-25T10:30:48.591+0000 I CONTROL  [initandlisten] options: {}
2016-06-25T10:30:48.614+0000 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-06-25T10:30:48.614+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
2016-06-25T10:30:48.988+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2016-06-25T10:30:48.988+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
2016-06-25T10:30:48.988+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-06-25T10:31:30.997+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:56229 #1 (1 connection now open)

在其他终端/控制台中

root@ip-172-31-43-40:/mongodb-linux-x86_64-ubuntu1404-3.2.7/bin# mongoMongoDB shell version: 3.2.7
connecting to: test
Server has startup warnings: 
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-25T10:30:48.987+0000 I CONTROL  [initandlisten] 
> 

无法运行Mongod作为服务...因此,想知道启动守护程序所需的步骤,并保持连续运行(如服务)

看起来好像PID文件夹和文件权限不适用于默认守护程序。

最简单的解决方案是通过将#放在配置文件中的行前方来禁用PID文件。

vi /etc/mongod.conf

找到pidfilepath =/var/run/mongodb/mongod.pid的行,并相应地更改。

# pidfilepath=/var/run/mongodb/mongod.pid

有关评论哪些评论的信息,请在此处检查。http://docs.mongodb.org/manual/reference/configuration-options/#processmanagement.pidfilepath

最新更新