Redis Server Installation configuration under Linux

Source: Internet
Author: User
Tags allkeys install redis redis server

Description
Operating system: CentOS
1. Install the Compilation tool
Yum install wget make gcc gcc-c++ zlib-devel OpenSSL openssl-devel pcre-devel kernel keyutils Patch Perl


2. Install TCL package (requires TCL support to install Redis)
CD/USR/LOCAL/SRC #进入软件包存放目录
wget http://downloads.sourceforge.net/tcl/tcl8.6.6-src.tar.gz
Tar zxvf tcl8.6.6-src.tar.gz #解压
CD tcl8.6.6 #进入安装目录
CD UNIX
./configure--prefix=/usr--without-tzdata--mandir=/usr/share/man $ ([$ (uname-m) = x86_64] && echo--enabl E-64bit) #配置
Make #编译
Sed-e "[Email protected]^\ (tcl_src_dir= '). *@\1/usr/include ' @"-e "/tcl_b/[email protected]= ' \ (-l\) \?. *[email protected]= ' \1/usr/[email protected] "-I tclconfig.sh
Make install #安装
Make Install-private-headers
Ln-v-SF Tclsh8.6/usr/bin/tclsh
Chmod-v 755/usr/lib/libtcl8.6.so


3. Installing Redis
Cd/usr/local/src
wget http://download.redis.io/redis-stable.tar.gz
TAR-ZXVF redis-stable.tar.gz #解压
MV Redis-stable/usr/local/redis #移动文件到安装目录
Cd/usr/local/redis #进入安装目录
Make && make install #安装
Cd/usr/local/bin #查看是否有下面文件, if not, copy the following file to the/usr/local/bin directory
Cd/usr/local/redis
Mkdir-p/usr/local/bin
Cp-p Redis-server/usr/local/bin
Cp-p Redis-benchmark/usr/local/bin
Cp-p Redis-cli/usr/local/bin
Cp-p Redis-check-dump/usr/local/bin
Cp-p Redis-check-aof/usr/local/bin
Ln-s/usr/local/redis/redis.conf/etc/redis.conf #添加配置文件软连接
Vi/etc/redis.conf #编辑
Daemonize Yes #设置后台启动redis
: wq! #保存退出
Redis-server/etc/redis.conf #启动redis服务
REDIS-CLI shutdown #关闭redis
Vi/etc/sysctl.conf #编辑, add the following code to the last line
Vm.overcommit_memory = 1
: wq! #保存退出
Sysctl-p #使设置立即生效


4. Set up Redis boot
Vi/etc/rc.d/init.d/redis #编辑, add the following code

#!/bin/sh# chkconfig:2345 10# Description:redis is a persistent key-value database# Redis Startup script for re Dis processes# processname:redisredis_path= "/usr/local/bin/redis-server" redis_conf= "/etc/redis.conf" redis_pid= "/ Var/run/redis.pid "# Source function library. /etc/rc.d/init.d/functions[-x $redis _path] | | Exit 0retval=0prog= "Redis" # Start Daemons.start () {If [-e $redis _pid-a!-Z $redis _pid];thenecho $prog "already running "Exit 1fiecho-n $" Starting $prog "# Single instance for all Caches$redis_path $redis _confretval=$? [$RETVAL-eq 0] && {touch/var/lock/subsys/$progsuccess $ "$prog"}echoreturn $RETVAL}# Stop daemons.stop () {echo -N $ "stopping $prog" killproc-d $redis _pathecho[$RETVAL = 0] && rm-f $redis _pid/var/lock/subsys/$progRETVA L=$?return $RETVAL}# See how we were Called.case "$" instart) start; stop) stop;; Status) status $progRETVAL =$?;; restart) Stopstart;; Condrestart) if test "x ' pidof redis '"! = x; Thenstopstartfi;; *) echo $ "USAGE: $ {Start|stop|status|restart|condrestart} "exit 1esacexit $RETVAL 

: wq! #保存退出
chmod 755/etc/init.d/redis #添加脚本执行权限
Chkconfig--add Redis #添加开启启动
Chkconfig--level 2345 Redis on #设置启动级别
Chkconfig--list Redis #查看启动级别
Service Redis Restart #重新启动redis

5. Setting Redis profile Parameters
Mkdir-p/usr/local/redis/var #创建redis数据库存放目录
Vi/etc/redis.conf #编辑

Daemonize Yes  #以后台daemon方式运行redispidfile "/var/run/redis.pid"  #redis以后台运行, default PID file path/var/run/ Redis.pidport 6379  #默认端口bind 127.0.0.1 #默认绑定本机所有ip地址, in order to be safe, can only monitor the intranet Iptimeout #客户端超时设置, the unit is seconds loglevel verbose  #设置日志级别, support four levels: Debug, notice, verbose, warninglogfile stdout  #日志记录方式, default to standard output, logs not write file, output to empty device/deb/ Nulllogfile "/usr/local/redis/var/redis.log"  #可以指定日志文件路径databases  #开启数据库的数量save 1save 10save 60 10000 Create a local database snapshot, format: Save * * 900 seconds, perform 1 write operations within 300 seconds, perform 10 write operations within 60 seconds, perform 10,000 writes rdbcompression Yes #启用数据库lzf压缩, can also be set to Nodbfilename Dump.rdb  #本地快照数据库名称dir "/usr/local/redis/var/"   #本地快照数据库存放目录requirepass 123456  # Set the Redis database connection password maxclients 10000 #同一时间最大客户端连接数, 0 is an unrestricted maxmemory 1024MB #设定redis最大使用内存, the value is less than the physical memory, you must set the appendonly Yes  #开启日志记录, equivalent to the MySQL binlogappendfilename "appendonly.aof"   #日志文件名, note: Not the directory path Appendfsync everysec #每秒执行同步, There are also two parameters always, no is generally set to everysec, the equivalent of the MySQL thing log writing method

: wq! #保存退出
Service Redis Restart #重启


6. Test Redis Database
Redis-cli-a 123456 #连接redis数据库, note:-A followed by a Redis database password
Set name Osyunwei.com #写数据
Get name #读取数据
Exit #退出redis数据库控制台
Redis-benchmark-h 127.0.0.1-p 6379-c 1000-n 100000 #1000个并发连接, 100,000 requests, testing Redis server performance with 127.0.0.1 Port 6379


7. Connect to Redis Database via PHP program #php必须先安装Redis扩展
Redis Database ip:192.168.21.128
Port: 6379
Password: 123456
Test code:
<?php
$redis = new Redis ();
$redis->connect (' 192.168.21.128 ', 6379);
$redis->auth (' 123456 ');
$redis->select (1);
$ret = $redis->set (' www.osyunwei.com ', ' Osyunwei ');
Var_dump ($ret);
$allKeys = $redis->keys (' * ');
Print_r ($allKeys);
?>
Save the above code as test.php, and the following page will appear after opening
BOOL (TRUE) Array ([0] = www.osyunwei.com)


At this point, the Redis Server installation configuration for Linux is complete.

Redis Server Installation configuration 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.