1.进入linux 服务器
2.进入/usr/local/下创建mongodb 文件
3.centos7下载mongodb文件
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.9.tgz
4.解压文件
tar -zxvf mongodb-linux-x86_64-rhel70-4.0.9.tgz
5.将文件拷贝到指定目录
mv mongodb-linux-x86_64-rhel70-4.0.9/* /usr/local/mongodb
6.在mongodb 下创建logs,data,conf 文件夹
7.在logs下创建mongodb.log
touch mongodb.conf
8.在conf下创建mongodb.conf,配置文档目录
9.添加环境变量
进入bin/etc/中 添加环境变量(如果编辑profile是吧,可以打开 ls -a 查看隐藏文件,删除.profile.swp这样的文件)
10.需要设置生效
11.启动mongodb服务
12.链接mongodb数据库
13.关闭 db.shutdownServer(),或者killall mongod
14.mongodb
cd /etc/init.d
MongoDB设置为系统服务并且设置开机启动
#!/bin/sh
##chkconfig: 2345 80 90#description: mongodbif test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabledfiif test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defragfistart() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf}stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf --shutdown}case "$1" in
start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1esac将代码放入mongod中
chmod –R a+x mongod 设置执行权限
chkconfig --add mongod #加入系统服务
chkconfig mongodb on #开机启动
shutdown -r重启服务器
启动mongodb service mongod start
service mongod stop 关闭
验证是否启动 lsof -i :28001
报错:
停止mongodb 运行重新运行
systemctl daemon-reload