一、Redis安装
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
想下载哪个版本可以复制上面链接删除redis-*部分内容,执行之后,在当前cd的目录下生成index.html文件,打开可以查看到所有redis版本
1、解压安装包到目录:
tar -zxvf redis-4.0.9.tar.gz -C /usr/local/
2、安装依赖gcc
先通过gcc -v是否有安装gcc,如果没有安装,执行命令:
sudo yum install -y gcc
3、编译安装:
转到解压目录下cd /usr/local/redis-4.0.9/ 执行:
make MALLOC=libc
和命令:
cd src && make install
4、启动redis
在redis-4.0.9目录下执行:
./src/redis-server
看到如下画面表示成功:
[root@localhost redis]# ./src/redis-server
2420:C 12 Sep 19:31:36.344 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2420:C 12 Sep 19:31:36.344 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=2420, just started
2420:C 12 Sep 19:31:36.344 # Warning: no config file specified, using the default config. In order to specify a config file use ./src/redis-server /path/to/redis.conf
2420:M 12 Sep 19:31:36.347 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2420
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
2420:M 12 Sep 19:31:36.350 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2420:M 12 Sep 19:31:36.350 # Server initialized
想要停止的话直接ctrl+c
后台启动:./src/redis-server ./redis.conf
5、修改配置,根据需要修改
vi redis.conf
支持远程:
注释掉bind 127.0.0.1 改为bind 0.0.0.0
支持后台启动
将
daemonize no
修改为
daemonize yes
6、查看进程
ps -aux|grep redis-server
[root@localhost utils]# ps -aux|grep redis-server
root 2541 0.2 0.1 141812 1984 ? Ssl 19:39 0:01 /usr/local/bin/redis-server *:6379
root 2596 0.0 0.0 112720 972 pts/0 S+ 19:48 0:00 grep --color=auto redis-server
二、添加开机启动服务
执行
./utils/install_server.sh
将添加服务,其中可以设置参数,我选择默认:
[root@localhost utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
安装服务成功可以执行
systemctl status redis_6379查看状态;
systemctl start redis_6379开启
systemctl stop redis_6379停止等
redis_6379不方便记忆,可修改文件名为redis:
mv /etc/init.d/redis_6379 /etc/init.d/redis
然后systemctl daemon-reload使生效,
就可以直接使用systemctl status redis等命令。
注意添加systemctl管理之前修改配置文件,执行./utils/install_server.sh后生成的配置文件:/etc/redis/6379.conf 和原修改后的配置是同步的。