1. redis的安装
-
下载
-
解压
[hadoop@spark000 software]$ tar -zxvf redis-5.0.5.tar.gz -C ~/app
-
编译
[hadoop@spark000 software]$ cd ~/app/redis-5.0.5/ [hadoop@spark000 redis-5.0.5]$ make [hadoop@spark000 redis-5.0.5]$ make install
出现问题
Error:Permission denied
Solve:使用 sudo make install
Error:hadoop is not in the sudoers file. This incident will be reported.Solve:
-
切到 root 用户
-
添加 sudo 文件的写权限
[root@spark000 ~]# chmod u+w /etc/sudoers
-
编辑 sudoers 文件
[root@spark000 ~]# vim /etc/sudoers
找到这行 root ALL=(ALL) ALL,在它下面添加 hadoop ALL=(ALL) ALL (这里的hadoop是你的用户名),如图
-
撤销 sudoers 文件写权限
[root@spark000 ~]# chmod u-w /etc/sudoers
-
扩展
# 你可以在 sudoers 文件中添加下面四行中任意一个 youruser ALL=(ALL) ALL :允许用户 youruser 执行 sudo 命令(需要输入密码)。 %youruser ALL=(ALL) ALL :允许用户组 youruser 里面的用户执行 sudo 命令(需要输入密码)。 youruser ALL=(ALL) NOPASSWD: ALL :允许用户 youruser 执行 sudo 命令,并且在执行的时候不输入密码。 %youruser ALL=(ALL) NOPASSWD: ALL :允许用户组 youuser 里面的用户执行 sudo 命令,并且在执行的时候不输入密码。
-
-
此时再输入 sudo make install
-
配置 redis.conf ,后台启动
[hadoop@spark000 redis-5.0.5]$ vim redis.conf 1). # bind 127.0.0.1 (将此行注释掉) 2). protected-mode no (测试阶段改为 no) 3). daemonize yes (进程后台启动) 4). logfile "/home/hadoop/data/redislogs/redis.log" (启动日志)
-
启动
[hadoop@spark000 redis-5.0.5]$ src/redis-server redis.conf [hadoop@spark000 redis-5.0.5]$ src/redis-cli -h spark000 -p 6379 spark000:6379>
-
测试
如果redis.conf配置文件中的 bind 127.0.0.1 没有被注释掉 则 [hadoop@spark000 redis-5.0.5]$ src/redis-cli -h spark000 -p 6379 Could not connect to Redis at spark000:6379: Connection refused not connected> 不能连接其他主机 此时发现 1)当注释掉此行启动时 [hadoop@spark000 redislogs]$ ps -ef|grep redis hadoop 58038 1 0 11:01 ? 00:00:00 src/redis-server *:6379 hadoop 58045 57947 0 11:02 pts/0 00:00:00 grep --color=auto redis 2)此行没有被注释时 [hadoop@spark000 redislogs]$ ps -ef|grep redis hadoop 58057 1 0 11:04 ? 00:00:00 src/redis-server 127.0.0.1:6379 hadoop 58062 57947 0 11:04 pts/0 00:00:00 grep --color=auto redis
2. redis命令的使用
-
如果你想查看 string 的使用方法
在命令行输入127.0.0.1:6379> help @string APPEND key value summary: Append a value to a key since: 2.0.0 GET key summary: Get the value of a key since: 1.0.0 INCR key summary: Increment the integer value of a key by one since: 1.0.0 INCRBY key increment summary: Increment the integer value of a key by the given amount since: 1.0.0 INCRBYFLOAT key increment summary: Increment the float value of a key by the given amount since: 2.6.0 MGET key [key ...] summary: Get the values of all the given keys since: 1.0.0 MSET key value [key value ...] summary: Set multiple keys to multiple values since: 1.0.1 ......
-
hash,list,set,sorted set 等命令查看方法一致
-
查看redis版本号
redis-cli -v redis-cli --version