CentOs6.x安装mongodb3.4.x

一、系统及安装说明

系统:CentOS6.x_x64,mongodb-3.4.10。mongodb官方下载地址 https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.10.tgz。本次安装选择编辑yum安装。

二、配置官方yum库

1>创建yum安装库文件

#vim /etc/yum.repos.d/mongodb-org-3.4.repo    #创建之后可以直接使用yum安装
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

当设置gpgcheck=0时,gpgkey路径可以不设置

2>yum安装

#yum install -y mongodb-org
#当出现以下即为安装中
updates/primary_db                                                                                                                                                                                                                            | 5.3 MB     00:01     
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:3.4.10-1.el6 will be installed
--> Processing Dependency: mongodb-org-tools = 3.4.10 for package: mongodb-org-3.4.10-1.el6.x86_64
--> Processing Dependency: mongodb-org-shell = 3.4.10 for package: mongodb-org-3.4.10-1.el6.x86_64
--> Processing Dependency: mongodb-org-server = 3.4.10 for package: mongodb-org-3.4.10-1.el6.x86_64
--> Processing Dependency: mongodb-org-mongos = 3.4.10 for package: mongodb-org-3.4.10-1.el6.x86_64
--> Running transaction check
---> Package mongodb-org-mongos.x86_64 0:3.4.10-1.el6 will be installed
---> Package mongodb-org-server.x86_64 0:3.4.10-1.el6 will be installed
---> Package mongodb-org-shell.x86_64 0:3.4.10-1.el6 will be installed
---> Package mongodb-org-tools.x86_64 0:3.4.10-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================================================================================================================
 Package                                                             Arch                                                    Version                                                          Repository                                                        Size
=====================================================================================================================================================================================================================================================================
Installing:
 mongodb-org                                                         x86_64                                                  3.4.10-1.el6                                                     mongodb-org-3.4                                                  5.8 k
Installing for dependencies:
 mongodb-org-mongos                                                  x86_64                                                  3.4.10-1.el6                                                     mongodb-org-3.4                                                   12 M
 mongodb-org-server                                                  x86_64                                                  3.4.10-1.el6                                                     mongodb-org-3.4                                                   20 M
 mongodb-org-shell                                                   x86_64                                                  3.4.10-1.el6                                                     mongodb-org-3.4                                                   11 M
 mongodb-org-tools                                                   x86_64                                                  3.4.10-1.el6                                                     mongodb-org-3.4                                                   49 M

Transaction Summary
=====================================================================================================================================================================================================================================================================
Install       5 Package(s)

Total size: 91 M
Total download size: 69 M
Installed size: 258 M
Downloading Packages:
(1/2): mongodb-org-server-3.4.10-1.el6.x86_64.rpm                                                                                                                                                                                             |  20 MB     00:03     
(2/2): mongodb-org-tools-3.4.10-1.el6.x86_64.rpm                                                                                                                                                                                              |  49 MB     00:15     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                3.4 MB/s |  69 MB     00:19

三、自定义安装配置

1>安装成功后,数据和日志目录默认是在 /var/lib/mongo 和 /var/log/mongodb,为方便管理我们可进行自定义。以 /data/mongodb  为例

2>编辑/etc/mongod.conf

#vim /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: /data/mongodb/log/mongod.log

# Where and how to store data.
storage:
  dbPath: /data/mongodb/data
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp

3>创建目录

#mkdir -p /data/mongodb/data
#mkdir -p /data/mongodb/log
#chown   mongod.mongod /data/mongodb -R   #修改权限,否则mongo有可能启动不了

四、启动并测试

1>启动mongod

#service mongod start|stop|restart

2>添加到开机启动项

#chkconfig --add mongod
#chkconfig mongod on

3>登录测试

#mongo --host 127.0.0.1

MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.4.10
Server has startup warnings: 
2017-12-06T10:41:30.462+0800 I STORAGE  [initandlisten] 
2017-12-06T10:41:30.462+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-12-06T10:41:30.462+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-12-06T10:41:30.901+0800 I CONTROL  [initandlisten] 
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] 
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] 
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] 
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] 
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
2017-12-06T10:41:30.902+0800 I CONTROL  [initandlisten] 
> show dbs
admin  0.000GB
local  0.000GB
>

五、问题排错

1> 登录mongodb数据库时,如果出现以下错误

MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Server has startup warnings: 
2017-12-06T10:46:46.575+0800 I STORAGE  [initandlisten] 
2017-12-06T10:46:46.575+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-12-06T10:46:46.575+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-12-06T10:46:46.955+0800 I CONTROL  [initandlisten] 
2017-12-06T10:46:46.955+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-06T10:46:46.955+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-12-06T10:46:46.955+0800 I CONTROL  [initandlisten] 
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] 
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] 
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] 
2017-12-06T10:46:46.956+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.

