Redis installation under Linux

Source: Internet
Author: User
Tags download redis redis server

1: Download Redis
  http://download.redis.io/releases/redis-3.0.2.tar.gz

2: Installing Redis
download and unzip the tar zxvf redis-3.0.2.tar.gz to any directory, such as/usr/local/redis-3.0.2


Yum groupinstall development Tool-Y

Yum install tcl-y #安装tcl, placing commands directly under/usr/bin when make

Cd/usr/local/redis-3.0.2.tar.gz #解压后, go to Redis directory


Make #不用./configure, directly execute make. Install to/usr/local by default (no matter where you unzip it)

Note: If you do not have TCL installed, you will be prompted hint:to run ' make test ' was a good idea; in fact, not test, generally can be used. However, to execute make test you must install TCL.

3: Copy files

CP redis.conf/etc/#将启动的配置文件拷到某个路径下 (can also be used without cuff)


CP Redis-benchmark REDIS-CLI redis-server/usr/bin/#将命拷到PATH路径下 and can be executed anywhere

Note: If TCL is installed in front of you, you do not have to copy the command to a path path.

4: Edit configuration file

Vim/etc/redis.conf #公司的主要配置

The main contents are as follows:

Daemonize Yes #设置redis进程为后台守护进程, default to No

Port 6379 #默认为6379

Dbfilename Dump.rdb #在redis. conf under the same path
Dir./#用命令config get dir to find the Redis directory

Bind x.x.x.x #监听的ip, intranet network can be, the intranet is more secure, the default is native (can be bound to many, then write on the line)

5: Set the memory allocation policy (optional, according to the actual situation of the server settings)

Vim/etc/sysctl.conf

Added: Vm.overcommit_memory=1 # If the memory situation is very tense, you need to set the kernel parameters
Or: Echo 1 >/proc/sys/vm/overcommit_memory


Note: The kernel parameters are described as follows:

The Overcommit_memory file specifies the kernel's policy for memory allocation, which can be 0, 1, 2.
0, indicates that the kernel will check for sufficient available memory to be used by the process, and if sufficient memory is available, the memory request is allowed; otherwise, the memory request fails and the error is returned to the application process.
1, which means that the kernel allows all physical memory to be allocated regardless of the current memory state.
2, which indicates that the kernel allows allocating more memory than the sum of all physical memory and swap space

6: Turn on the firewall

VIM/ETC/SYSCONFIG/IPTABLES 
   -A rh-firewall-1-input-m State--state new-m tcp-p TCP--dport 6379-j accept 

Service I Ptables restart   #重启

7: Start Redis service
redis-server/etc/redis.conf  # Because the command has been added to the path, it can be used anywhere.

Ps-ef | grep redis   #查看进程 to confirm that Redis has started  
  root       401 29222   0 18:06 pts/3    00:00:00 grep redis 
  root     29258      1  0 16:23?        00:00:00 redis-server/etc/redis.conf& nbsp

Note: If the Redis service fails to start here, generally because of a problem with the redis.conf file, it is recommended to check or find an available profile to overwrite, avoid detours, recommend, modify redis.conf, set up the Redis process as the daemon daemon

8: Test Redis
[[[email protected] redis-1.2.6] #pgrep-lf redis

14934 Redis-server 10.253.101.2:6379

[[email protected] redis-1.2.6]# redis-cli #redis-cli-h ip-p Port number
Redis> Set name Songbin #建值
Ok
Redis> Get name #获得内容
"Songbin"

Redis > select 0 #redis默认有16个库, switch with SELECT
Ok
Redis > SELECT 1
Ok
Redis > SELECT 0
Ok
Redis > Keys * #查看所有建值
1) "app_id"
2) "u_6039"
3) "u_6037"
4) "u_6035"
5) "u_6033"
Redis > Hgetall u_6039 #查看某个
1) "app_id"
2) "9999"
3) "School"
4) "1141"
Redis > Exit

10: Turn off Redis service
Law one: Using commands

REDIS-CLI shutdown
Note: After the Redis service is closed, the cached data is automatically dump to the hard disk, the hard disk address is the configuration item in redis.conf dbfilename Dump.rdb is set
To force backup data to disk, use the following command: REDIS-CLI Save or Redis-cli-p 6380 Save (Specify port)

Law II: Using scripts

Vim/etc/init.d/redis

#!/bin/bash
#
# Redis-this script starts and stops the Redis-server daemon
#
# Chkconfig:-80 12
# Description:redis is a persistent key-value database
# Processname:redis-server
# config:/usr/local/redis/etc/redis.conf
# Pidfile:/usr/local/redis/var/redis.pid

Source/etc/init.d/functions

Bin= "/usr/local/bin "#安装路径
Config= "/etc/redis.conf"
Pidfile= "/usr/local/redis/var/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

Service Redis Start #启动服务


This article is from the "Nobody Knows" blog, please be sure to keep this source http://cuixuemei.blog.51cto.com/8852728/1683467

Redis installation under Linux

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.