1. Install redis
1. Go to the official website to download the latest version of redis, I downloaded 3.0.3
2. Copy redis-3.0.3 to the /usr/local directory
3. Unzip sudo tar -zxf redis-3.0.3.tar.gz
4. Enter the decompressed directory cd redis-3.0.3
5. Compile and test: sudo make test
6. Compile and install: sudo make install
7. Start the service: ./redis-server
(PS: This interface reminds me of Knight's Xing, a Mud (MUD) game I played in 1999) At this point there is a warning that there is no configuration file. We need to make a progress configuration.
Two, placement
Configuration:
1. Create a directory redis under /usr/local/. Create bin, etc, db three directories in the redis directory
sudo mkdir /usr/local/redis/bin
....
2. Copy mkreleasehdr.sh, redis-benchmark, redis-check-dump, redis-cli, redis-server in the src directory to
bin directory
sudo mv /usr/local/redis3.0.3/mkreleasehdr.sh /usr/local/redis/mkreleasehdr.sh
......
3. Under etc, refer to the redis.conf in the original redis3.0.3 directory, and create a new redis.conf
cd /usr/local/redis/etc
vim redis.conf
Modify redis.conf as follows:
#Modify to guard mode
daemonize=yes
#Set the process lock file
pidfile /usr/local/redis/redis.pid
#port
port 6379
#Client timeout
timeout 300
# log level
loglevel debug
#log file location
logfile /usr/local/redis/log-redis.log
#设置数据库的数量,默认数据库为0,可以使用SELECT <dbid>命令在连接上指定数据库id
databases 8
##指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合
#save <seconds> <changes>
#Redis默认配置文件中提供了三个条件:
save 900 1
save 300 10
save 60 10000
#指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,
#可以关闭该#选项,但会导致数据库文件变的巨大
rdbcompression yes
#指定本地数据库文件名
dbfilename dump.rdb
#指定本地数据库路径
dir /usr/local/redis/db/
#指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能
#会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的,所以有
#的数据会在一段时间内只存在于内存中
appendonly no
#指定更新日志条件,共有3个可选值:
#no:表示等操作系统进行数据缓存同步到磁盘(快)
#always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)
#everysec:表示每秒同步一次(折衷,默认值)
appendfsync everysec
4、如果用户不是root,那么为了减少麻烦,可以将目录的所有者修改为本人:
chown -R xxxx redis
5、保存后,启动redis
./bin/redis-server etc/redis.conf
6. View log files
tail -f log-redis.log
At this point, redis installation and configuration are complete! Ready to try.