1.mongodb之安装配置和启动
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了1.mongodb之安装配置和启动,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4143字,纯文字阅读大概需要6分钟。
内容图文
![1.mongodb之安装配置和启动](/upload/InfoBanner/zyjiaocheng/870/259af59ee9514427bfce3b1705326fce.jpg)
1.mongodb逻辑结构
Mongodb 逻辑结构 MySQL逻辑结构 库database 库 集合(collection) 表 文档(document) 数据行
2.安装部署
系统准备
(1)redhat或centos6.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 cat /sys/kernel/mm/transparent_hugepage/enabled cat /sys/kernel/mm/transparent_hugepage/defrag 其他系统关闭参照官方文档: https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/ --------------- 为什么要关闭? Transparent Huge Pages (THP) is a Linux memory management system that reduces the overhead of Translation Lookaside Buffer (TLB) lookups on machines with large amounts of memory by using larger memory pages. However, database workloads often perform poorly with THP, because they tend to have sparse rather than contiguous memory access patterns. You should disable THP on Linux machines to ensure best performance with MongoDB. ############################################################################
3.mongdb安装
1. 创建用户和密码
useradd mongod passwd mongod
2.创建mongdb所需要的目录结构
mkdir -p /mongodb/conf
mkdir -p /mongodb/log
mkdir -p /mongodb/data
3.上传并解压软件到指定位置
cd /data
tar -xf mongodb软件包
cp -r /mongodb/data/解压后的软件包目录/bin /mongodb/bin
4.设置目录结构和权限
chown -R mongod:mongod /mongodb
5.设置用户环境变量
su - mongd
vi .bash_profile
export PATH=/mongodb/bin:$PATH
source ./bash_profile
4. 启动mongodb
mongod --dbpath=/mongodb/data --logpath=/mongodb/log/mongodb.log --port=27017 --logappend --fork
5.登录mongodb
[mongod@server2 ~]$ mongo
6.使用配置文件
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> -- 监听地址 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: 172.17.94.206,127.0.0.1 EOF mongod -f /mongodb/conf/mongo.conf --shutdown mongod -f /mongodb/conf/mongo.conf
7.mongodb的关闭方式
mongod -f mongo.conf --shutdown
8.mongodb使用systemd管理
[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
内容总结
以上是互联网集市为您收集整理的1.mongodb之安装配置和启动全部内容,希望文章能够帮你解决1.mongodb之安装配置和启动所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。