1.下载安装包
# mkdir mongodb
# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.10.tgz
-bash: wget: 未找到命令
# yum install -y wget #安装wget
# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.10.tgz
--2016-10-04 17:59:38-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.10.tgz
正在解析主机 fastdl.mongodb.org (fastdl.mongodb.org)... 54.230.73.145, 54.230.73 .80, 54.230.73.231
正在连接 fastdl.mongodb.org (fastdl.mongodb.org)|54.230.73.145|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 读取文件头错误 (Connection reset by peer)。
重试中。
--2016-10-04 18:00:11-- (尝试次数: 2) https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.10.tgz
# yum update openssl #更新openssl
# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.10.tgz
2.解压并测试运行
# tar cxvf mongodb-linux-x86_64-rhel70-3.2.10.tgz
# cd mongodb-linux-x86_64-rhel70-3.2.10
# bin/mongod
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] MongoDB starting : pid=2642 port=27017 dbpath=/data/db 64-bit host=localhost.localdomain
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] db version v3.2.10
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] allocator: tcmalloc
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] modules: none
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] build environment:
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] distmod: rhel70
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] distarch: x86_64
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] target_arch: x86_64
2016-10-04T20:21:34.217+0800 I CONTROL [initandlisten] options: {}
2016-10-04T20:21:34.238+0800 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-10-04T20:21:34.238+0800 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-10-04T20:21:38.481+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten]
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten]
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten]
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-10-04T20:21:38.482+0800 I CONTROL [initandlisten]
2016-10-04T20:21:38.486+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2016-10-04T20:21:38.487+0800 I NETWORK [initandlisten] waiting for connections on port 27017
2016-10-04T20:21:38.488+0800 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
使用robomongo测试连接状态
3.配置环境变量(可省略) 在/etc/profile中添加
export PATH=/mongodb/mongodb-linux-x86_64-rhel70-3.2.10/bin:$PATH
# source /etc/profile #刷新bash
# echo $PATH
/mongodb/mongodb-linux-x86_64-rhel70-3.2.10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
4.使用配置文件启动 新建mongod.conf,上传至/etc
port=27018 #端口号
logpath=/data/mongodb/log/mongodb.log #日志输出文件路径
logappend=true #日志输出方式
dbpath=/data/mongodb/data/db #数据库路径
# mkdir -p /data/mongodb/log/
# mkdir -p /data/mongodb/data/db
# mongod --config /etc/mongod.conf #因为配置了环境变量,可直接使用mongod,如果不配置,可执行命令bin/mongod --config /etc/mongod.conf
5.创建service启动 添加mongod.service文件,并将其上传到/usr/lib/systemd/system目录
[Unit]
Description=Mongodb nosql database
After=network.target
[Service]
ExecStart=/mongodb/mongodb-linux-x86_64-rhel70-3.2.10/bin/mongod --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
启动并配置随开机启动
# systemctl start mongod.service
# systemctl enable mongod.service
# ss -lt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:27018 *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 100 127.0.0.1:smtp *:*
LISTEN 0 128 :::ssh :::*
LISTEN 0 100 ::1:smtp :::*