mongodb安装比较简单,centos可以直接用yum或rpm包安装,ubuntu或debian可以直接用apt或deb包安装。不过个人还是习惯直接下载官方源码或二进制文件安装。以下我就从官方下载安装文件安装,步骤类似如下。
1、修改主机名,添加hosts信息echo \mongodb1\ >/etc/hostnamehostname mongodb1修改添加/etc/hosts,例如:
192.168.1.106 mongodb12、创建mongo用户和数据目录useradd mongomkdir -pv /data/mongodbchown -r mongo.mongo /data/mongodbchmod go-rwx /data/mongodb3、下载安装下载的是3.2的最新版本。
mkdir /root/softbakcd /root/softbakwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.21.tgztar zxf mongodb-linux-x86_64-3.2.21.tgzmv mongodb-linux-x86_64-3.2.21 /usr/local/mongodb增加环境变量
vim /etc/profileexport path=/usr/local/mongodb/bin:$pathsource /etc/profile配置目录
mkdir /usr/local/mongodb/etcchown mongo.mongo /usr/local/mongodb/etcchmod go-rwx /usr/local/mongodb/etc4、配置启动su - rootmkdir -pv /var/log/mongodbmkdir -pv /var/run/mongodbchown -r mongo.mongo /var/log/mongodb/chown -r mongo.mongo /var/run/mongodb/关闭hugepage的动态分配,默认centos 7开启。
参考:https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/
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 755 /etc/init.d/disable-transparent-hugepageschkconfig --add disable-transparent-hugepages修改ulimit限制
参考:https://docs.mongodb.com/manual/reference/ulimit/
默认需要修改的地方是open files、nproc和lock in memory size。
vim /etc/security/limits.conf # 推荐配置如下-f (file size): unlimited-t (cpu time): unlimited-v (virtual memory): unlimited-l (locked-in-memory size): unlimited-n (open files): 64000-m (memory size): unlimited-u (processes/threads): 64000配置类似如下
su - mongocd /usr/local/mongodb/etc cat /usr/local/mongodb/etc/mongod.confsystemlog: destination: file logappend: true path: /var/log/mongodb/mongod.log storage: dbpath: /data/mongodb journal: enabled: true processmanagement: fork: true pidfilepath: /var/run/mongodb/mongod.pid replication: replsetname: rs1 net: port: 27017 bindip: 0.0.0.0启动
su - mongomongod -f /usr/local/mongodb/etc/mongod.conf连接本地mongodb
su - mongomongo
网站后台打不开请筛查下原因苹果系统为什么更新不了 苹果更新不了的解决办法域名由什么组成?购买域名时如何评判域名的价值?本周好米惊爆米市:776.com、FN.com、MB.cn相继易主网站建设需要购买哪些东西虚拟主机超期找回-虚拟主机/数据库问题租云服务器贵吗盘点近年来那些高价交易的数字域名