Centos7安装Redis

声明:来源:https://www.cnblogs.com/heqiuyong/p/10463334.html

centos7.6 安装实例:

#包放到 /urs/local 下面
tar
-zxvf redis-6.2.7.tar.gz cd redis-6.2.7 make make install PREFIX=/usr/local/redis-6.2.7 --解压到当前目录使用 tar -zxvf redis-6.2.7.tar.gz --strip-components 1 -C ./ vi redis.conf

绑定ip: bind 0.0.0.0 -::1 修改 redis.conf 文件,把 daemonize no 改为 daemonize yes 修改密码: requirepass
持久化配置: appendonly yes
设置工作目录: dir /usr/local/redis-6.2.7
#启动redis服务 .
/bin/redis-server redis.conf #添加开机启动服务 [root@localhost bin]# vi /etc/systemd/system/redis.service 复制粘贴以下内容: [Unit] Description=redis-server After=network.target [Service] Type=forking ExecStart=/usr/local/redis-6.2.7/bin/redis-server /usr/local/redis-6.2.7/redis.conf PrivateTmp=true [Install] WantedBy=multi-user.target 执行命令使改动生效:systemctl daemon-reload 设置开机启动 [root@localhost bin]# systemctl daemon-reload [root@localhost bin]# systemctl start redis.service [root@localhost bin]# systemctl enable redis.service

 

 七 同一个服务器上部署两个时用:

[root@localhost system]# cat /etc/systemd/system/redis2.service                     #---名称必须要用 service结尾,不然出问题
[Unit]
Description=redis-service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis16380/bin/redis-server /usr/local/redis16380/redis.conf       #------路径,端口,存储位置,/dir 都要修改
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

执行命令使改动生效:systemctl daemon-reload

设置开机启动

[root@localhost bin]# systemctl daemon-reload

[root@localhost bin]# systemctl start redis.service

[root@localhost bin]# systemctl enable redis.service

 

创建 redis 命令软链接

[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

测试 redis

 

服务操作命令

systemctl start redis.service   #启动redis服务

systemctl stop redis.service   #停止redis服务

systemctl restart redis.service   #重新启动服务

systemctl status redis.service   #查看服务当前状态

systemctl enable redis.service   #设置开机自启动

systemctl disable redis.service   #停止开机自启动

 

启动reids:

src 目录下面: ./redis-server ../redis.conf

查看:
whereis redis-cli
whereis redis-server


登录
/usr/local/bin/redis-cli

进程
ps -ef |grep redis

端口
netstat -lntp | grep 6379

 

处理:redis 报错:Asynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting fo

分析:

Redis在执行write的时候,由操作系统自身被动控制何时进行fsync。这里如果我们要主动触发操作系统的fsync,可以设置操作系统级别的参数:

# 查看内存的脏页字节大小,设置为0代表由系统自己控制何时调用fsync
sysctl -a | grep vm.dirty_bytes
vm.dirty_bytes = 0 # 修改为一个小的值,例如32MB,达到这个数据量就fsync,让操作系统fsync这个动作更频繁一点,避免单次fsync太多数据,导致阻塞 echo "vm.dirty_bytes=33554432" >> /etc/sysctl.conf 

echo "vm.dirty_bytes=33554432" >> /etc/sysctl.conf

    overcommit_memory=0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
    overcommit_memory=1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
    overcommit_memory=2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf  

sysctl vm.overcommit_memory=1 

 

信创环境下redis报错   Note that it is possible to suppress this warning by setting the following config: ignore-warnings ARM64-COW-BUG:

修改配置文件 ,redis.conf 中,把注释去掉:ignore-warnings ARM64-COW-BUG

 

示例:

vi /etc/systemd/system/redis2.service

[Unit]
Description=redis-service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis16380/bin/redis-server /usr/local/redis16380/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start redis2.service

ps -ef|grep redis

systemctl enable redis2.service
systemctl enable redis3.service

firewall-cmd --zone=public --add-port=16380/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports

cp -r /usr/local/redis-6.2.7/*  /usr/local/redis16380

tar -zxvf redis-6.2.7.tar.gz --strip-components 1 -C ./redis16380

make install PREFIX=/usr/local/redis16381
make install PREFIX=/usr/local/redis16380

 

posted @ 2020-09-05 09:39  leolzi  阅读(148)  评论(0编辑  收藏  举报