NoSQL-Mongodb安装部署

一、逻辑结构
Mongodb 逻辑结构 MySQL逻辑结构
库database 库
集合(collection) 表
文档(document) 数据行

二、安装部署
1、系统准备
(1)redhat或cnetos6.2以上系统
(2)系统开发包完整
(3)ip地址和hosts文件解析正常
(4)iptables防火墙&SElinux关闭
(5)关闭大页内存机制

root用户下
永久关闭
在vi /etc/rc.local最后添加如下代码
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
临时关闭
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
修改文件描述符 vim /etc/security/limits.conf
#* - nofile 65535

2、mongodb安装
(1)创建所需用户和组
useradd mongod
passwd mongod
(2)创建mongodb所需目录结构
mkdir -p /mongodb/conf
mkdir -p /mongodb/log
mkdir -p /mongodb/data

(3)上传并解压软件到指定位置

上传到:
cd /server/tools/
解压:
tar xf mongodb-linux-x86_64-rhel70-3.2.16.tgz

拷贝目录下bin程序到/mongodb/bin
cp -a /server/tools/mongodb-linux-x86_64-rhel70-3.2.16/bin/* /mongodb/bin

(4)设置目录结构权限

chown -R mongod:mongod /mongodb

(5)设置用户环境变量

su - mongod
vi .bash_profile
export PATH=/mongodb/bin:$PATH
source .bash_profile

(6)启动mongodb
su - mongod
mongod --dbpath=/mongodb/data --logpath=/mongodb/log/mongodb.log --port=27017 --logappend --fork

(7)登录mongodb
[mongod@server2 ~]$ mongo

(8)使用配置文件
vim /mongodb/conf/mongodb.conf

logpath=/mongodb/log/mongodb.log
dbpath=/mongodb/data
port=27017
logappend=true
fork=true

关闭mongodb
mongod -f /mongodb/conf/mongodb.conf --shutdown
使用配置文件启动mongodb
mongod -f /mongodb/conf/mongodb.conf

(YAML模式:)

NOTE:
YAML does not support tab characters for indentation: use spaces instead.

----系统日志有关
systemLog:
destination: file
path: “/mongodb/log/mongodb.log” -------日志位置
logAppend: true --------------------------------日志以追加模式记录

----数据存储有关
storage:
journal:
enabled: true
dbPath: “/mongodb/data” --------------------数据路径的位置

---- 进程控制
processManagement:
fork: true ------------------------------------------后台守护进程
pidFilePath: string ------------------------------pid文件的位置,一般不用配置,可以去掉这行,自动生成到data中

----网络配置有关
net:
bindIp: ip ----------------------------------- 监听地址,如果不配置这行是监听在0.0.0.0
port: port ----------------------------------- 端口号,默认不配置端口号,是27017

---- 安全验证有关配置
security:
authorization: enabled ------------------------是否打开用户名密码验证

--------------------------------------------------以下是复制集与分片集群有关-------------------------------------------

replication:
oplogSizeMB: NUM
replSetName: REPSETNAME
secondaryIndexPrefetch: all

sharding:
clusterRole: string
archiveMovedChunks:<boolean

----for mongos only
replication:
localPingThresholdMs: int

sharding:
configDB: string

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
YAML例子
cat > /mongodb/conf/mongo.conf <<EOF
systemLog:
destination: file
path: “/mongodb/log/mongodb.log”
logAppend: true
storage:
journal:
enabled: true
dbPath: “/mongodb/data/”
processManagement:
fork: true
net:
port: 27017
bindIp: 192.168.200.51,127.0.0.1
EOF

mongod -f /mongodb/conf/mongo.conf --shutdown
mongod -f /mongodb/conf/mongo.conf

===============================================================

(9)mongodb的关闭方式
mongod -f /mongodb/conf/mongo.conf --shutdown

(10) systemd 管理(root)

[root@db01 ~]# cat > /etc/systemd/system/mongod.service <<EOF
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
User=mongod
Type=forking
ExecStart=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf --shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF

[root@db01 ~]# systemctl restart mongod
[root@db01 ~]# systemctl stop mongod
[root@db01 ~]# systemctl start mongod

猜你喜欢

转载自blog.csdn.net/qq_44788449/article/details/107029468
今日推荐