Redis Server Installation configuration under Linux

Source: Internet
Author: User
Tags allkeys benchmark 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  - Ten# Description:redis isA persistent key-value database# redis Startup script forRedis 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] | | Exit0RETVAL=0Prog="Redis"# Start Daemons.start () {if[-E $redis _pid-a!z $redis _pid];thenecho $prog"already running ...."Exit1Fiecho-N $"starting $prog"# Single Instance forAll caches$redis_path $redis _confretval=$?[$RETVAL-eq0] &&{Touch/var/Lock/subsys/$progsuccess $"$prog"}echoreturn$RETVAL}# Stop daemons.stop () {echo-N $"stopping $prog"Killproc-DTen$redis _pathecho[$RETVAL=0] && rm-f $redis _pid/var/Lock/subsys/$progRETVAL=$?return$RETVAL}# See how we were called. Case " $" inchstart) Start; stop) stop;; Status) Status $progRETVAL=$?;; restart) Stopstart;; Condrestart)ifTest"x ' pidof redis '"!=x; thenstopstartfi;;*) echo $"Usage: $ {Start|stop|status|restart|condrestart}"Exit1esacexit $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.pidport6379#默认端口bind127.0.0.1#默认绑定本机所有ip地址, for security, you can only monitor the intranet Iptimeout -#客户端超时设置, units in 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 the 1Save - TenSave - 10000Create a local database snapshot, format: Save* *Within 900 seconds, perform 1 write operations within 300 seconds, perform 10 write operations within 60 seconds, perform 10,000 write operations rdbcompression Yes #启用数据库lzf压缩, or set to Nodbfilename Dump.rdb # Local snapshot database name dir"/usr/local/redis/var/"#本地快照数据库存放目录requirepass123456#设置redis数据库连接密码maxclients10000#同一时间最大客户端连接数, 0 is an unrestricted maxmemory 1024MB #设定redis最大使用内存, the value is less than the physical memory, you must set the appendonly Yes #开启日志记录, The equivalent of MySQL binlogappendfilename"appendonly.aof"#日志文件名, note: Not a directory path Appendfsync everysec #每秒执行同步, there are two parameters always, no is generally set to everysec, the equivalent of the MySQL thing log write way

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


6, Test Redis database
redis-cli-a 123456  #连接redis数据库, note:-A followed by the Redis database password
Set name osyunwei.com  #写数据
Get name  #读取数据
exit # Exit the Redis Database console
redis-benchmark-h 127.0.0.1-p 6379-c 1000-n 100000  # 1000 concurrent connections, 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.