设为首页 收藏本站
查看: 1018|回复: 0

[经验分享] CentOs6.x安装mongodb3.4.x

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-12-7 11:24:50 | 显示全部楼层 |阅读模式
一、系统及安装说明
      系统: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安装库文件
1
2
3
4
5
6
7
#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安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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>创建目录
1
2
3
#mkdir -p /data/mongodb/data
#mkdir -p /data/mongodb/log
#chown   mongod.mongod /data/mongodb -R   #修改权限,否则mongo有可能启动不了



四、启动并测试
1>启动mongod
1
#service mongod start|stop|restart



2>添加到开机启动项
1
2
#chkconfig --add mongod
#chkconfig mongod on



3>登录测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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数据库时,如果出现以下错误
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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



添加到开机服务
1
2
#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
1
2
3
4
#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
添加
1
2
3
4
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000



重启系统 sudo reboot

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421638-1-1.html 上篇帖子: linux下安装mongodb 下篇帖子: 在centos中使用yum安装mongodb
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表