第十九周-文档数据库MongoDB、消息队列和微服务

  1. 完成redis单机安装,哨兵模式安装,主从安装,集群安装

单机安装

#安装依赖包

root@centos8\~#yum -y install gcc make jemalloc-devel

#如果支持systemd需要安装下面包

root@ubuntu2204 \~#apt update && apt -y install make gcc libjemalloc-dev

libsystemd-dev

root@ubuntu2004 \~#apt update && apt -y install make gcc libjemalloc-dev

libsystemd-dev

root@ubuntu1804 \~#apt update && apt -y install make gcc libjemalloc-dev

libsystemd-dev

root@centos8 \~#yum -y install gcc jemalloc-devel systemd-devel

root@centos7 \~#yum -y install gcc jemalloc-devel systemd-devel

#下载源码

root@centos8 \~#wget http://download.redis.io/releases/redis-6.2.4.tar.gz

root@centos8 \~#tar xvf redis-6.2.4.tar.gz

#编译安装

root@centos8 \~#cd redis-6.2.4/

#如果支持systemd,需要执行下面

root@centos8 redis-6.2.4#make -j 2 USE_SYSTEMD=yes PREFIX=/apps/redis

install

#如果不支持systemd,执行下面

root@centos8 redis-6.2.4#make -j 2 PREFIX=/apps/redis install #指定redis安装目录

#配置环境变量

root@centos8 \~#echo 'PATH=/apps/redis/bin:$PATH' >> /etc/profile

root@centos8 \~#. /etc/profile

#目录结构

root@centos8 \~#tree /apps/redis/

/apps/redis/

└── bin

├── redis-benchmark

├── redis-check-aof

├── redis-check-rdb

├── redis-cli

├── redis-sentinel -> redis-server

└── redis-server

1 directory, 6 files

#准备相关目录和配置文件

root@centos8 \~#mkdir /apps/redis/{etc,log,data,run} #创建配置文件、日志、数据等目录

#默认配置文件有问题,需要修改

root@centos8 redis-6.2.4#cp redis.conf /apps/redis/etc/

哨兵安装

#在所有主从节点执行

#基于包安装

root@centos8 \~#yum -y install redis

root@ubuntu2004 \~#apt -y install redis redis-sentinel

#所有节点的masterauth和requirepass必须相同

root@centos8 \~#vim /etc/redis.conf

bind 0.0.0.0

masterauth "123456"

requirepass "123456"

#或者非交互执行

root@centos8 \~#sed -i -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e 's/^# masterauth

.*/masterauth 123456/' -e 's/^# requirepass .*/requirepass 123456/'

/etc/redis.conf

#在所有从节点执行

root@centos8 \~#echo "replicaof 10.0.0.8 6379" >> /etc/redis.conf

#在所有主从节点执行

root@centos8 \~#systemctl enable --now redis

配置slave1

root@redis-slave1 \~#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface

may not be safe.

127.0.0.1:6379> REPLICAOF 10.0.0.8 6379

OK

127.0.0.1:6379> CONFIG SET masterauth "123456"

OK

127.0.0.1:6379> INFO replication

Replication

role:slave

master_host:10.0.0.8

master_port:6379

master_link_status:up

master_last_io_seconds_ago:4

master_sync_in_progress:0

slave_repl_offset:140

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:8fdca730a2ae48fb9c8b7e739dcd2efcc76794f3

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:140

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:99

repl_backlog_histlen:42

配置slave2

root@redis-slave2 \~#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface

may not be safe.

127.0.0.1:6379> REPLICAOF 10.0.0.8 6379

OK

127.0.0.1:6379> CONFIG SET masterauth "123456"

OK

127.0.0.1:6379> INFO replication

Replication

role:slave

master_host:10.0.0.8

master_port:6379

master_link_status:up

master_last_io_seconds_ago:3

master_sync_in_progress:0

slave_repl_offset:182

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:8fdca730a2ae48fb9c8b7e739dcd2efcc76794f3

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:182

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:15

