centos7 redis安装教程
1.下载解压
#下载至/home/install(或windows系统下载后上传)
mkdir /home/install
cd /home/install
wget http://download.redis.io/releases/redis-4.0.11.tar.gz
#解压
tar -zxvf redis-4.0.11.tar.gz
#移动
mv redis-4.0.11 /usr/local/redis
2.编译安装
cd /usr/local/redis
make && make install
#查看src目录是否生成redis相关工具
ll /usr/local/redis/src/
3.redis.conf(详情官网参考每行注释)
vim /usr/local/redis/redis.conf
#修改如下几行信息
bind 0.0.0.0#不限制访问ip和远程连接
protected-mode no#保护模式
daemonize yes#后台运行线程
4.启动
#启动命令
/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
#查看是否运行
ps -ax|grep redis
5.连接测试
/usr/local/redis/src/redis-cli -p 6379 --raw #连接指令 --raw中文显示
set name '丁洁'
set sex '女'
get name
get sex
6.开机启动
(1)编辑redis.service文件
cd /usr/lib/systemd/system #进入service文件目录
vim ./redis.service #因为有的机器需部署多个redis这里以redis+端口号命名
加入如下内容
Description=redis
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
ExecReload=/usr/local/redis/src/redis-cli -p 6379 shutdown | /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/local/redis/src/redis-cli -p 6379 shutdown
[Install]
WantedBy=multi-user.target
(2)生效
systemctl daemon-reload
(3)改变文件权限
chmod 777 ./redis.service
(4)建立软连接
ln -s /usr/lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
(5)systemctl开机启动redis
systemctl enable redis.service
或
systemctl enable redis
(6)systemctl取消开机启动redis
systemctl disable redis.service
(7)systemctl启动redis
systemctl start redis.service
(8)systemctl重启redis
systemctl restart redis.service
(9)systemctl停止redis
systemctl restart redis.service
(10)systemctl查看redis状态
systemctl status redis.service