安装redis
-
操作步骤
# 解压 tar -zxvf redis-5.0.14/.tat.gz -C /urs/local/ # 重命名,易读 mv /urs/local/redis-5.0.14/ /urs/local/redis/ # 安装环境依赖包 yum install -y gcc-c++ # 编译【异常执行:make MALLOC=libc,避免jemalloc重载Linux下的ANSI C的malloc和free函数】 cd /urs/local/redis/ make # 安装 make install # 验证 redis-server
后台启动
-
编辑redis配置文件
vim /usr/local/redis/redis.conf
-
修改可后台启动:daemonize yes
################################# GENERAL ##################################### # By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. daemonize yes
-
验证
redis-server /usr/local/redis/redis.conf
systemctl 管理redis
-
创建服务脚本
vim /usr/lib/systemd/system/redis.service
-
修改服务脚本
# 在/usr/lib/systemd/system/路径下创建redis.service [Unit] Description=Redis server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/bin/bash -c '/usr/local/bin/redis-server /usr/local/redis/redis.conf' ExecStop=/bin/bash -c '/usr/local/bin/redis-cli shutdown' Restart=always PrivateTmp=true [Install] WantedBy=multi-user.target
-
重新加载systemctl配置
systemctl daemon-reload
-
启停redis服务
# 启停redis systemctl start|restart|stop|status redis.service # 开机启动/不启动redis服务 systemctl enable|disable redis.service