repl_backlog_histlen:168

127.0.0.1:6379>

sentinel 配置

#如果是编译安装,在源码目录有sentinel.conf,复制到安装目录即可,

如:/apps/redis/etc/sentinel.conf

root@ubuntu2204 \~#cp redis-7.0.5/sentinel.conf /apps/redis/etc/sentinel.conf

root@centos8 \~#cp redis-6.2.5/sentinel.conf /apps/redis/etc/sentinel.conf

root@ubuntu2204 \~#chown redis.redis /apps/redis/etc/sentinel.conf

#编译安装修改配置文件

root@ubuntu2204 \~#vim /apps/redis/etc/sentinel.conf

root@ubuntu2204 \~#grep -Ev "#|^$" /apps/redis/etc/sentinel.conf

protected-mode no

port 26379

daemonize no

pidfile "/apps/redis/run/redis-sentinel.pid"

logfile "/apps/redis/log/redis-sentinel.log"

dir "/tmp"

sentinel monitor mymaster 10.0.0.102 6379 2

#mymaster是集群的名称,此行指定当前mymaster集群中master服务器的地址和端口

#2为法定人数限制(quorum),即有几个sentinel认为master down了就进行故障转移,一般此值是所有

sentinel节点(一般总数是>=3的 奇数,如:3,5,7等)的一半以上的整数值,比如,总数是3,即3/2=1.5,

取整为2,是master的ODOWN客观下线的依据

sentinel auth-pass mymaster 123456

#mymaster集群中master的密码,注意此行要在上面行的下面,注意:要求这组redis主从复制所有节点的密

码是一样的

sentinel down-after-milliseconds mymaster 3000

#判断mymaster集群中所有节点的主观下线(SDOWN)的时间,单位:毫秒,建议3000

acllog-max-len 128

sentinel deny-scripts-reconfig yes

sentinel resolve-hostnames no

sentinel announce-hostnames no

#包安装修改配置文件

root@centos8 \~#vim /etc/redis-sentinel.conf

bind 0.0.0.0

port 26379

daemonize yes

pidfile "redis-sentinel.pid"

logfile "sentinel_26379.log"

dir "/tmp" #工作目录

sentinel monitor mymaster 10.0.0.8 6379 2

#mymaster是集群的名称,此行指定当前mymaster集群中master服务器的地址和端口

#2为法定人数限制(quorum),即有几个sentinel认为master down了就进行故障转移,一般此值是所有

sentinel节点(一般总数是>=3的 奇数,如:3,5,7等)的一半以上的整数值,比如,总数是3,即3/2=1.5,

取整为2,是master的ODOWN客观下线的依据

sentinel auth-pass mymaster 123456

#mymaster集群中master的密码,注意此行要在上面行的下面,注意:要求这组redis主从复制所有节点的密

码是一样的

sentinel down-after-milliseconds mymaster 30000

#判断mymaster集群中所有节点的主观下线(SDOWN)的时间,单位:毫秒,建议3000

sentinel parallel-syncs mymaster 1

#发生故障转移后,可以同时向新master同步数据的slave的数量,数字越小总同步时间越长,但可以减轻新

master的负载压力

sentinel failover-timeout mymaster 180000

#所有slaves指向新的master所需的超时时间,单位:毫秒

sentinel deny-scripts-reconfig yes #禁止修改脚本

logfile /var/log/redis/sentinel.log

三个哨兵服务器的配置都如下

root@redis-master \~#grep -vE "^#|^$" /etc/redis-sentinel.conf

port 26379

daemonize no

pidfile "/var/run/redis-sentinel.pid"

logfile "/var/log/redis/sentinel.log"

dir "/tmp"

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|
| sentinel monitor mymaster 10.0.0.8 6379 2 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 3000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes | #修改此行 #增加此行 #修改此行 |

#注意此行自动生成必须唯一,一般不需要修改,如果相同则修改此值需重启redis和sentinel服务

sentinel myid 50547f34ed71fd48c197924969937e738a39975b

.....

