在linux安装redis
1:将下载的redis-5.0.2.tar.gz拉到/opt文件夹下
2:解压文件到当前目录下
tar -zvxf redis-5.0.2.tar.gz
3:将解压出来的文件名修改为redis
4:由于redis是c语言编写的,所以我们需要先安装gcc,安装的命令如下:
yum -y install gcc
5:安装成功后输入 :
gcc -v
查看版本
6:然后进入到redis目录,进入redis,然后输入:
make
控制台会输出一些编译的信息
7:编译成功后,输入:
make install
自此redis就安装成功了
8:输入:redis-server 启动redis,启动成功。
启动redis服务:(三种启动方式)
1)前台启动:在任何目录下执行 redis-server
2)后台启动:在任何目录下执行 redis-server &
3)启动redis服务时,指定配置文件:redis-server redis.conf & ,这种主要用于你改了配置文件的情况,比如你把默认端口号改了,你就用这个,正常也用这个
9:修改redis密码,注意requirepass前面不能有空格
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 123456
# Command renaming.
#
redis的客户端,链接是redis-cli,有密码的需要输入auth 密码,显示OK才表示链接上,退出是exit
[root@localhost redis]# redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> exit
[root@localhost redis]#
10:编写sh启动脚本,保存为sh
#/bin/bash
redis-server redis.conf &
10:编写sh关闭脚本(通过密码),保存为sh
#/bin/bash
redis-cli -a 123456 shuntdown
11:设置redis开机自启动
11-1:在/etc目录下新建redis目录
11-2:将/usr/local/redis/redis.conf文件复制一份到/etc/redis目录下,并命名为6379.conf
11-3:将redis的启动脚本复制一份放到/etc/init.d目录下
[root@localhost ~]# cp /opt/app/redis/utils/redis_init_script /etc/init.d/redisd
[root@localhost ~]#
11-4:设置redis开机自启动, 先切换到/etc/init.d目录下, 然后执行自启命令
[root@localhost ~]# cd /etc/init.d
[root@localhost init.d]# chkconfig redisd on
[root@localhost init.d]#