我是靠谱客的博主 刻苦金针菇,这篇文章主要介绍Redis 5.0.8 安装与基本配置1.下载安装包(root)2.创建用户和组(root) 3.调整 redis 用户的 ulimit(root)4.创建 redis 的安装路径(root) 5.创建 redis 的数据路径(root)6.编译、安装源程序(redis)7.配置环境变量(redis)8.修改系统参数 (root) 9.启动 redis 服务(redis)10.客户端连接测试 (redis)11.停止 redis 服务(redis)12.设置开机自动启动(root)13.修改 r,现在分享给大家,希望可以做个参考。
1.下载安装包(root)
官网:https://redis.io/ 下载即可。
放入 /soft 文件加并授权 chmod 777 -R /soft 备用
2.创建用户和组(root)
复制代码
1
2
3
4
5
6
7
8
9
10
11[root@test2 ~]# groupadd -g 601 redis [root@test2 ~]# useradd -u 6001 -g 601 redis [root@test2 ~]# id redis uid=6001(redis) gid=601(redis) groups=601(redis) [root@test2 ~]# passwd redis Changing password for user redis. New password: BAD PASSWORD: it is too short BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully.
3.调整 redis 用户的 ulimit(root)
复制代码
1
2
3
4echo "redis hard nofile 10240" >> /etc/security/limits.conf echo "redis soft nofile 10240" >> /etc/security/limits.conf echo "redis hard nproc 8192" >> /etc/security/limits.conf echo "redis soft nproc 8192" >> /etc/security/limits.conf
4.创建 redis 的安装路径(root)
复制代码
1
2mkdir -p /data/redis chown -R redis:redis /data/redis
5.创建 redis 的数据路径(root)
复制代码
1
2
3
4mkdir -p /data/redis/log mkdir -p /data/redis/conf mkdir -p /data/redis/data chown -R redis:redis /data/redis
6.编译、安装源程序(redis)
复制代码
1
2
3
4
5
6
7
8su - redis cd /soft tar zxvf redis-5.0.8.tar.gz cd redis-5.0.8 make cd src make PREFIX=/data/redis install cp ../redis.conf /data/redis/redis.conf
7.配置环境变量(redis)
复制代码
1
2vi ~/.bash_profile PATH=/data/redis/bin:$PATH
8.修改系统参数 (root)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29a.调整vm.overcommit_memory echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf 可选值:0、1、2 0:表示内核将检查是否有足够的可用内存供应用进程使用,如果有足够的可用内存,内存申请 允许,否则,内存申请失败,并把错误返回给应用进程。 1:表示内核允许分配所有的物理内存,而不管当前的内存状态如何。 2:表示内核允许分配超过所有物理内存和交换空间综合的内存。 b.调整Transparent Huge Pages(THP) 解决:redis 做 rdb时会有部分请求超时的case echo "never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local c.TCP backlog设置 echo "net.core.somaxconn = 2048 " >> /etc/sysctl.conf sysctl -p 此参数确定了TCP 连接中已完成队列(完成3次握手之后)的长度, 当然此值必须不大于Linux系统定义的/proc/sys/net/core/somaxconn值,默认是511, 而Linux的默认参数值是128.当系统并发量大并且客户端速度缓慢的时候,可以将这2个参数一起参考 设定。 d.调整redis.conf vi /data/redis/redis.conf添加以下 daemonize yes logfile "/data/redis/log/redis.log" requirepass redis 并修改 bind参数的127.0.0.1 ,改为本机IP 其中还有内存,最大连接数等参数,根据情况自己设置
9.启动 redis 服务(redis)
复制代码
1
2
3
4
5
6
7
8
9[redis@test2 ~]$ redis-server /data/redis/redis.conf [redis@test2 ~]$ ps -ef|grep redis root 32070 27704 0 01:58 pts/0 00:00:00 su - redis redis 32071 32070 0 01:58 pts/0 00:00:00 -bash redis 32091 1 0 01:58 ? 00:00:00 redis-server 192.168.65.2:6379 redis 32099 32071 0 01:59 pts/0 00:00:00 ps -ef redis 32100 32071 0 01:59 pts/0 00:00:00 grep redis [redis@test2 ~]$ netstat -an|grep 6379 tcp 0 0 192.168.65.2:6379 0.0.0.0:* LISTEN
10.客户端连接测试 (redis)
复制代码
1
2
3
4
5
6
7
8
9[redis@test2 ~]$ redis-cli -h 192.168.65.2 192.168.65.2:6379> ping (error) NOAUTH Authentication required. #这里要进行密码验证是因为我们在配置文件中修改requirepass参数,如果不设置,则默认为空,客户端连进来就直接可以操作,如果设置了就需要验证密码后才能操作 192.168.65.2:6379> auth redis OK 192.168.65.2:6379> ping PONG 192.168.65.2:6379>
11.停止 redis 服务(redis)
复制代码
1
2
3
4
5
6
7
8
9
10[redis@test2 ~]$ redis-cli -h 192.168.65.2 -a redis Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 192.168.65.2:6379> ping PONG 192.168.65.2:6379> shutdown not connected> PS:-a 后面跟的是密码,进去后就无需验证密码 也可以使用 pkill redis-server
12.设置开机自动启动(root)
复制代码
1
2
3vim /etc/rc.local 添加以下内容: su - redis -c "/data/redis/bin/redis-server /data/redis/redis.conf"
13.修改 redis 密码 (redis)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30a.关闭 redis 服务 > vi /data/redis/redis.conf > 修改 requirepass redis123 > 重启 redis b.不关闭 redis 服务 > vi /data/redis/redis.conf > 修改 requirepass redis123 > redis-cli -h 192.168.65.2 192.168.65.2:6379> ping (error) NOAUTH Authentication required. 192.168.65.2:6379> auth redis13 (error) ERR invalid password 192.168.65.2:6379> auth redis123 OK 192.168.65.2:6379> config get requirepass 1) "requirepass" 2) "redis123" 192.168.65.2:6379> config set requirepass redis OK 192.168.65.2:6379> config get requirepass 1) "requirepass" 2) "redis" 192.168.65.2:6379> exit [redis@test2 ~]$ redis-cli -h 192.168.65.2 192.168.65.2:6379> auth redis OK 192.168.65.2:6379> ping PONG
14. master 有密码,slave 如何设置
复制代码
1
2
3vi /data/redis/redis.conf 添加以下内容: masterauth redis
15.第二种安装方法(不推荐,因为是用 root 安装的)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33cd /soft/redis-5.0.8/utils [root@test2 utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] 6479 # 写新的端口号 Please select the redis config file name [/etc/redis/6479.conf] /data/redis/6479/redis_6479.conf #填配置文件存放路径 Please select the redis log file name [/var/log/redis_6479.log] /data/redis/6479/log/redis_6479.conf #填日志文件存放路径 Please select the data directory for this instance [/var/lib/redis/6479] /data/redis/6479/data/ #填数据文件存放的路径 Please select the redis executable path [] /data/redis/bin/redis-server Selected config: Port : 6479 Config file : /data/redis/6479/redis_6479.conf Log file : /data/redis/6479/log/redis_6479.conf Data dir : /data/redis/6479/data/ Executable : /data/redis/bin/redis-server Cli Executable : /data/redis/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. #按回车 Copied /tmp/6479.conf => /etc/init.d/redis_6479 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! #安装成功 查看状态 [root@test2 utils]# ps -ef|grep redis redis 2127 1 0 03:22 ? 00:00:01 redis-server 192.168.65.2:6379 root 2192 1 0 03:34 ? 00:00:00 /data/redis/bin/redis-server 127.0.0.1:6479 root 2197 2044 0 03:34 pts/0 00:00:00 grep redis [root@test2 utils]# netstat -an|grep 6479 tcp 0 0 127.0.0.1:6479 0.0.0.0:* LISTEN [root@test2 utils]#
最后
以上就是刻苦金针菇最近收集整理的关于Redis 5.0.8 安装与基本配置1.下载安装包(root)2.创建用户和组(root) 3.调整 redis 用户的 ulimit(root)4.创建 redis 的安装路径(root) 5.创建 redis 的数据路径(root)6.编译、安装源程序(redis)7.配置环境变量(redis)8.修改系统参数 (root) 9.启动 redis 服务(redis)10.客户端连接测试 (redis)11.停止 redis 服务(redis)12.设置开机自动启动(root)13.修改 r的全部内容,更多相关Redis内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复