Generated by CONFIG REWRITE

protected-mode no

supervised systemd

sentinel leader-epoch mymaster 0

sentinel known-replica mymaster 10.0.0.28 6379

sentinel known-replica mymaster 10.0.0.18 6379

sentinel current-epoch 0

root@redis-master \~#scp /etc/redis-sentinel.conf redis-slave1:/etc/

root@redis-master \~#scp /etc/redis-sentinel.conf redis-slave2:/etc/

启动哨兵服务

#确保每个哨兵主机myid不同,如果相同,必须手动修改为不同的值

root@redis-slave1 \~#vim /etc/redis-sentinel.conf

sentinel myid 50547f34ed71fd48c197924969937e738a39975c

root@redis-slave2 \~#vim /etc/redis-sentinel.conf

sentinel myid 50547f34ed71fd48c197924969937e738a39975d

root@redis-master \~#systemctl enable --now redis-sentinel.service

root@redis-slave1 \~#systemctl enable --now redis-sentinel.service

root@redis-slave2 \~#systemctl enable --now redis-sentinel.service

主从安装

Redis Server 默认为 master节点,如果要配置为从节点,需要指定master服务器的IP,端口及连接密码

在从节点执行 REPLICAOF MASTER_IP PORT 指令可以启用主从同步复制功能,早期版本使用 SLAVEOF

指令

127.0.0.1:6379> REPLICAOF MASTER_IP PORT #新版推荐使用

127.0.0.1:6379> SLAVEOF MasterIP Port #旧版使用,将被淘汰

127.0.0.1:6379> CONFIG SET masterauth <masterpass>

#在mater上设置key1

root@centos8 \~#redis-cli

127.0.0.1:6379> AUTH 123456

OK

127.0.0.1:6379> INFO replication

Replication

role:master

connected_slaves:0

master_replid:a3504cab4d33e9723a7bc988ff8e022f6d9325bf

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:0

second_repl_offset:-1

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

127.0.0.1:6379> SET key1 v1-master

OK

127.0.0.1:6379> KEYS *

  1. "key1"

127.0.0.1:6379> GET key1

"v1-master"

127.0.0.1:6379>

#以下都在slave上执行,登录

root@centos8 \~#redis-cli

127.0.0.1:6379> info

NOAUTH Authentication required.

127.0.0.1:6379> AUTH 123456

OK

127.0.0.1:6379> INFO replication #查看当前角色默认为master

Replication

role:master

connected_slaves:0

master_replid:a3504cab4d33e9723a7bc988ff8e022f6d9325bf

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:0

second_repl_offset:-1

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

127.0.0.1:6379> SET key1 v1-slave-18

OK

127.0.0.1:6379> KEYS *

  1. "key1"

127.0.0.1:6379> GET key1

"v1-slave-18"

127.0.0.1:6379>

#在第二个slave,也设置相同的key1,但值不同

127.0.0.1:6379> KEYS *

  1. "key1"

127.0.0.1:6379> GET key1

"v1-slave-28"

127.0.0.1:6379>

127.0.0.1:6379> INFO replication

Replication

role:master

connected_slaves:0

master_replid:a3504cab4d33e9723a7bc988ff8e022f6d9325bf

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:0

second_repl_offset:-1

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

127.0.0.1:6379>

#在slave上设置master的IP和端口,4.0版之前的指令为slaveof

127.0.0.1:6379> REPLICAOF 10.0.0.8 6379 #仍可使用SLAVEOF MasterIP Port

OK

#在slave上设置master的密码,才可以同步

127.0.0.1:6379> CONFIG SET masterauth 123456

OK

127.0.0.1:6379> INFO replication

Replication #角色变为slave

role:slave

master_host:10.0.0.8 #指向master

master_port:6379

master_link_status:up

master_last_io_seconds_ago:8

master_sync_in_progress:0

slave_repl_offset:42

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:b69908f23236fb20b810d198f7f4539f795e0ee5

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:42

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:42

#查看已经同步成功

127.0.0.1:6379> GET key1