环境不通解决办法也不通,详情请参照官方文档 https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/

2>创建脚本

# vim  /etc/init.d/disable-transparent-hugepages

#!/bin/bash### BEGIN INIT INFO
# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.
### END INIT INFO
case $1 in
  start)
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/transparent_hugepage    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/redhat_transparent_hugepage    else
      return 0
    fi

    echo 'never' > ${thp_path}/enabled    echo 'never' > ${thp_path}/defrag    re='^[0-1]+$'
    if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
    then
      # RHEL 7
      echo 0  > ${thp_path}/khugepaged/defrag    else
      # RHEL 6
      echo 'no' > ${thp_path}/khugepaged/defrag    fi

    unset re    unset thp_path    ;;
    esac

添加到开机服务

#chmod +x /etc/init.d/disable-transparent-hugepages
#chkconfig --add disable-transparent-hugepages

3>创建编辑 /etc/tune-profiles/no-thp/ktune.sh

#vim  /etc/tune-profiles/no-thp/ktune.sh

#echo "set_transparent_hugepages never" > ktune.sh
#chmod +x ktune.sh
#tuned-adm profile no-thp 
#如果提示找不到命令请执行yum install tuned -y

#vim /etc/security/limits.conf

添加

mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000

重启系统 sudo reboot

时间: 2024-08-12 02:26:53

CentOs6.x安装mongodb3.4.x的相关文章

CentOS6.8安装mongodb3.0并添加到系统服务

一.系统环境CentOS 6.8_x64官方参考文档https://docs.mongodb.org/manual/reference/glossary/#term-init-script 二.添加官方yum库#cd /etc/yum.repo.d/#vim  mongodb.repo [mongodb-org-3.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-

如何在CentOS6上安装Python2.7和Python3.3

原文来自http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/,个人觉得对在linux安装新版本Python是很有参考意义,因而转载,原文是英文的,本人简单翻译下,大家看懂即可,有不妥的地方请留言. 如何在CentOS 6上同时安装Python 2.7和Python 3.3 本文将介绍如何在CentOS 6上安装Python 2.7和3.3.下面以Python 2.7.6和Python 3.3.5为例进行说明,但本人实

centos6.5安装docker

centos6.5 安装docker 防伪码:吃的苦中苦,方为人上人! 前言:在当今的主流社会中,docker和openstatick是一大主流方向,下面为大家讲解理论知识和实际操作现实中的docker! 理论知识: 相信大家都知道docker是什么?那在这里就不多说了! Docker 基于 Go 语言开发,代码托管在Github上,并遵循Apache 2.0 开源协议. docker的专业叫法是应用容器(Application Container). 为什么要使用docker? 1 .快速交付

CentOS6.5 安装+ Tengine + PHP + MySQL

centos6.5安装+Tengine+php+mysql

Centos6.4 安装fail2ban防暴力破解

Centos6.4 安装fail2ban防暴力破解 一. 安装 curl -O https://codeload.github.com/fail2ban/fail2ban/tar.gz/0.9.0 mv 0.9.0 0.9.0.tar.gz tar zxvf 0.9.0.tar.gz cd fail2ban-0.9.0/ python setup.py build python setup.py install 二.配置(防ssh暴力) vi /etc/fail2ban/jail.conf [s

CentOS-6.5安装配置JDK-7

安装说明 系统环境:centos-6.5 安装方式:rpm安装 软件:jdk-7-linux-x64.rpm 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html 注:rpm,gz文件区别 初接解Linux的朋友一定对软件的安装特别头疼,同样都是for Linux,但RPM.tar.gz.DEB包还是有很大区别的,这种区别很有可能使你的安装过程进行不下去.那我

centos6.5安装和配置cobbler

Cobbler介绍 Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装.重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows.该工具使用python开发,小巧轻便(才15k行代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理 DHCP,DNS,以及yum包镜像. Cobbler 使用命令行方式管理,也提供了基于 Web 的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发

CentOS6.4安装python2.7.3环境和Tornado

Centos6.4默认的python环境是2.6.6.我们可以自己安装Python 2.7.3. 但是值得注意的是,我们必须不能破坏系统的环境. 因为几个关键的实用应用程序依赖于Python2.6.6. 如果替换了系统的python环境就会发生很多难以预见的错误,导致要重装系统. 在没有破坏系统的python环境的情况下安装Python 2.7.3. 执行以下命令,请使 用root的身份登录或者使用sudo命令 一.安装Python 2.7.3 1. 安装开发工具 为了编辑Python,你必须要

CentOS6.5安装Cacti统计图乱码解决

这个就是rrdtool调用字体失败 安装字体即可 [[email protected] -]# yum -y install  cjkuni-ukai-fonts #安装字体 [[email protected] -]# fc-cache -f -v #刷新字体哦缓存 CentOS6.5安装Cacti统计图乱码解决,布布扣,bubuko.com