Redis compile installation and saltstack simple configuration

Source: Internet
Author: User
Tags memory usage redis redis version redis cluster redis server saltstack

The-redis of distributed storage
Redis is commonly used for database read caching and write caching, usually write caching needs to consider the problem of data consistency, read cache application more
Redis is an open-source, Key-value database that is written in C and that supports network interaction and can be based on memory and persistence

Currently the largest Redis cluster in China--Sina Weibo

Comparison of Redis and memcached

[Root@yum-down local]# wget http://download.redis.io/releases/redis-3.0.7.tar.gz
[Root@yum-down local]# Tar XF redis-3.0.7.tar.gz
[Root@yum-down local]# CD redis-3.0.7
[Root@yum-down redis-3.0.7]# make Prefix=/usr/local/redis Install
[Root@yum-down utils]# CP Redis_init_script/etc/init.d/redis
[Root@yum-down utils]# chmod +x/etc/init.d/redis
Modify the installation path in the script

[Root@yum-down utils]# Vim/etc/init.d/redis
Exec=/usr/local/redis/bin/redis-server
Cliexec=/usr/local/redis/bin/redis-cli
Create a profile path and copy the configuration file to name the port number

[Root@yum-down redis-3.0.7]# Mkdir/etc/redis
[Root@yum-down redis-3.0.7]# cp/usr/local/redis-3.0.7/redis.conf/etc/redis/6379.conf
First boot, if no modification is initiated at the foreground page