"v1-master

#在master上可以看到所有slave信息

127.0.0.1:6379> INFO replication

Replication

role:master

connected_slaves:2

slave0:ip=10.0.0.18,port=6379,state=online,offset=112,lag=1 #slave信息

slave1:ip=10.0.0.28,port=6379,state=online,offset=112,lag=1

master_replid:dc30f86c2d3c9029b6d07831ae3f27f8dbacac62

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:112

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:112

127.0.0.1:6379>

验证同步
root@centos8 \~#tail /var/log/redis/redis.log

24402:M 06 Oct 2020 09:09:16.448 * Replica 10.0.0.18:6379 asks for

synchronization

24402:M 06 Oct 2020 09:09:16.448 * Full resync requested by replica

10.0.0.18:6379

24402:M 06 Oct 2020 09:09:16.448 * Starting BGSAVE for SYNC with target: disk

24402:M 06 Oct 2020 09:09:16.453 * Background saving started by pid 24507

24507:C 06 Oct 2020 09:09:16.454 * DB saved on disk

24507:C 06 Oct 2020 09:09:16.455 * RDB: 2 MB of memory used by copy-on-write

24402:M 06 Oct 2020 09:09:16.489 * Background saving terminated with success

24402:M 06 Oct 2020 09:09:16.490 * Synchronization with replica 10.0.0.18:6379

succeeded

在 slave 节点观察日志

root@centos8 \~#tail -f /var/log/redis/redis.log

24395:S 06 Oct 2020 09:09:16.411 * Connecting to MASTER 10.0.0.8:6379

24395:S 06 Oct 2020 09:09:16.412 * MASTER <-> REPLICA sync started

24395:S 06 Oct 2020 09:09:16.412 * Non blocking connect for SYNC fired the

event.

24395:S 06 Oct 2020 09:09:16.412 * Master replied to PING, replication can

continue...

24395:S 06 Oct 2020 09:09:16.414 * Partial resynchronization not possible (no

cached master)

24395:S 06 Oct 2020 09:09:16.419 * Full resync from master:

20ec2450b850782b6eeaed4a29a61a25b9a7f4da:0

24395:S 06 Oct 2020 09:09:16.456 * MASTER <-> REPLICA sync: receiving 196 bytes

from master

24395:S 06 Oct 2020 09:09:16.456 * MASTER <-> REPLICA sync: Flushing old data

24395:S 06 Oct 2020 09:09:16.456 * MASTER <-> REPLICA sync: Loading DB in memory

24395:S 06 Oct 2020 09:09:16.457 * MASTER <-> REPLICA sync: Finished with

success

修改 Slave 节点配置文件

root@centos8 \~#vim /etc/redis.conf

.......

replicaof <masterip> <masterport>

replicaof 10.0.0.8 6379 #指定master的IP和端口号

......

masterauth <master-password>

masterauth 123456 #如果密码需要设置

|----------------------------|--------------------------------|
| requirepass 123456 ....... | #和masterauth保持一致,用于将来从节点提升主后使用 |

root@centos8 \~#systemctl restart redis

Master 和 Slave查看状态

#在master上查看状态

127.0.0.1:6379> info replication

Replication

role:master

connected_slaves:1

slave0:ip=10.0.0.18,port=6379,state=online,offset=1104403,lag=0

master_replid:b2517cd6cb3ad1508c516a38caed5b9d2d9a3e73

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:1104403

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:55828

repl_backlog_histlen:1048576

127.0.0.1:6379>

#在slave上查看状态

|---------------------------------------|--------------------------------------|
| 127.0.0.1:6379> get key1 "v1-master" | #同步成功后,slave原key信息丢失,获取master复制过来新的值 |

127.0.0.1:6379> INFO replication

Replication

role:slave

master_host:10.0.0.8

master_port:6379

master_link_status:up

|-----------------------------------------|---------------------------------|
| master_last_io_seconds_ago:6 | #如果主从复制通信正常,每10秒重新从0计数,此值无法修改,如 |
| 果无法通信,当计数到60时,master_link_status显示为down |
| master_sync_in_progress:0 | #0表示同步完成,1表示正在同步 |

