英文官网:Redis - The Real-time Data Platform
中文官网:http://www.redis.cn/
下载地址:https://download.redis.io/releases/xxxxx.tar.gz
1.1 安装前的说明:
Redis的服务端可以安装在Linux、Windows上,但是在实际生产环境中,Redis几乎99%都是安装在Linux服务器上的;又因为是使用c语言开发的,所以源码安装时,需要c语言环境
yum -y install gcc-c++
如果安装过,可以使用gcc -v来查看一下c语言环境的版本号,必须大于等于4.8.5
1.2 安装
步驟1) 检查安装c语言环境
[root@qianfeng01 ~]# yum -y install gcc gcc-c++
[root@qianfeng01 ~]# yum -y install zlib* zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
步骤2)上传、解压、更名
[root@qianfeng01 ~]# tar -zxvf redis-7.2.6.tar.gz -C /usr/local/
[root@qianfeng01 ~]# cd /usr/local/
[root@qianfeng01 local]# mv redis-7.2.6/ redis
步骤3)编译
[root@qianfeng01 local]# cd redis
[root@qianfeng01 redis]# make
步骤4)安装
注意:安装时,如果不指定安装目录的前缀,会将bin文件夹,安装到/usr/local下的bin里,因此最好指定一下前缀
[root@qianfeng01 redis]# make install PREFIX=/usr/local/redis
注意:此时在redis目录下,就会出现bin目录
步骤5)配置环境变量
[root@qianfeng01 redis]# vim /etc/profile
..........省略...........
#redis environment
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
[root@qianfeng01 redis]# source /etc/profile
#查看版本号
[root@qianfeng01 redis]# redis-cli --version
1.3 Redis服务的启动与关闭
1.3.1 配置文件的修改
注意:修改四个地方,参考下面的提示:
#1: 将redis里的redis.conf拷贝到bin目录下
[root@qianfeng01 redis]# cp redis.conf bin/
#2: 修改bin下的redis.conf文件
[root@qianfeng01 bin]# vim redis.conf
...省略...
82 # COMMENT OUT THE FOLLOWING LINE.
83 #
84 # You will also need to set a password unless you explicitly disable protected
85 # mode.
86 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 #bind 127.0.0.1 -::1
<== 将87行的ip绑定注释掉。 注释掉,表示远程可以使用具体IP连接,本机可以使用具体IP和127.0.0.1连接
<== 第二种方式:解开注释,bind后面绑定具体IP, 一旦绑定具体IP,127.0.0.1 就无法使用了
...省略...
108 # By default protected mode is enabled. You should disable it only if
109 # you are sure you want clients from other hosts to connect to Redis
110 # even if no authentication is configured.
111 protected-mode no <== 将yes改为no,表示关闭保护模式,可以远程连接
...省略...
304 ################################# GENERAL #####################################
305
306 # By default Redis does not run as a daemon. Use 'yes' if you need it.
307 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
308 # When Redis is supervised by upstart or systemd, this parameter has no impact.
309 daemonize yes <== 将no改为yes,改为后台进程运行
...省略...
1035 # IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
1036 # layer on top of the new ACL system. The option effect will be just setting
1037 # the password for the default user. Clients will still authenticate using
1038 # AUTH <password> as usually, or more explicitly with AUTH default <password>
1039 # if they follow the new protocol: both will work.
1040 #
1041 # The requirepass is not compatible with aclfile option and the ACL LOAD
1042 # command, these will cause requirepass to be ignored.
1043 #
1044 requirepass 123456 <== 解开注释,设置密码
1.3.2 启动服务
启动服务, 带上配置文件
[root@qianfeng01 bin]# redis-server /usr/local/redis/bin/redis.conf
如果在后续修改了配置文件,那么必须重启服务才能生效。
查看进程
[root@qianfeng01 ~]# ps -ef | grep redis
root 31713 1 0 10:37 ? 00:00:00 redis-server *:6379
root 31771 19391 0 10:38 pts/0 00:00:00 grep --color=auto redis
警告处理
//针对这两个问题,都要修改/etc/sysctl.conf文件,在文件末尾加入以下两句:
net.core.somaxconn= 1024
vm.overcommit_memory = 1
1.3.3 关闭方式
方式1)正规关闭方式
[root@qianfeng01 ~]# redis-cli -h <ip地址或者主机名> -a <密码> shutdown
方式2)kill掉
[root@qianfeng01 ~]# kill -9 pid