Installation and deployment of Redis under Linux (GO)

Source: Internet
Author: User
Tags download redis redis server value store

First, Redis Introduction

Redis is one of the most popular NoSQL systems today, and it is a key-value storage system. Similar to memcache, but largely compensates for the lack of memcache, which supports storing more value types, including string, list, set, Zset, and hash. These data types support Push/pop, Add/remove, and intersection sets and differences, and richer operations. Based on this, Redis supports sorting in a variety of different ways.
Like Memcache, Redis data is cached in the computer's memory, except that memcache can only cache data in memory and not automatically write to the hard disk periodically, which means that a power outage or restart, memory emptying, and data loss. So Memcache's application scenario is for caching data that does not need to be persisted. The difference between redis is that it periodically writes the updated data to the disk or writes the modified operation to the appended record file, which makes the data persistent.

Second, Redis the installation

The following is a description of the installation and deployment of Redis under the Linux environment

1, First officer network Download Redis compressed package, address: Http://redis.io/download Download stable version 3.0.7 can.

2, through the Remote management tool, the compressed package copy to the Linux server, to perform the decompression operation

3. Perform make to compile files after Redis decompression

After compiling, you can see that the extracted file redis-3.0.7 will have the corresponding SRC, conf and other folders, which is the same as installing the extracted files under Windows, most of the installation packages will have corresponding class files, configuration files and some command files.

4, after the successful compilation, enter the SRC folder, execute make install for Redis installation

5, the installation is complete, the interface is as follows

Third, Redis the deployment

After the installation is successful, Redis is deployed below

1 , first for the convenience of management, will Redis in the file conf configuration files and common commands are moved to the unified file

A) Creating Bin and redis.conf files

Copy the code code as follows:
Mkdir-p/usr/local/redis/bin
Mkdir-p/usr/local/redis/ect

b) Execute the Linux file Move command:

Copy the code code as follows:
Mv/lamp/redis-3.0.7/redis.conf/usr/local/redis/etc
Cd/lamp/redis-3.0.7/src
MV mkreleasdhdr.sh Redis-benchmark redis-check-aof redis-check-dump redis-cliredis-server/usr/local/redis/bin

2 , Execution Redis-server command, start Redis Service

Note: The Redis service, which executes the redis-server boot directly, is run directly in the foreground (as an effect), that is, if LUnix closes the current session after executing the command, the Redis service is closed. Under normal circumstances, starting the Redis service requires booting from the background and specifying a startup configuration file.

3 , background boot Redis Service

A) First edit the Conf file and change the Daemonize property to Yes (indicating that you need to run in the background)

CD etc/
Vi redis.conf

b) Start the Redis service again and specify the startup service profile

Redis-server/usr/local/redis/etc/redis.conf

4 , the server starts successfully, executes redis-cli Start Redis client, view the port number.

Vim/etc/init.d/redis

#!/bin/sh
#
#redis Startup script for Redis Server
#
# Chkconfig:-80 12
# Description:redis is an open source,advanced Key-value store.
#
# Processname:redis-server
# config:/etc/redis.conf
# Pidfile:/var/run/redis.pid
Source/etc/init.d/functions
Bin= "/usr/local/redis/bin"
Config= "/usr/local/redis/redis.conf"
Pidfile= "/var/run/redis.pid"
# # Read Configuration
[-R "$SYSCONFIG"] &&source "$SYSCONFIG"
Retval=0
Prog= "Redis-server"
desc= "Redis Server"
Start () {
if[-E $PIDFILE];then
echo "$desc already running ..."
Exit 1
Fi
Echo-n $ "Starting $desc:"
Daemon $BIN/$prog $CONFIG
Retval=$?
Echo
[$RETVAL-eq 0] && touch/var/lock/subsys/$prog
Return $RETVAL
}
Stop () {
Echo-n $ "Stop $desc:"
Killproc $prog
Retval=$?
Echo
[$RETVAL-eq 0] && rm-f/var/lock/subsys/$prog $PIDFILE
Return $RETVAL
}
Restart () {
Stop
Start
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Restart
;;
Condrestart)
[-e/var/lock/subsys/$prog] && restart
Retval=$?
;;
Status
Status $prog
Retval=$?
;;
*)
echo $ "Usage: $ {Start|stop|restart|condrestart|status}"
Retval=1
Esac
Exit $RETVAL

chmod +x/etc/init.d/redis

Service Redis Start
Service Redis Stop

Chkconfig--add Redis

To modify a profile:

# Vi/etc/profile

In the last line add:

Export path= "$PATH:/usr/local/redis/bin"

Then apply this file immediately:

# . /etc/profile

Configure the following kernel parameters, or the Redis script will error when restarting or stopping Redis, and cannot automatically synchronize data to disk before stopping the service/etc/sysctl.conf Plus

#vim/etc/sysctl.conf

Vm.overcommit_memory = 1

#sysctl-P

Iv. Summary Linux , Redis Operations Common Commands

Linux :

Cd/usr from subfolders into parent folder usr
CD local from parent to child
mv/a/b Moves file A to B
VI usr/local/redis/redis.conf Edit redis.conf file
: Wq Save the changes and exit

Redis :

redis-server/usr..../redis.conf start the Redis service and specify the configuration file
REDIS-CLI starting the Redis client
Pkill redis-server off Redis service
REDIS-CLI Shutdown Close Redis Client
Netstat-tunpl|grep 6379 View Redis default port number 6379 occupancy

4. Configuration of Redis

4.1.Redis default is not run as daemon, can be modified by this configuration item, use Yes to enable daemon

