Centos6.5 install Redis
After a long time, we will find that there is no difference in the next step between linux software and Windows. Even more fun. Just give me a line of command. Let's go! A pile of screens flashed through. It's amazing to be a layman. Hahaha, there is actually no technical content. Just a few lines of commands.
# Install redis in linux to obtain [root @ weixinht src] # wget http://download.redis.io/redis-stable.tar.gz#decompress the package and put it in the directory specified by the-C parameter in/usr/local. # Tar-zxvf redis-stable.tar.gz-C/usr/local/# Switch to the decompressed directory redis-stable is the decompressed file name [root @ weixinht ~] # Cd/usr/local/redis-stable/# compile and install [root @ weixinht ~] # Make # After completion, you will be prompted to go To the src directory and execute make test. [root @ weixinht ~] # Cd/usr/local/redis-stable/src/[root @ weixinht ~] # Make test # Here I will report an error. If tcl is not installed, it will certainly not report my feelings, but it will be of great help to beginners. [root @ weixinht ~] # Yum install-y tcl prompt success no errors or errors, and do not be afraid of Baidu Google's Solutions
Note: After make is successful, some executable files will be added to the src directory: redis-server, redis-cli, and so on. The key part is the following boot script snippet. Note the following paths: "'redis_path ="/usr/local/bin/redis-server "redis_conf ="/etc/redis/redis_m.conf "redis_pid ="/var/redis/run/ redis_m.pid"
These directories are created to store the configuration file mkdir/etc/redismkdir/var/redis/logmkdir/var/redis/runmkdir/var/redis/redis_m.
Copy the configuration file
[Root @ weixinht redis-stable] # pwd/usr/local/redis-stable # Find the configuration file template in the redis root directory and copy it to the following location. [Root @ weixinht redis-stable] # cp redis. conf/etc/redis/redis_m.conf [root @ weixinht redis-stable] # cd src [root @ weixinht src] # cp redis-server/usr/local/bin/[root @ weixinht src] # cp redis-cli/usr/local/bin/
Vim Modify/etc/redis/redis_m.conf
daemonize yespidfile /var/redis/run/redis_m.pidlogfile /var/redis/log/redis_m.logdir /var/redis/redis_m
Finally, run the redis specified configuration file: [root @ weixinht src] # the corresponding redis-server/etc/redis/redis_m.conf file will be generated
Redis boot start redis boot script note that the configuration file path is correct
Vim/etc/init. d/redis # create a file and add the content #! /Bin/sh # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database # redis Startup script for redis processes # processname: redis # note the following paths: redis_path = "/usr/local/bin/redis-server" redis_conf = "/etc/redis/redis_m.conf" redis_pid = "/var/redis/run/ redis_m.pid "# Source function library .. /etc/rc. d/init. d/functions [-x $ redis_path] | exit 0 RETVAL = 0 prog = "redis" # Start daemons. start () {if [-E $ redis_pid-! -Z $ redis_pid]; thenecho $ prog "already running .... "exit 1 fiecho-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 10 $ redis_pathecho [$ RETVAL = 0] & rm-f $ redis_pid/var/lock/subsys/$ progRETVAL = $? Return $ RETVAL} # See how we were called. case "$1" instart) start; stop) stop; status) status $ progRETVAL =$ ?;; Restart) stopstart; condrestart) if test "x 'pidof redis '"! = X; thenstopstartfi; *) echo $ "Usage: $0 {start | stop | status | restart | condrestart}" exit 1 esacexit $ RETVAL
Change permissions to add to auto-Start Service
[Root @ weixinht redis] # chmod 755/etc/init. d/reredis restorecond [root @ weixinht redis] # chmod 755/etc/init. d/redis [root @ weixinht redis] # chkconfig -- add redis [root @ weixinht redis] # chkconfig -- level 2345 redis on [root @ weixinht redis] # chkconfig -- list redisredis 0: disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: disable [root @ weixinht redis] # service redis restartStopping redis [OK] Starting redis [OK] [root @ weixinht redis] #
Test
[Root @ weixinht ~] # Redis-cli-a 123456 # connect to the redis database. Note:-a is followed by the redis Database Password 127.0.0.1: 6379> set name maobo. me # Write Data OK127.0.0.1: 6379> get name # Read data "maobo. me "127.0.0.1: 6379> exit [root @ weixinht ~] # Exit the Console
Redis configuration file Parameters
Set the redis configuration file parameter mkdir-p/usr/local/redis/var # create the redis database storage directory vi/etc/redis. conf # edit daemonize yes # run redispidfile in daemon mode "/var/run/redis. pid "# run on apsaradb for redis later. The default pid file path is/var/run/redis. pidport 6379 # default port bind 127.0.0.1 # All IP addresses of the local machine are bound by default. To ensure security, you can only listen to intranet iptimeout 300 # Set the client timeout, in the unit of second loglevel verbose # Set the log level, four levels are supported: debug, notice, verbose, warninglogfile stdout # log record mode. The default value is standard output, and logs does not write files, output to empty device/deb/nulllogfile "/usr/local/re Dis/var/redis. log "# You can specify the log file path databases 16 # number of databases enabled save 900 1 save 300 10 save 60 10000 create a local database snapshot in the format of save ** 900 seconds, execute 1 write operation within 300 seconds, execute 10 write operations within 60 seconds, execute 10000 write operations rdbcompression yes # enable lzf compression of the database, or set it to nodbfilename dump. rdb # local snapshot database name dir "/usr/local/redis/var/" # local snapshot database storage directory requirepass 123456 # Set the redis database connection password maxclients 10000 # maximum number of client connections at the same time, 0 is unrestricted maxmemory 1024 MB # set the maximum memory usage of redis. The value must be smaller than the physical memory. You must set appendonly yes # Enable logging, which is equivalent Binlogappendfilename "appendonly. aof "# log file name. Note: it is not the directory path appendfsync everysec # synchronization is executed per second. Two other parameters always and no are generally set to everysec, which is equivalent to the write method of MySQL transaction logs: wq! # Save and exit service redis restart # restart