安装
1 ## 官网下载源码
2 ##安装依赖包
yum install gcc tcl
3## 下载源码包
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
4 ##解压安装
tar -xf redis-4.0.10.tar.gz
cd redis-4.0.10
make && make install
5 ##配置 redis
mkdir /etc/redis
cd redis-4.0.10/
cp redis.conf /etc/redis/6379.conf
守护进程的方式启动服务时,即使执行启动服务命令的终端关闭,服务仍然可以在后台运行。
配置 centos7 systemd 管理 redis 服务
在/lib/systemd/system目录下创建一个脚本文件redis.service,里面的内容如下:
[Unit]
Description=Redis
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/redis-server /etc/redis/6379.conf --daemonize no
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown
[Install]
WantedBy=multi-user.target
[Unit] 表示这是基础信息配置块
Description 是描述
After 开启自启动时候的顺序, 指定的服务必须先于次此服务启动,一般是网络服务启动后启动
[Service] 表示这里是服务信息配置块
Type 指定启动服务的类型, simple 是默认的方式
EnvironmentFile 指定服务启动时用到的配置文件
ExecStart 是启动服务的命令
ExecStop 是停止服务的指令
[Install] 表示这是是安装信息配置块
WantedBy 是以哪种方式启动:multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行。
授权在主机启动的时候同时启动服务
创建两个文件
mkdir /redis/logs
配置文件/etc/redis/63779.conf
先搜索 /dbfilename
修改为 dir "/redis/data"
搜索 /logs
修改为 logfile "/redis/logs/6379.log”
搜索 /bind
注释掉这一行 # bind 127.0.0.1 192.168.1.10
注意此配置项可能在 71 行左右。默认是 bind 127.0.0.1
刷新配置,让 systemd 识别刚刚添加的 redis 服务
systemctl daemon-reload
启动服务
systemctl start redis
systemctl enable redis
或手动用命令指定配置文件启动
/usr/local/bin/redis-sever /etc/redis/6379.cof
检查默认端口 6379 是否监听
设置使用守护进程都方式运行服务
需要编辑配置文件 /etc/redis/6379.conf
daemonize yes # 守护进程的方式启动服务
客户端指定端口访问
redis-cli -p 6379
手动停止服务
redis-cli -p 6379 shutdown
假如重启后出现如下错误信息,就按照提示操作
1044:M 27 Feb 14:47:21.993 # Server initialized
1044:M 27 Feb 14:47:21.993 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1044:M 27 Feb 14:47:21.993 # Short read or OOM loading DB. Unrecoverable error, aborting now.
1044:M 27 Feb 14:47:21.993 # Internal error in RDB reading function at rdb.c:1666 -> Unexpected EOF reading RDB file
网友评论