下载redis
http://download.redis.io/releases/redis-2.8.13.tar.gz
使用root用户安装redis
[[email protected] ~]# id uid=0(root) gid=0(root) groups=0(root) [[email protected] ~]# ls -l redis-2.8.13.tar.gz -rw-r--r-- 1 oracle oinstall 1227538 Oct 23 14:53redis-2.8.13.tar.gz 解压 [[email protected] ~]# tar xzf redis-2.8.13.tar.gz [[email protected] ~]# ls -ld redis-2.8.13 drwxrwxr-x 6 root root 4096 Jul 14 2014 redis-2.8.13 [[email protected] ~]# cd redis-2.8.13 [[email protected] redis-2.8.13]# ls 00-RELEASENOTES CONTRIBUTING deps Makefile README runtest sentinel.conf tests BUGS COPYING INSTALL MANIFESTO redis.conf runtest-sentinel src utils 这里推荐是make && make test && make install 输出内容太多了,并没有完全贴出来。 [[email protected] redis-2.8.13]# make cd src && make all make[1]: Entering directory `/root/redis-2.8.13/src‘ …. Hint: To run ‘make test‘ is a good idea ;) make[1]: Leaving directory `/root/redis-2.8.13/src‘ [[email protected] redis-2.8.13]# make test cd src && make test make[1]: Entering directory `/root/redis-2.8.13/src‘ You need tcl 8.5 or newer in order to run the Redis test make[1]: *** [test] Error 1 make[1]: Leaving directory `/root/redis-2.8.13/src‘ make: *** [test] Error 2 [[email protected] redis-2.8.13]# make install cd src && make install make[1]: Entering directory `/root/redis-2.8.13/src‘ Hint: To run ‘make test‘ is a good idea ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install make[1]: Leaving directory `/root/redis-2.8.13/src‘
初始化一个服务
拷贝可执行文件到/usr/local/ [[email protected] redis-2.8.13]# cp utils /usr/local/ -rf 直接在/root/redis-2.8.13/utils中运行install_server.sh脚本, 初始化一个端口号为6379的服务 [[email protected] utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redisserver Please select the redis port for this instance: [6379] #选择端口号 Selecting default: 6379 Please select the redis config file name[/etc/redis/6379.conf] #选择配置文件 Selected default - /etc/redis/6379.conf Please select the redis log file name[/var/log/redis_6379.log] #选择log文件 Selected default - /var/log/redis_6379.log Please select the data directory for this instance[/var/lib/redis/6379] #选择数据文件目录 Selected default - /var/lib/redis/6379 Please select the redis executable path[/usr/local/bin/redis-server] #选择redis-server的执行路径 Selected config: Port : 6379 Config file :/etc/redis/6379.conf Log file :/var/log/redis_6379.log Data dir :/var/lib/redis/6379 Executable :/usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! 另外重新配置一个6378,选择跟刚才的类似 [[email protected] utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redisserver Please select the redis port for this instance: [6379] 6378 #只需要改动这个位置 Please select the redis config file name[/etc/redis/6378.conf] Selected default - /etc/redis/6378.conf Please select the redis log file name[/var/log/redis_6378.log] Selected default - /var/log/redis_6378.log Please select the data directory for this instance[/var/lib/redis/6378] Selected default - /var/lib/redis/6378 Please select the redis executable path[/usr/local/bin/redis-server] Selected config: Port : 6378 Config file :/etc/redis/6378.conf Log file :/var/log/redis_6378.log Data dir :/var/lib/redis/6378 Executable :/usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6378.conf => /etc/init.d/redis_6378 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!
验证是否安装成功
[[email protected] utils]#/etc/init.d/redis_6378 status #查看redis状态 Redis is running (9487) [[email protected] utils]# /etc/init.d/redis_6378 stop #关闭redis Stopping ... Redis stopped [[email protected] utils]# /etc/init.d/redis_6378 start #启动redis Starting Redis server... 添加开机自启动服务 [[email protected] utils]# chkconfig redis_6378 on 2345 [[email protected] utils]# chkconfig --list redis_6378 redis_6378 0:off 1:off 2:on 3:on 4:on 5:on 6:off 使用redis-cli来设置值和获取值 [[email protected] utils]# /usr/local/bin/redis-cli #默认调用6379端口 127.0.0.1:6379> set k1 1 OK 127.0.0.1:6379> exit [[email protected] utils]# /usr/local/bin/redis-cli -p 6378 #-p 参数可以指定端口访问 127.0.0.1:6378> set ke1 a OK 127.0.0.1:6378> get ke1 "a" #这里可以通过get方式获取值,就说明安装成功了 127.0.0.1:6378> quit [[email protected] utils]# /usr/local/bin/redis-cli -p 6379 127.0.0.1:6379> get k1 "1" 127.0.0.1:6379> 访问远程redis,直接通过-h 参数就可以指定IP地址,进行远程访问了 [[email protected] utils]# /usr/local/bin/redis-cli -h 192.168.10.140 -p 6379 192.168.10.140:6379> get k1 "1" 192.168.10.140:6379> get ka (nil) 192.168.10.140:6379> get ke1 (nil)
时间: 2024-10-21 21:14:38