slave_repl_offset:1104431

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:b2517cd6cb3ad1508c516a38caed5b9d2d9a3e73

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:1104431

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:55856

repl_backlog_histlen:1048576

127.0.0.1:6379>

#停止master的redis服务:systemctl stop redis,在slave上可以观察到以下现象

127.0.0.1:6379> INFO replication

Replication

role:slave

master_host:10.0.0.8

master_port:6379

master_link_status:down #显示down,表示无法连接master

master_last_io_seconds_ago:-1

master_sync_in_progress:0

slave_repl_offset:1104529

master_link_down_since_seconds:4

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:b2517cd6cb3ad1508c516a38caed5b9d2d9a3e73

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:1104529

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:55954

repl_backlog_histle

集群安装

  1. 总结redis的持久化算法和淘汰策略

持久化算法

RDB(Redis DataBase):是基于某个时间点的快照,注意RDB只保留当前最新版本的一个快照

相当于MySQL中的完全备份

RDB 持久化功能所生成的 RDB 文件是一个经过压缩的二进制文件,通过该文件可以还原生成该 RDB 文

件时数据库的状态。因为 RDB 文件是保存在磁盘中的,所以即便 Redis 服务进程甚至服务器宕机,只要

磁盘中 RDB 文件存在,就能将数据恢复

RDB 支持save和bgsave两种命令实现数据文件的持久化

注意: save 指令使用主进程进行备份,而不生成新的子进程,但是也会生成临时文件temp-<主进程

PID>.rdb文件

AOF 即 AppendOnlyFile,AOF 和 RDB 都采有COW机制

AOF 可以指定不同的保存策略,默认为每秒钟执行一次 fsync,按照操作的顺序地将变更命令追加至指定的

AOF日志文件尾部

在第一次启用AOF功能时,会做一次完全备份,后续将执行增量性备份,相当于完全数据备份+增量变化

如果同时启用RDB和AOF,进行恢复时,默认AOF文件优先级高于RDB文件,即会使用AOF文件进行恢复

在第一次开启AOF功能时,会自动备份所有数据到AOF文件中,后续只会记录数据的更新指令

注意: AOF 模式默认是关闭的,第一次开启AOF后,并重启服务生效后,会因为AOF的优先级高于RDB,而

AOF默认没有数据文件存在,从而导致所有数据丢失

淘汰策略

  1. noeviction (不淘汰 - 默认策略):

    • 行为: 当内存不足时,新写入操作会报错(如OOM command not allowed)。读请求不受影响。

    • 适用场景: 数据绝对不能丢失,且你确信有足够内存或愿意处理写入失败。

  2. volatile-* (只淘汰设置了过期时间的键):

    • volatile-lru: 从设置了过期时间 的键中,淘汰最近最少使用的键。

    • volatile-lfu (Redis 4.0+): 从设置了过期时间 的键中,淘汰最不经常使用的键。

    • volatile-random: 从设置了过期时间 的键中,随机淘汰一个键。

    • volatile-ttl: 从设置了过期时间 的键中,淘汰剩余生存时间最短的键。

    • 适用场景: 数据集中有部分数据是临时缓存(有TTL),部分数据是持久重要的(无TTL)。只允许淘汰缓存部分。

  3. allkeys-* (淘汰所有键,无论是否设置过期时间):

    • allkeys-lru: 从所有键 中,淘汰最近最少使用的键。

    • allkeys-lfu (Redis 4.0+): 从所有键 中,淘汰最不经常使用的键。

    • allkeys-random: 从所有键 中,随机淘汰一个键。

    • 适用场景: 整个数据集都可视为缓存,所有数据在内存不足时都可以被淘汰。

  1. 完成mongodb的安装
