Centos7安装redis5.0.7

1. 安装依赖包(Redis是C语言开发,需要安装gcc依赖环境)

yum install -y gcc gcc-c++

2. 下载最新版redis安装包并解压安装

复制代码
cd /usr/local/src

wget http://download.redis.io/releases/redis-5.0.7.tar.gz

tar -zxvf redis-5.0.7.tar.gz
mkdir -p /usr/local/redis/{etc,data}
cd redis-5.0.7/

#指定redis使用哪种内存分配器,目前有jemalloc,tcmalloc,libc
#jemalloc是facebook推出的,https://github.com/jemalloc/jemalloc
#tcmalloc是Google推出的,https://github.com/gperftools/gperftools
#libc是标准的内存分配库malloc和free
#具体使用哪种自己可以调整下面参数对比下
make MALLOC=libc
make install PREFIX=/usr/local/redis

ln -s /usr/local/src/redis-5.0.7/redis.conf /usr/local/redis/redis.conf

#创建日志文件
touch /var/log/redis/6379.log
复制代码

3.  打开 redis.conf 并更改配置文件

复制代码
更改密码
# requirepass foobared
requirepass xxx

允许后台静默运行
#daemonize no
daemonize yes

更改日志文件
#logfile ""
logfile "/var/log/redis/6379.log"
复制代码

4. 增加启动服务脚本

复制代码
新增配置文件
touch /usr/lib/systemd/system/redis.service redis.service内容如下: [Unit] Description=Redis 6379 After=syslog.target network.target [Service] Type=forking PrivateTmp=yes Restart=always ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 -a jcon shutdown User=root Group=root LimitCORE=infinity LimitNOFILE=100000 LimitNPROC=100000 [Install] WantedBy=multi-user.target

重新加载redis服务配置文件
systemctl daemon-reload

启动redis
systemctl start redis
停止redis
systemctl stop redis
重启redis
systemctl restart redis
加入开机启动
systemctl enable redis
禁止开机启动
systemctl disable redis
查看状态
systemctl status redis
复制代码
 
原文地址:https://www.cnblogs.com/a-du/p/12434257.html