MongoDB集群搭建及Sharding的实现思路

企鹅博客 2019年8月14日07:55:51 评论 348

MongoDB集群搭建

MongoDB的复制集群类型:

·主从模式(master/slave)

·副本集模式(replica set)

副本及模式至少3个节点(一主二从),从节点负责复制主节点的oplog到本地并且应用到本地从而实现冗余。

(·arbiter:仅参与选举,但不持有任何数据

·0优先级:可以触发选举,但是不能被选举成为主节点

·可以使用repiset来定义集群名称)

------------------------------------------------------------------

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

相关阅读

MongoDB备份与恢复 http://www.linuxidc.com/Linux/2012-07/64113.htm

CentOS编译安装MongoDB http://www.linuxidc.com/Linux/2012-02/53834.htm

CentOS 编译安装 MongoDB与mongoDB的php扩展 http://www.linuxidc.com/Linux/2012-02/53833.htm

CentOS 6 使用 yum 安装MongoDB及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htm

Ubuntu 13.04下安装MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htm

如何在MongoDB中建立新数据库和集合 http://www.linuxidc.com/Linux/2013-06/85749.htm

MongoDB入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htm

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htm

------------------------------------------------------------------

1.编译安装MongDB

准备环境:

系统:Debian 7.2 64位

mongodb:mongodb-linux-x86_64-2.4.5.tgz(官网有下)

root@namenode1:/usr/local/tools# tar xfmongodb-linux-x86_64-2.4.5.tgz

root@namenode1:/usr/local/tools# mv mongodb-linux-x86_64-2.4.5 /usr/local/
root@namenode1:/usr/local/tools# cd /usr/local/
root@namenode1:/usr/local# ln -s /usr/local/mongodb-linux-x86_64-2.4.5//usr/local/mongodb

root@namenode1:/usr/local# ll | grep mongo
lrwxrwxrwx 1 root staff 38 3
月 17 15:35 mongodb ->/usr/local/mongodb-linux-x86_64-2.4.5/
drwxr-sr-x 3 root staff 4096 3月 17 15:08 mongodb-linux-x86_64-2.4.5

#创建用户

root@namenode1:~# groupadd -r mongod
root@namenode1:~# useradd -M -r -g mongod -d /data/db -s /bin/false -c mongodmongod

#建立目录

root@namenode1:~# mkdir -p /var/log/mongo/

root@namenode1:~# mkdir -p /mongo/data
root@namenode1:~# chown mongod /mongo/data /var/log/mongo/

 

root@namenode1:~# ll /var/log/ | grep mongo

drwxr-xr-x 2mongod root 4096 Mar 17 15:25mongo
root@namenode1:~# ll /mongo/
total 4
drwxr-xr-x 2 mongod root 4096 Mar 17 15:27 data

#LC_ALL="C"加入环境变量,以防启动出错

root@namenode1:~# echo ‘export LC_ALL="C"’ >> /etc/profile

#创建配置文件(将之前rpm包安装mongodb后的配置文件拷贝过来即可)

root@namenode1:~# cat /etc/mongod.conf
# mongo.conf

#where to log
logpath=/var/log/mongo/mongod.log

logappend=true

# fork and run in background
fork = true

#port = 27017

dbpath=/mongo/data

# location of pidfile
pidfilepath = /var/run/mongodb/mongod.pid

# Disables write-ahead journaling
# nojournal = true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security. Off is currently the default
#noauth = true
#auth = true

# Verbose logging output.
#verbose = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true

# Enable db quota management
#quota = true

# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#diaglog = 0

# Ignore query hints
#nohints = true

# Disable the HTTP interface (Defaults to localhost:27018).
#nohttpinterface = true

# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting = true

# Turns off table scans. Any query that would do a table scan fails.
#notablescan = true

# Disable data file preallocation.
#noprealloc = true

# Specify .ns file size for new databases.
# nssize = <size>

# Accout token for Mongo monitoring server.
#mms-token = <token>

# Server name for Mongo monitoring server.
#mms-name = <server-name>

# Ping interval for Mongo monitoring server.
#mms-interval = <seconds>

# Replication Options

# in replicated mongo databases, specify here whether this is a slave or master
#slave = true
#source = master.example.com
# Slave only: specify a single database to replicate
#only = master.example.com
# or
#master = true
#source = slave.example.com

启动mongodb

export LC_ALL="C"

root@namenode2:/usr/local/mongodb/bin# mongod -f /etc/mongod.conf

 

2.安装Rockmongo

RockMongo 是一个PHP5写的MongoDB管理工具。主要特征:使用宽松的New BSD License协议,速度快,安装简单,与mysql的phpmyadmin相似

root@namenode1:~# apt-get install apache2 php5 php5-dev php5-cli

root@namenode1:/etc/apache2# cd /var/www/
root@namenode1:/var/www# wgethttp://rock-php.googlecode.com/files/rockmongo-v1.0.11.zip
root@namenode1:/var/www# unzip rockmongo-v1.0.11.zip

#二次编译php模块

root@namenode1:/var/www/mongo-php-driver-master# phpize
root@namenode1:/var/www/mongo-php-driver-master# ./configure
root@namenode1:/var/www/mongo-php-driver-master# make && makeinstall

#找到php模块所在路径

root@namenode1:/var/www/mongo-php-driver-master# php -i | grepextension_dir

extension_dir => /usr/lib/php5/20100525 => /usr/lib/php5/20100525
root@namenode1:/var/www/mongo-php-driver-master# ll /usr/lib/php5/20100525

total 2084
-rwxr-xr-x 1 root root 2016810 Mar 17 16:35 mongo.so

-rw-r--r-- 1 root root 113072 Dec 12 16:53 pdo.so

#php在debian系统所安装的路径在以下的位置,如果是其他系统需根据相对路径进行查找

root@namenode1:/var/www/mongo-php-driver-master# ll/etc/php5/apache2/php.ini

-rw-r--r-- 1 root root 65755 Dec 12 16:53 /etc/php5/apache2/php.ini

root@namenode1:/var/www/mongo-php-driver-master# vi/etc/php5/apache2/php.ini

在733行加入内容,并保存退出

733 extension = mongo.so

 

重启apache并查看url是否生效

root@namenode1:/etc/init.d/apache restart

访问以下地址

http://172.23.214.50/rockmongo/index.php?action=index.login

可以看到如下图所示,已经可以正常显示mongodb的管理登陆界面,默认情况下用户名与密码默认都为admin

 

weinxin
欢迎加入中国SEO站长博客之家
本站的所有资源都会上传分享到博客之家,希望大家互相学习交流进步。
企鹅博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: