CentOS安装Redis

4次阅读

共计 1685 个字符,预计需要花费 5 分钟才能阅读完成。

前言

应用 CentOS7 零碎 yum 形式装置 Redis-5.0.3

一、Redis 装置

因为 Redis 是用 C 语音开发,所以咱们装置前需先确认是否装置 gcc 环境:

$ gcc -v
$ rpm -qa | grep gcc

个别状况下 CentOS 是默认装置 gcc,如果没有装置,执行以下命令进行装置:

$ yum -y install gcc

下载并解压安装包:

$ wget http://download.redis.io/releases/redis-5.0.3.tar.gz
$ tar -xzf redis-5.0.3.tar.gz

进入 Redis 目录下,执行编译

$ cd redis-5.0.3
$ make
$ make install

二、批改配置文件

关上配置文件

$ cd redis-5.0.3
$ vim redis.conf

属性:bind

bind 127.0.0.1 #限度只有本机能够连贯 redis 服务连贯
bind 0.0.0.0   #容许任意计算机都能够连贯 redis 服务连贯 

属性:protected-mode

protected-mode yes #保护模式,需配置 bind ip 或者设置拜访明码
protected-mode no  #内部网络能够间接拜访 

属性:daemonize

daemonize no  #redis 在以后终端显示输入,并运行,exit 强制退出或者敞开连贯工具
daemonize yes #redis 在后盾运行,此时 redis 将始终运行,除非手动 kill 该过程 

属性:requirepass

# requirepass foobared #默认无明码
requirepass password   #看集体需要设置你喜爱得明码 

属性:logfile

logfile "" #默认无输入
logfile "/var/log/redis/6379.log" #看状况设置 

三、启动服务

将配置文件复制到指定为止

$ mkdir /etc/redis
$ cp /root/redis-5.0.3/redis.conf /etc/redis/redis.conf

命令行启动

$ redis-server

如下图所示胜利启动

后盾启动

$ redis-server /etc/redis/redis.conf

设置启动脚本

$ cat > /usr/lib/systemd/system/redis.service <<-EOF
[Unit]
Description=Redis 6379
After=syslog.target network.target
[Service]
Type=forking
PrivateTmp=yes
Restart=always
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/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
EOF

设置开机自启,并启动 Redis

$ systemctl daemon-reload #从新加载服务配置
$ systemctl enable redis  #设置开机自启动
$ systemctl start redis   #启动 redis 服务
$ systemctl status redis  #查看服务以后状态 

服务操作命令(扩大)

$ systemctl daemon-reload     #从新加载服务配置
$ systemctl enabl *.service   #设置 * 服务开机自启动
$ systemctl disabl *.service  #勾销 * 服务开机自启动
$ systemctl status *.service  #查看 * 服务状态
$ systemctl start *.service   #启动 * 服务
$ systemctl stop *.service    #进行 * 服务
$ systemctl restart *.service #重启 * 服务
$ systemctl reload *.service  #从新加载 * 服务配置 
正文完
 0