[Database Redis] Installation and startup in Linux environment

I recently came into contact with Redis, one of the more popular NoSQL databases. Of course, this technology is now mature, but I haven’t had extensive contact with it in previous work and studies. Today, I will learn this technology from scratch. There are now technical blogs about Redis on the Internet. There are many, but the author thinks that some things can only be learned by personal experience.

Learning Redis requires an application environment. The author prepared Aliyun, server and Redis4.0.12 installation package as the basic platform for environment construction.

One, briefly introduce the Redis database

Redis is currently one of the more popular NOSQL systems. It is an open source key-value storage system written in ANSI c language (different from MySQL's two-dimensional table storage.). It is similar to Memcache, but it largely compensates for the shortcomings of Memcache. Like Memcache, Redis data is cached in computer memory. The difference is that Memcache can only cache data in memory and cannot automatically write to the hard disk regularly. This means that when the power is off or restarted, the memory is emptied and data is lost. . Therefore, the application scenario of Memcache is suitable for caching data that does not need to be persisted. The difference with Redis is that it periodically writes updated data to disk or writes modification operations to additional record files to achieve data persistence.

Features of Redis itself

  • Redis read speed is 110000 times/sec, write speed is 81000 times/sec
  • Atomicity: All Redis operations are atomic, and Redis also supports atomic execution of several operations after they are combined.
  • Support multiple data structures: string (String), list (List), hash (Hash), set (Set), ordered set (ZSet)
  • Persistence: Persistence, master-slave replication (cluster)
  • Support expiration time, transaction, message subscription
  • Window is not officially supported, but there can be a tripartite version

 

Two, Redis installation

This article only introduces the installation under the Linux system

1. Prepare the system environment (Alibaba Cloud Server Linux)

2. First download the installation package on the Redis official website at http://download.redis.io/releases/redis-4.0.12.tar.gz

3. Copy Redis-4.0.12.tar.gz to the Linux server through the remote management tools XShell and XFtp

4. Switch the file path and decompress the source file

cd /opt/soft_instation
tar zxvf redis-4.0.12.tar.gz

5. Use the make command to compile the redis decompressed file

cd redis-4.0.12.tar.gz
make

After the compilation is complete, you can see that there will be corresponding src, conf and other folders in the decompressed file redis-3.0.7. This is the same as the files installed and decompressed under windows. Most installation packages will have corresponding class files, configuration files and Some command files.

6. After the compilation is complete, enter the src folder and execute the make install command to install

cd src
make install

The above operation completes the installation of Redis

 

Three, environment configuration and service startup

1. Under normal circumstances, in order to facilitate management, Redis installation configuration files and commonly used command scripts are copied to a unified folder

  • Store commonly used commands /softfiles/redis/bin
  • Store configuration files /softfiles/redis/etc

Command to create a folder

mkdir -p /softfiles/redis/bin
mkdir -p /softfiles/redis/etc

File copy command

-- 配置文件copy
cd /opt/soft_instation/redis-4.0.12/
cp redis.config /softfiles/redis/etc

-- 常用命令copy
cd /opt/soft_instation/redis-4.0.12/src
cp redis-cli redis-server mkreleasehdr.sh redis-check-aof redis-check-rdb redis-benchmark /softfiles/redis/bin

 2. Modify the daemonize in the redis.config file to yes (default is no)

3. Start the redis service again and make the modified file

./redis-server /softfiles/redis/etc/redis.config

-- 查看服务启动
ps -A | grep redis

4. Simple test and use

Execute the redis-cli operation script, enter the redis operating environment, set the variable name and variable value in the form of key-value pairs, and then get the value through the variable name

-- 使用redis终端脚本
cd /softfiles/redis/bin
./redis-cli

-- 设置值
set redisTest RedisTest(设置值时候千万不要留有空格)

-- 取值
get redisTest

Guess you like

Origin blog.csdn.net/dgxin_605/article/details/85222519