bash 复制代码
#安装相关包
#Red Hat/CentOS:
yum install libcurl openssl
#Ubuntu 18.04 LTS ("Bionic")/Debian 10 "Buster":
sudo apt-get install libcurl4 openssl
#Ubuntu 16.04 LTS ("Xenial")/Debian 9 "Stretch":
sudo apt-get install libcurl3 openssl


cat >> /etc/rc.local <<EOF
echo never > /sys/kernel/mm/transparent hugepage/enabled
EOF
chmod +x /etc/rc.local


#创建所需用户和组
useradd mongod
#创建mongodb所需目录结构
mkdir -p /mongodb/{conf,data,log}
#创建YAML格式的配置文件,早期3.0版本以前是普通文本格式
cat > /mongodb/conf/mongo.conf <<EOF
#日志相关
systemLog:
destination: file
path: "/mongodb/log/mongodb.log" #日志位置
logAppend: true #追加日志

#数据存储有关
storage:
dbPath: "/mongodb/data/" #数据路径的位置
#进程控制
processManagement:
fork : true #后台守护进程
#网络配置有关
net:
port: 27017 #端口号,默认不配置端口号,是27017
bindIp: 0.0.0.0 #监听地址自MongoDB 3.6版本后默认监听在localhost
#安全验证有关配置
security:
authorization: enabled #是否打开用户名密码验证,默认此项为关掉
EOF
cat /mongodb/conf/mongo.conf
systemLog:
destination: file
path: "/mongodb/log/mongodb.log"
logAppend: true
storage:
dbPath: "/mongodb/data/"
processManagement:
fork: true
net:
port: 27017
bindIp: 0.0.0.0
chown -R mongod.mongod /mongodb/
tar xf mongodb-linux-x86_64-rhel70-v3.6-latest.tgz -C /usr/local
ln -s /usr/local/mongodb-linux-x86_64-rhel70-3.6.23-8-gc2609ed/
/usr/local/mongodb
#设置PATH变量
echo PATH=/usr/local/mongodb/bin/:'$PATH' > /etc/profile.d/mongodb.sh
. /etc/profile.d/mongodb.sh
#启动
su - mongod
mongod --dbpath /mongodb/data --bind_ip_all --port 27017 --logpath
/mongodb/log/mongod.log --logappend --fork
mongod -f /mongodb/conf/mongo.conf
#登录mongodb
mongo
#mongodb的关闭方式
mongod -f /mongodb/conf/mongo.conf --shutdown
#mongodb使用systemd管理
cat > /lib/systemd/system/mongod.service <<EOF
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
User=mongod
Group=mongod
ExecStart=/usr/local/mongodb/bin/mongod --config /mongodb/conf/mongo.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --config /mongodb/conf/mongo.conf --
shutdown
PrivateTmp=true
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now mongod
相关推荐
这个DBA有点耶6 小时前
NULL不是空——数据库里最反直觉的设计,90%新人踩过的坑
数据库·mysql·代码规范
这个DBA有点耶8 小时前
AI写的SQL跑崩了生产库,这锅谁背?
数据库·人工智能·程序员
镜舟科技9 小时前
Databricks 再提 LTAP,AI 时代的数据底座为何重回大一统叙事?
数据库·架构·agent
Databend10 小时前
从湖仓升级为 Agent 时代的数据控制面,Snowflake 和 Databricks 有哪些布局
大数据·数据库·agent
ClouGence13 小时前
SQL Server CDC 能放到 Always On 备库读吗?一文讲透原理与实践
数据库·sql server
葫芦和十三16 小时前
图解 MongoDB 25|分片架构三件套:mongos、config server 和 shard
后端·mongodb·agent
葫芦和十三1 天前
图解 MongoDB 26|片键设计:决定集群命运的一个决定
后端·mongodb·agent
先吃饱再说1 天前
存储的进化:从 MySQL 到浏览器缓存,数据到底住在哪?
数据库
Nturmoils1 天前
字段太多看不全,ksql 的展开模式和输出控制怎么用
数据库·后端
Databend1 天前
Agent 轨迹分析与归因的数据工程实践
大数据·数据库·agent