Redis installation/Ubuntu18.04

Introduction of Redis

Redis is an open source (BSD licensed) in-memory data structure stored as a database, cache and message broker. Redis provides data structures such as strings, hashes, lists, collections, sorted collections with range queries, bitmaps, hyperlogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of disk persistence, and provides high availability through automatic partitioning of The Redis Sentinel and Redis Cluster.

Redis website

https://redis.io/

Official Installation Tutorial

Compile environment Installation

Redis is written in C/C++, so compiling from source to executable requires a C/C++ compiler and a Make toolchain

#Install GCCroot@DESKTOP:/usr/local# apt install gcc Reading package lists... Done Building dependency tree Reading state information... Done GCC is already the newest version (4:7.4.0-1Ubuntu2.3). The following packages were automatically installed and are  no longer required: Git-man golang-1.10-src liberror-perl Use 'apt autoremove' toremove them. 0 Upgrade, 0 newly installed, 0 to remove and 90 not upgraded.#Install the g + +root@DESKTOP:/usr/local# apt install g++ Reading package lists... Done Building dependency tree Reading state information... Done g++ is already the newest version (4:7.4.0-1ubuntu2.3).#g++ is the newest version the following packages were automatically installed and are no longer required: Git-man golang-1.10-src liberror-perl Use 'apt autoremove' toremove them. 0 Upgrade, 0 newly installed, 0 to remove and 90 not upgraded.#Install the makeroot@DESKTOP:/usr/local# apt install make Reading package lists... Done Building dependency tree Reading state information... Done make is already the newest version (4.1-9.1ubuntu1). # Make is the newest version the following packages were automatically installed and are no longer required: Git-man golang-1.10-src liberror-perl Use 'apt autoremove' toremove them. 0 Upgrade, 0 newly installed, 0 to remove and 90 not upgraded.Copy the code

Compile the installation

Root @ DESKTOP: / usr/local/SRC/REDIS# ls redis - 6.2.3. Tar. Gz root @ DESKTOP: / usr/local/SRC/REDIS# tar XVF - redis - 6.2.3. Tar. Gz Root @ # decompression DESKTOP: / usr/local/SRC/REDIS# redis - 6.2.3 / root @ DESKTOP: CD/usr/local/SRC/redis/redis - 6.2.3 # make # compiling redis Root @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 # make install REDIS server REDIS - cli # REDIS - benchmark installed to the specified directoryCopy the code

Custom configuration files

#Creating a Configuration DirectoryRoot @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 # mkdir MYCONF#Copy the /redis-6.2.3/redis.conf redis server configuration file to MYCONFRoot @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 # cp REDIS. Conf MYCONF /Copy the code

Modifying a Configuration File

Root @ DESKTOP: / usr/local/SRC/REDIS CD MYCONF/root/REDIS - 6.2.3 # @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 / MYCONF# vim redis.confCopy the code

Redis does not start in the background by default. If you normally want it to start in the background, change it as follows:

daemonize no
#Modified to
daemonize yes
Copy the code

By default, Redis does not have a login password, and the official password configuration section is commented, and the corresponding password is added for security reasons:

#requirepass foobared
#Modified to
requirepass wsharkcoder
#The password is wsharkcoder

### Redis server started

​``` shell
#Boot mode: redis-server < profile >Root @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 / MYCONF# REDIS server/usr/local/SRC/REDIS/REDIS - 6.2.3 / MYCONF/REDIS. Conf#Check whether the process is startedRoot @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 / MYCONF# ps - ef | grep - e REDIS 11797 0 any root of 16388? 00:00:00 redis - server 127.0.0.1:6379Copy the code

The Redis built-in client connects to the Redis server

#Connection mode :redis-cli -h < host > -p < port > -A < password >Redis - cli - h localhost -p 6379 - a wsharkcoder root @ DESKTOP: / usr/local/SRC/redis/redis - 6.2.3 / MYCONF# redis - cli - h localhost -p 6379 -a wsharkcoder#No security
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
localhost:6379>
Copy the code

Close the Redis

#Redis- you can use shutdown to shutdown the cli connectionLocalhost: 6379 > shutdown not connected > root @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 / MYCONF# ps - ef | grep - e REDIS root  17824 11798 0 18:41 pts/0 00:00:00 grep --color=auto -e redisCopy the code

The startup script

#Simple script startupRoot @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 # touch Start_Redis. Sh # create startup scripts Root @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 # vim Start_Redis. Sh # editor startup scripts root @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 # Cat start_redis. sh # Check the startup script content#! /bin/bashRedis - server. / MYCONF/redis. Conf root @ DESKTOP: / usr/local/SRC/redis/redis - 6.2.3 # chmod u + x Start_Redis. Sh # given startup scripts execute permissions Root @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 #. / Start_Redis sh # script to start the root @ DESKTOP: / usr/local/SRC/REDIS/REDIS - 6.2.3 # ps - ef | grep - e # redis root 19201 11797 0 18:48 retrieval process? 00:00:00 redis-server 127.0.0.1:6379 root 19228 11798 0 18:48 PTS /0 00:00:00 grep --color= auto-e redisCopy the code

Shell scripts and commands are the same. More convenient script way, learned to use in the future and then add, hey hey ~

conclusion

Here is the source code compilation of the installation, we know that the Linux platform installation software also includes the use of package management software, the way is relatively simple will not repeat the introduction! If you think my article is helpful to you, give me a thumbs up!