Linux端安装
我们从MonDB官网下载Linux端的安装包,建议下载4.0版本
打开虚拟机,在虚拟机上安装传输工具lrzsz,将下载好的.tgz包拖到虚拟机当中,拖到/usr/local/mongoDB目录下,
[root@server ~]# yum install -y lrzsz
[root@server ~]# cd /usr/local/
[root@server local]# mkdir mongoDB
[root@server local]# cd mongoDB/
[root@server mongoDB]# rz -E
rz waiting to receive.
[root@server mongoDB]# ll
total 102556
-rw-r--r--. 1 root root 105017141 Apr 24 14:35 mongodb-linux-x86_64-rhel80-4.0.28.tgz
使用tar命令进行解压缩
[root@server mongoDB]# tar -xvf mongodb-linux-x86_64-rhel80-4.0.28.tgz
mongodb-linux-x86_64-rhel80-4.0.28/THIRD-PARTY-NOTICES.gotools
mongodb-linux-x86_64-rhel80-4.0.28/README
mongodb-linux-x86_64-rhel80-4.0.28/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-rhel80-4.0.28/MPL-2
mongodb-linux-x86_64-rhel80-4.0.28/LICENSE-Community.txt
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongodump
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongorestore
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongoexport
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongoimport
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongostat
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongotop
mongodb-linux-x86_64-rhel80-4.0.28/bin/bsondump
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongofiles
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongoreplay
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongod
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongos
mongodb-linux-x86_64-rhel80-4.0.28/bin/mongo
mongodb-linux-x86_64-rhel80-4.0.28/bin/install_compass
[root@server mongoDB]# ll
total 102556
drwxr-xr-x. 3 root root 135 Apr 24 14:43 mongodb-linux-x86_64-rhel80-4.0.28
-rw-r--r--. 1 root root 105017141 Apr 24 14:35 mongodb-linux-x86_64-rhel80-4.0.28.tgz
将mongodb-linux-x86_64-rhel80-4.0.28传入到mondodbserver下
[root@server mongoDB]# mv mongodb-linux-x86_64-rhel80-4.0.28 mongodbserver
[root@server mongoDB]# ll
total 102556
-rw-r--r--. 1 root root 105017141 Apr 24 14:35 mongodb-linux-x86_64-rhel80-4.0.28.tgz
drwxr-xr-x. 3 root root 135 Apr 24 14:43 mongodbserver
[root@server mongoDB]# cd mongodbserver/
创建使用数据库时数据的存放路径和日志
root@server mongodbserver]# mkdir data
[root@server mongodbserver]# mkdir log
[root@server mongodbserver]# mkdir etc
[root@server mongodbserver]# mkdir conf
进入到/etc目录下,编辑mongodb.conf配置文件
[root@server mongodbserver]# cd etc
[root@server etc]# vim mongodb.conf
dbpath=/usr/local/mongoDB/mongodbserver/data
logpath=/usr/local/mongoDB/mongodbserver/log/mongodb.log
bind_ip=0.0.0.0
port=27017
fork=true
journal=false
storageEngine=mmapv1
执行mongo命令时出现报错
[root@server bin]# ./mongod --config /usr/local/mongoDB/mongodbserver/etc/mongodb.conf
./mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
解决方案
[root@server bin]# yum install -y libcrypto.so.*
#出现以下信息就说明安装成功了
[root@server bin]# mongo
MongoDB shell version v4.0.28
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2024-04-24T15:13:01.329+0800 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:356:17
@(connect):2:6
exception: connect failed
启动MonDB
[root@server bin]# cat /sys/kernel/mm/transparent_hugepage/defrag
always defer defer+madvise [madvise] never
[root@server bin]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
将以下脚本添加到/etc/rc.local
[root@server etc]# vim /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
创建mongo普通用户,给mongod用户赋权
[root@server bin]# useradd mongod
[root@server bin]# passwd mongod
Changing password for user mongod.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@server mongodbserver]# chown -R mongod:mongod /usr/local/mongoDB/mongodbserver
添加环境变量/etc/profile
export PATH=/usr/local/mongoDB/mongodbserver/bin:$PATH
进入普通用户mongod,输入mongo启动完成
[mongod@server ~]$ mongod --dbpath=/usr/local/mongoDB/mongodbserver/data --logpath=/usr/local/mongoDB/mongodbserver/log/mongodb.log --port=27017 --logappend --fork
[mongod@server ~]$ mongo
MongoDB shell version v4.0.28
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("64c64085-4ccc-4b3c-bce2-7579afb56920") }
MongoDB server version: 4.0.28
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten]
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten]
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten]
2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten]
2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> > show databases;
admin 0.000GB
config 0.000GB
local 0.000GB