The purpose of this article is to familiarize yourself with the download, installation and use of redis, and prepare for the deployment of redis clusters later.
Download and install
- On linux, I am in
/download
the directory and execute the downloaded command
root@--- ~]# wget http://download.redis.io/redis-stable.tar.gz
- Next, perform the following operations on the downloaded file, unzip the file, and move the file to
/usr/local/redis/
the directory
tar -xzf redis-stable.tar.gz
mkdir -p /usr/local/redis
mv ./redis-stable/* /usr/local/redis/
- Compile redis file
cd /usr/local/redis
make
After the command is executed make
, the redis
compiled redis
service program redis-server
and the client program for testing will appear in the directory redis-cli
. The two programs are located in the installation src
directory
Start the redis service
- Method 1:
./redis-server
Note that starting redis in this way uses the default configuration.
- Method 2:
./redis-server ../redis.conf
Use the startup parameters to tell redis to use the specified configuration file to start using the following command.
redis.conf
is a default configuration file. We can use our own configuration files as needed.
After starting the redis service process, you can use the test client program to interact with the service redis-cli
. redis
Create another window to start the test client program, and then execute the following command in the new window:
cd /usr/local/redis/src
[root@--- src]# ./redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> exit
[root@--- src]#
Configure Redis as a background service
Change the configuration file redis.conf
to configure it to start in the background.daemonize no
daemonize yes
redis
Set Redis access password
redis.conf
Find it in the configuration file requirepass
, remove the previous comment, and modify the latter password.
Common configuration file example redis.conf
#默认端口6379
port 6379
#绑定ip,如果是内网可以直接绑定 127.0.0.1, 或者忽略, 0.0.0.0是外网
bind 0.0.0.0
#守护进程启动
daemonize yes
#超时
timeout 300
loglevel notice
#分区
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
#存储文件
dbfilename dump.rdb
#密码
requirepass xxxxxxxx