Redis的安装
第一部分:安装redis
1.官网获取解压包并解压到 /usr/local 下
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar -zxvf redis-5.0.3.tar.gz -C /usr/local/software/
2.通过yum安装gcc
yum install -y gcc
3.执行编译安装(在redis路径下)
cd /usr/local/software/redis-5.0.3/
make install
在安装redis成功后,你将可以在/usr/local/看到一个bin的目录,里面包括了以下文件:
[root@bogon redis-5.0.3]# cd /usr/local/bin/
[root@bogon bin]# ll
total 32656
lrwxrwxrwx. 1 root root 32 Dec 25 11:42 cnpm -> node-v10.14.2-linux-x64/bin/cnpm
-rwxr-xr-x. 1 root root 4365216 Dec 25 17:58 redis-benchmark
-rwxr-xr-x. 1 root root 8089430 Dec 25 17:58 redis-check-aof
-rwxr-xr-x. 1 root root 8089430 Dec 25 17:58 redis-check-rdb
-rwxr-xr-x. 1 root root 4800599 Dec 25 17:58 redis-cli
lrwxrwxrwx. 1 root root 12 Dec 25 17:58 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8089430 Dec 25 17:58 redis-server
lrwxrwxrwx. 1 root root 31 Dec 25 10:33 vue -> node-v10.14.2-linux-x64/bin/vue
第二部分:将redis做成一个服务
1.复制脚本到/etc/rc.d/init.d目录
按以上步骤安装Redis时,其服务脚本位于:
cd /usr/local/software/redis-5.0.3/utils
#复制脚本
cp redis_init_script /etc/init.d/redis
2.更改redis脚本
vi /etc/init.d/redis
3.将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf
[root@bogon utils]# mkdir /etc/redis
[root@bogon utils]# cp /usr/local/software/redis-5.0.3/redis.conf /etc/redis/6379.conf
(如果要开放远程端口访问,需要将config文件先进行如下修改:)
vi /usr/local/software/redis-5.0.3/redis.conf
将默认绑定的本机bind行注释掉,将protected-mode模式改为no
6379为端口号,以上操作完成后,即可注册redis服务:
chkconfig --add redis
4.设置开机自启redis服务
chkconfig redis on
5.开机启动测试
[onegis@bogon ~]$ netstat -nlpt
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN -
Redis常用命令
启动redis-cli:
redis-cli -h 192.168.1.178 -p 6379
redis-cli命令
1.select 1,2,3.....:选择数据库,默认为16
2.set key value :插入类型为String的
3.get key:取数据类型为String的