daemonize No

4.2. When Redis is running as a daemon, Redis writes the PID to the/var/run/redis.pid file by default and can be specified by pidfile

Pidfile/var/run/redis.pid

4.3. Specify the Redis listening port, the default port is 6379, the author in his own article blog post explains why 6379 as the default port, because 6379 Merz the corresponding number on the phone keypad, and Merz from Italy showgirl Alessiamerz name

Port 6379

4.4. The host address of the binding

bind127.0.0.1

4.5. If the client closes the connection after a long period of inactivity, if it is specified as 0, the function is turned off

Timeout

4.6. Specify logging level, Redis supports four levels in total: Debug, verbose, notice, warning, default is verbose

Loglevelverbose

4.7. Logging mode, default to standard output, if Redis is configured to run as daemon, and this is configured as logging mode as standard output, the log will be sent to/dev/null

Logfilestdout

4.8. Set the number of databases, the default database is 0, you can use the select<dbid> command to specify the database ID on the connection

databases

4.9. Specify how many times the update operation will synchronize the data to the data file and can be combined with multiple conditions

save<seconds> <changes>

There are three conditions available in the Redis default configuration file:

Save 1

save300 Ten

save60 10000

Represents 1 changes in 900 seconds (15 minutes), 5 changes in 300 seconds (10 minutes), and 60 changes in 10,000 seconds.

4.10. Specify whether to compress the data when storing to the local database, the default is Yes,redis with LZF compression, if you want to save CPU time, you can turn off this option, but it will cause the database file to become huge

Rdbcompressionyes

4.11. Specify the local database file name, the default value is Dump.rdb

Dbfilenamedump.rdb

4.12. Specify the local database to hold the directory

dir./

4.13. Set the IP address and port of the master service when this machine is a Slav service, and it will automatically synchronize data from master when Redis boots

slaveof<masterip> <masterport>

4.14. When the master service is password protected, the Slav service connects the password of master

masterauth<master-password>

4.15. Set the Redis connection password, if the connection password is configured, the client needs to provide the password via the auth<password> command when connecting to Redis, which is turned off by default

requirepassfoobared

4.16. Set the maximum number of client connections at the same time, the default is unlimited, Redis can open the number of client connections for the Redis process can open the maximum number of file descriptors, if set maxclients 0, indicating no restrictions. When the number of client connections reaches the limit, Redis closes the new connection and returns MaxNumber of clients reached error message to the client

maxclients128

4.17. Specify the maximum Redis memory limit, Redis will load the data into memory when it is started, Redis will first try to clear the expired or expiring key, when this method processing, still reach the maximum memory settings, will no longer write operations, However, the read operation can still be performed. Redis new VM mechanism will store key memory, value will be stored in swap area

maxmemory<bytes>

4.18. Specifies whether logging occurs after each update operation, which, by default, writes data to disk asynchronously and, if not turned on, may result in data loss over a period of time when power is lost. Because the Redis itself synchronizes data files in sync with the save conditions above, some data will only exist in memory for a period of time. Default is No

appendonly No

4.19. Specify the update log file name, default to Appendonly.aof

appendfilenameappendonly.aof

4.20. Specify the update log condition, a total of 3 optional values:
No: Indicates that the data cache of the operating system is synchronized to disk (fast)
always: Represents a manual call to Fsync () to write data to disk (slow, secure) after each update operation
everysec: Indicates synchronization once per second (trade-offs, default values)

Appendfsync everysec

4.21. Specify whether to enable the virtual memory mechanism, the default value is no, a simple introduction, the VM mechanism to store data paging, by Redis will be less accessible pages, such as cold data swap to disk, Access to multiple pages is automatically swapped out into memory by the disk (in a later article I will carefully analyze the Redis VM mechanism)

vm-enabled No

4.22. Virtual memory file path, default value is/tmp/redis.swap, cannot be shared by multiple Redis instances

Vm-swap-file/tmp/redis.swap

4.23. Store all data greater than vm-max-memory in virtual memory, regardless of the vm-max-memory settings, all index data is memory stored (REDIS index data is keys), that is, When Vm-max-memory is set to 0, all value is actually present on the disk. The default value is 0

vm-max-memory0

4.24.Redis swap file is divided into a lot of page, an object can be saved on more than one page, but a page can not be shared by multiple objects, Vm-page-size is based on the size of the stored data to set, the author suggests that if you store many small objects, The page size is best set to 32 or 64bytes, and if you store large objects, you can use a larger page, and if you are unsure, use the default values

vm-page-size32

4.25. Set the number of pages in the swap file, since the page table (a bitmap that indicates that the page is idle or used) is in memory and consumes 1byte of memory per 8 pages on disk.

vm-pages134217728

4.26. Set the number of threads to access swap files, preferably do not exceed the machine's core number, if set to 0, then all the swap file operation is serial, may cause a relatively long delay. The default value is 4

VM-MAX-THREADS4

4.27. Set when replying to the client, whether to merge the smaller package into one package send, the default is to turn on

Glueoutputbufyes

4.28. Specifies that a special hashing algorithm is used when more than a certain number or maximum element exceeds a critical value

Hash-max-zipmap-entries64

hash-max-zipmap-value512

4.29. Specify whether to activate the reset hash, which is on by default (described later in the introduction of the Redis hashing algorithm)

Activerehashingyes

4.30. Specify other profiles that can use the same configuration file across multiple Redis instances on the same host, while each instance has its own specific configuration file

include/path/to/local.conf

The above part from the network blog, I did some summary

Installation and deployment of Redis under Linux (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.