[Root@yum-down ~]#/etc/init.d/redis start
Starting Redis server ...
5228:m Feb 07:16:27.342 * Increased maximum number of open files to 10032 (it is originally set to 1024).
_._
_.-``__ ''-._
_.-``    `.  `_. "'-._ Redis 3.0.7 (00000000/0) bit
.-`` .-```. ```\/    _.,_ ''-._
(    '      ,       .-`  | `,    ) Running in standalone mode
|`-._`-...-` __...-.``-._|'     ` _.-'| port:6379
|     `-._   `._    /     _.-'    | pid:5228
`-._    `-._  `-./  _.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|           `-._`-._        _.-'_.-'    | Http://redis.io
`-._    `-._`-.__.-'_.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
| `-._`-._        _.-'_.-'    |
`-._    `-._`-.__.-'_.-'    _.-'
`-._    `-.__.-'    _.-'
`-._        _.-'
`-.__.-'

5228:m Feb 07:16:27.344 # warning:the TCP Backlog setting of 511 cannot be enforced BECAUSE/PROC/SYS/NET/CORE/SOMAXCO NN is set to the lower value of 128.
5228:m Feb 07:16:27.344 # Server started, Redis version 3.0.7
5228:m Feb 07:16:27.344 # WARNING Overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ' vm.overcommit_memory = 1 ' to/etc/sysctl.conf and then reboot or run the command ' Sysctl vm.overcom Mit_memory=1 ' for this to take effect.
5228:m Feb 07:16:27.344 # WARNING You have transparent Huge Pages (THP) support be enabled in your kernel. This would create latency and memory usage issues with Redis. To fix this issue run the command ' echo never >/sys/kernel/mm/transparent_hugepage/enabled ' as root, and add it to you R/etc/rc.local in order to retain the setting after a reboot. Redis must be restarted the THP is disabled.
5228:m Feb 07:16:27.344 * The server is now ready to accept connections on port 6379
^c5228:signal-handler (1456327043) Received SIGINT scheduling shutdown ...
5228:m Feb 07:17:23.607 # User requested shutdown ...
5228:m Feb 07:17:23.607 * Saving final RDB snapshot before.
5228:m Feb 07:17:23.611 * DB saved on disk
5228:m Feb 07:17:23.611 # Redis is now ready to exit, Bye bye ...
Modify configuration file ' daemonize to Yes '

[Root@yum-down ~]# vim/etc/redis/6379.conf
Daemonize Yes
Modify PID and/etc/init.d/redis in the same

Pidfile/var/run/redis_6379.pid
[Root@yum-down ~]#/etc/init.d/redis start
starting Redis server ...
[Root@yum-down ~]# netstat-ntlp |grep redis
tcp        0       0 0.0.0.0:6379                 0.0.0.0:*                    listen      5235/redis-server
tcp         0      0:::6379                     :::*                          listen      5235/redis-server
Close test

[Root@yum-down ~]# service Redis stop
Stopping ...
Redis stopped
[Root@yum-down ~]#
Do a soft connection start:

[Root@yum-down ~]# ln-s/USR/LOCAL/REDIS/BIN/REDIS-CLI/USR/LOCAL/BIN/REDIS-CLI
[Root@yum-down ~]# Redis-cli
127.0.0.1:6379>
Because the Redis is single-threaded, can only use one CPU, may start multiple, you can specify IP and port

[Root@yum-down ~]# redis-cli-h 10.10.0.250-p 6379
10.10.0.250:6379>
Simple to use:
Set insert String, get view

[Root@yum-down ~]# redis-cli-h 10.10.0.250-p 6379
10.10.0.250:6379> Set KeyName Hello
Ok
10.10.0.250:6379> Get KeyName
"Hello"
10.10.0.250:6379>
Filter:
Show All

10.10.0.250:6379> keys *
1) "Keya"
2) "Keyna"
3) "KeyName1"
4) "KeyName"
Match KeyName Start

10.10.0.250:6379> keys KeyName?
1) "KeyName2"
2) "KeyName1"
10.10.0.250:6379>
Determine whether the key exists, 0 does not exist, not 0 exist, indicating quantity

10.10.0.250:6379> EXISTS Keya
(integer) 1
10.10.0.250:6379> EXISTS KEYA1
(integer) 0
10.10.0.250:6379>
Delete: 0 does not exist, non 0 exists, indicating quantity

10.10.0.250:6379> DEL Keya
(integer) 1
10.10.0.250:6379> DEL Keya
(integer) 0
10.10.0.250:6379>
Info

# Keyspace
Db0:keys=2,expires=0,avg_ttl=0
Db0: Example
as follows: SELECT 1 and 22 instances, insert data separately

10.10.0.250:6379[2]> SELECT 1
Ok
10.10.0.250:6379[1]> SELECT 2
Ok
10.10.0.250:6379[2]> SET 1 1
Ok
10.10.0.250:6379[2]> SELECT 1
Ok
10.10.0.250:6379[1]> SET 1 1
Ok
There are 1 and 2 instances of using the info view

# Keyspace
Db0:keys=2,expires=0,avg_ttl=0
Db1:keys=1,expires=0,avg_ttl=0
Db2:keys=1,expires=0,avg_ttl=0
Flushall to empty all instances

10.10.0.250:6379[1]> Flushall
Number of Keys:key
Expires: Expired Quantity
Number of Avg_ttl:ttl

Simple configuration file Description:

[Root@yum-down ~]# egrep-v "^#|^$"/etc/redis/6379.conf
Daemonize yes before and after the table starts
Pidfile/var/run/redis.pid PID Position
Port 6379 Ports
LogFile "" Log
Dir./Directory of Startup
[Root@yum-down ~]#
Redis-saltstack Configuration
1, copy installation package to salt/redis/files/
2, copy configuration file to salt/redis/files/
3, copy startup script to salt/redis/files/directory, no to create;
Install.sls is as follows:

File.managed:
-Name:/usr/local/src/redis-3.0.7.tar.gz
-Source:salt://redis/files/redis-3.0.7.tar.gz
-User:root
-Group:root
-mode:755
Cmd.run:
-Name:cd/usr/local/src && Tar XF redis-3.0.7.tar.gz && cd redis-3.0.7 && Prefix=/usr/local/redi s Install
-Unless:test-d/usr/local/redis
Redis-config:
File.managed:
-Name:/etc/redis/6379.conf
-Spurce:salt://redis/files/6379.conf
-User:root
-Group:root
-mode:644
Redis-service:
File.managed:
-Name:/etc/init.d/redis
-Source:salt://redis/files/redis.init
-User:root
-Group:root
-mode:755
Cmd.run
-Name:chkconfig--add Redis && chkconfig Redis on
-Unless:chkconfig--list |grep Redis
Service.runnig:
-Name:redis
-Emable:true
-Watch:
-File:redis-config
-Require:
-Cmd:redis-install
-Cmd:redis-service

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.