Introduction to Redis
Features of redis
redis installation
1. No matter what you install, first configure Alibaba’s yum source! Remember to install wget through yum first . The following is for CentOS7
wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-7.repo
2. Since redis is developed in C language, you need to download gcc before installing redis .
Note: The default gcc version of Centos 7 is 4.8. Sometimes a higher version is required. Here is an example of upgrading to version 9.3.1.
Just execute the following three commands respectively. There is no need to manually download the source code and compile it.
1. Install centos-release-scl
sudo yum install centos-release-scl
2. Install devtoolset. Note that if you want to install version 7, change it to devtoolset-7-gcc, and so on.
sudo yum install devtoolset-9-gcc*
3. Activate the corresponding devtoolset, so you can install multiple versions of devtoolset at one time. Use the following command to switch to the corresponding version when needed.
scl enable devtoolset-9 bash
4. Done, check the gcc version
gcc -v
3. Download the redis installation package. You can choose the stable version by yourself. Here we take version 6.0.8 as an example. The online download speed is slightly slower (you can also choose the offline download method) and you need to wait for about 6 minutes.
Online download method:
Specify download path:
cd /opt #进入opt目录
mkdir redis #创建redis目录
I have already installed it. The above is just to show you the specific operation commands.
Online download: Go to the created redis directory cd /opt/redis
wget http://download.redis.io/releases/redis-6.0.8.tar.gz
I have already installed it. The above is just to show you the specific operation commands.
Offline download method:
4. After downloading, decompress and compile
Note: The offline download method requires the downloaded package to be uploaded to the specified path using tools such as XShell or MobaXterm (you can specify it yourself, usually uploaded to /opt/redis). If you are not familiar with it, you can directly download it online. The compressed package is very small. Download soon
tar xzf redis-6.0.8.tar.gz
cd redis-6.0.8
make
5. Install redis to the specified directory
make PREFIX=/usr/local/redis install
6. After installation, test it
1. Start the redis service
redis-server #记得在/opt/redis/redis-6.0.8目录下执行该命令
2. At this time, you need to open another terminal to connect to the redis service
redis-cli #记得在/opt/redis/redis-6.0.8目录下执行该命令
After connecting to the client, ping it. If it enters PONG normally, the connection is successful.
Note: The above method of starting the redis service is to start it in the foreground, which will put the terminal in a blocked state. It is recommended to start the redis server in the backend. This requires the help of the configuration file redis.conf located in the redis decompression directory . It is recommended to copy the configuration file to the redis installation directory
cp /redis.conf /usr/local/redis/ #在redis所在的压缩包目录下执行该命令
1. redis默认不是后台运行的,可以通过修改该配置项为yes,让
redis在后台运行
daemonize no
2. 当redis以守护进程方式运行时,redis会把pid写
入/var/run/redis_6379.pid文件中,也可以自己指定写入的位置
pidfile /var/run/redis_6379.pid
3. redis监听的端口
port 6379
4. 设置redis连接密码,如果配置了连接密码,则客户端在连接redis
时需要通过AUTH <passowrd> 命令来提供密码
requirepass foobared
5. 绑定的主机地址,目前这样的配置这意味着只有当前机器才能连
接redis服务
bind 127.0.0.1
如果设置bind为0.0.0.0则表示运行任何远程机器访问当前redis服务
cd /usr/local/redis/ redis-server redis.conf
This time you can see that it is started in the background
Then use the redis client to connect to the redis service
redis-cli -h 192.168.195.130 -p 6379 #记得在/usr/local/redis目录下执行该命令
Here -h 192.168.195.130 can specify your own IP address (provided that the bind of the redis.conf configuration file is changed to 0.0.0.0) -p is followed by the port of the redis service
The above is the introduction and installation of redis. If you have any questions during the installation process, you can leave a message in the comment area to discuss. Tutorials on Linux installation of JDK, tomcat, mybatis, nginx, etc. will be published later. Thank you for previewing