1.下载可能需要的依赖
yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc
2.下载redis
wget http://download.redis.io/releases/redis-3.2.6.tar.gz
3.解压缩
tar xzf redis-3.2.6.tar.gz
4.进入目录并编译
cd redis-3.2.6/
make
5.创建存储redis的目录并复制文件
mkdir -p /usr/local/redis
cd src/
cp ./redis-server /usr/local/redis/
cp ./redis-cli /usr/local/redis/
cd ..
cp redis.conf /usr/local/redis/
6.编辑配置文件
61行修改绑定的IP : bind 0.0.0.0
128行改成可后台运行: daemonize yes
cd /usr/local/redis/
vim redis.conf
7.直接运行
cd /usr/local/redis/
./redis-server
8.后台运行
cd /usr/local/redis/
./redis-server ./redis.conf
8.设置开机启动
在/etc 目录下创建redis 文件夹
cd /etc/
mkdir redis
将 /usr/local/redis/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf
cp /usr/local/redis/redis.conf /etc/redis/6379.conf
将redis的启动脚本复制一份放到/etc/init.d目录下
cp /home/redis-3.2.6/utils/redis_init_script /etc/init.d/redisd
设置redis开机自启动
cd /etc/init.d/
vim redisd
在第一行加入如下两行注释
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
修改路径,保存并退出vim
EXEC=/usr/local/redis/redis-server
CLIEXEC=/usr/local/redis/redis-cli
执行开机自启命令
chkconfig redisd on
启动和关闭redis
service redisd start
service redisd stop
参考资料:
https://www.cnblogs.com/onephp/p/6245902.html
https://www.cnblogs.com/zuidongfeng/p/8032505.html