阅读目录
1.下载
https://redis.io/download cd /usr/local/src wget -c http://download.redis.io/releases/redis-3.2.6.tar.gz
2.解压
cd /usr/local/src tar xzf redis-3.2.6.tar.gz
3.编译
cd /usr/local/src/redis-3.2.6make
若出现错误则说明未安装gcc
yum install gcc && make MALLOC=libccd /usr/local/src/redis-3.2.6 && make
4.创建redis目录
mkdir -p /usr/local/redis
5.复制主要配置文件到新文件夹
cp /usr/local/src/redis-3.2.6/src/redis-server /usr/local/redis/ cp /usr/local/src/redis-3.2.6/src/redis-cli /usr/local/redis/ cp /usr/local/src/redis-3.2.6/redis.conf /usr/local/redis/
6.开启后台运行
vim /usr/local/redis/redis.conf
修改redis.conf文件中的daemonize no为daemonize yes并保存
7.创建redis命令软连接
ln -s /usr/local/redis/redis-cli /usr/bin/redis
在任意命令行执行redis
8.添加开机启动服务
vim /etc/systemd/system/redis-server.service
粘贴以下内容
[Unit] Description=The redis-server Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/var/run/redis_6379.pid ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target
9.设置开机启动
systemctl daemon-reload systemctl start redis-server.service systemctl enable redis-server.servic
10.检查是否安装成功
ps -A|grep redis
11.连接登录
#交互式
#redis-cli -h {host} -p {port} $redis-cli -h 127.0.0.1 -p 6379 127.0.0.1:6379>set hello world OK 127.0.0.1:6379>get hello "world"
#命令式
#redis-cli -h {host} -p {port} {command} $redis-cli -h 127.0.0.1-p 6379 get hello "world"
12.永久设置Redis密码
vim /etc/redis.conf
#在配置文件中有个参数:requirepass 这个就是配置redis访问密码的参数;
#比如 requirepass test123;
需重启Redis才能生效
13.临时设置Redis密码
redis 127.0.0.1:6379> config set requirepass test123
#查询密码:
redis 127.0.0.1:6379> config get requirepass (error) ERR operation not permitted
#密码验证:
redis 127.0.0.1:6379> auth test123 OK
#再次查询:
redis 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "test123"
14.登陆有密码的Redis
redis-cli -p 6379 -a test123
15.先登陆后验证
redis-cli -p 6379 redis 127.0.0.1:6379> auth test123 OK
16.开启后台运行
将redis.conf中的"daemonize no"为"daemonize yes"并保存,重启redis生效。