Mongo 4.2.8 安装

系统环境

Redhat 7

01.修改hosts文件

[mongodb@ty1 apps]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.65.130  ty1

02.安装相关包

yum install -y cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs lm_sensors-libs net-snmp-agent-libs net-snmp openssl openssl-devel rpm-libs tcp_wrappers-libs

03.关闭防火墙与安全认证

systemctl disable firewalld

vi /etc/selinux/config

SELINUX=disabled

04.优化内核参数

echo "vm.zone_relaim_mode=0" >> /etc/sysctl.conf
sysctl -p

禁止Transparent Huge Pages(THP)

服务器重启后立即生效办法:

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

05.创建mongodb目录与用户权限

[root@ty1 soft]# mkdir -p /mongodb
[root@ty1 soft]# 
[root@ty1 soft]# mkdir -p /mongodb/{data,logs,apps}
[root@ty1 soft]# /usr/sbin/groupadd -g 10001 mongodb
[root@ty1 soft]# /usr/sbin/useradd -u 10001 -g mongodb mongodb
[root@ty1 soft]# id mongodb
uid=10001(mongodb) gid=10001(mongodb) groups=10001(mongodb)
[root@ty1 soft]# passwd mongodb
Changing password for user mongodb.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@ty1 soft]# chown -R mongodb:mongodb /mongodb
[root@ty1 soft]# chown -R 775 /mongodb


06.优化lunux读取性能,不使用atime属性

vi /etc/fstab

在mongodb的挂载点,那一行,default后面加上atime即可,如  default,noatime

然后卸载挂载点,重新挂载

挂载后然后输入mount命令,然后看输出结果中是否有noatime即可

07.修改最大连接数

vi /etc/security/limits.conf

mongodb hard nofile 25600
mongodb soft nofile 25600
mongodb hard nproc 25600
mongodb soft nproc 25600

 

08.下载安装mongodb

https://www.mongodb.com/try/download/community

su -mongodb

cd /mongodb/apps

tar zxvf mongodb-linux-x86_64-rhel70-4.2.8.tgz

ln -s /mongodb/apps/mongodb-linux-x86_64-rhel70-4.2.8 /mongodb/apps/mongodb

vi ~/.bash_profile

PATH=$PATH:$HOME/.local/bin:/mongodb/apps/mongodb/bin:$HOME/bin

source ~/.bash_profile

验证环境变量是否生效

which mongod

09.编辑配置文件

vi /mongodb/apps/mongodb/bin/mongodb.conf

dbpath=/mongodb/data
logpath=/mongodb/logs/mongodb.log
port=27017
fork=true
auth=true
#noauth=true
#verbose=true
#vvvv=true
journal=true
maxConns=500
logappend=true
directoryperdb=true
#pidfilepath=/var/run/mongo.pid
#cpu=true
#nohttpinterface=false
#notablescan=false
#profile=0
#slowms=200
#quiet=true
#syncdelay=60
bind_ip=127.0.0.1,192.168.65.130

10.启动

[mongodb@ty1 apps]$ mongod -f /mongodb/apps/mongodb/bin/mongodb.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 57768
child process started successfully, parent exiting

[mongodb@ty1 apps]$ ps -ef|grep mongo
root      57447   2539  0 09:13 pts/1    00:00:00 su - mongodb
mongodb   57448  57447  0 09:13 pts/1    00:00:00 -bash
mongodb   57768      1 23 09:24 ?        00:00:02 mongod -f /mongodb/apps/mongdb/bin/mongodb.conf
mongodb   57804  57448  0 09:24 pts/1    00:00:00 ps -ef
mongodb   57805  57448  0 09:24 pts/1    00:00:00 grep --color=auto mongo

or

mongod --config /mongodb/apps/mongodb/bin/mongodb.conf


11.连接方式

1.mongo 默认连接的127.0.0.1

2.mongo -part 27017

3.mongo 192.168.65.130:27017

12.停止进程

kill -2 `ps -ef|grep mongod|grep -v grep |awk '{print $2}'`

or

kill -2 3333

or

mongo -port 27017

use admin

db.shutdownServer();

如果提示没权限,则需要创建管理员用户,然后重新尝试
通过 db.shutdownServer() 关闭服务时需要使用本地连接才行,进去后要先use admin,然后认证用户后再执行。

认证用户:db.auth('username','pwd')

13.其他命令
 

1.创建用户命令:

db.createUser(
	{
		user:"root",
		pwd:"123456",
		roles:[{role:"root",db:"admin"}]
	}
);

2.关闭服务

进去后先use admin
db.shutdownServer()

3.删除用户

db.dropUser('ty')

4.看运行状态

db.runCommand({"serverStatus":1})


更多命令可以通过db.help()来查看

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ty_FFTQ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值