http://www.cnblogs.com/HYXJavaweb/p/5217262.html?utm_source=tuicool&utm_medium=referral ----------------------------------------------------- Redis的安装步骤:
步骤1.安装redis必须已经安装了gcc,如果没安装gcc 就使用命令 yum install -y gcc 步骤2.下载redis包 下载地址:http://download.redis.io/releases/redis-3.0.7.tar.gz上传到你要安装的目录然后解压。我解压在usr目录下 步骤3.进入usr/redis-3.0.7/src 步骤4.make #编译 步骤5.make test
[root@localhost src]# make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] 错误 1
步骤6.根据错误下载tcl 使用命令:yum install -y tcl 然后make test
步骤7.make install [root@localhost src]# make install
Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install
见到这个你就安装成功了,意思是说好习惯是先运行测试,然后我们再来移动和修改配置文件。
步骤8.移动文件,便于管理:(所有源代码安装的软件都安装在/usr/local下) 创建两个文件夹,bin用于存放命令,etc拥有存放配置文件。 [root@localhost src]$ sudo mkdir -p /usr/local/redis/bin [root@localhost src]$ sudo mkdir -p /usr/local/redis/etc -p是递归创建
步骤9.接下来, 将redis-3.0.7文件夹下的redis.conf复制到/usr/local/redis/etc/ 并将src目录下的7个命令文件(绿色的),移动到/usr/local/redis/bin/
sudo mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server /usr/local/redis/bin/
步骤10:启动Redis服务: 首先进入刚才安装redis的目录: [root@localhost src]$ cd /usr/local/redis/bin [root@localhost src]$ ls mkreleasehdr.sh redis-check-aof redis-cli redis-server redis-benchmark redis-check-dump redis-sentinel 之后我们启动redis服务。启动redis服务需要用到命令redis-server
[root@localhost bin]$ ./redis-server
[13019] 15 Mar 22:34:24.568 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf [13019] 15 Mar 22:34:24.569 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.19 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 13019 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [13019] 15 Mar 22:34:24.570 # Server started, Redis version 2.8.19 [13019] 15 Mar 22:34:24.570 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. [13019] 15 Mar 22:34:24.570 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. [13019] 15 Mar 22:34:24.570 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. [13019] 15 Mar 22:34:24.570 * The server is now ready to accept connections on port 6379
但是,这样做的话,我们并没有使用etc的下的配置文件进行启动。
如果希望通过指定的配置文件启动,需要在启动时指定配置文件:
这里我们先用ctrl+C来终止服务,然后查看redis服务是否终止干净了,之后通过设置配置文件来启动服务:
步骤11:查看redis是否启动 netstat -tunpl | grep 6379 如果什么都没有就是没有启动 步骤12:启动redis服务 进入/usr/local/redis/bin/目录下执行./redis-server /usr/local/redis/etc/redis.conf命令开启Redis服务。 例:[root@localhost bin]# ./redis-server /usr/local/redis/etc/redis.conf 然后再查看redis是否启动,我们往往需要查看6379端口是否被占用,如果出现以下情况那么就服务开启成功. [root@localhost bin]# netstat -tunpl | grep 6379 tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 41645/./redis-serve tcp6 0 0 :::6379 :::* LISTEN 41645/./redis-serve 至此,redis服务已经按照配置文件启动成功!!
步骤13:我们进行测试客户端连接 [root@localhost bin]# ./redis-cli 127.0.0.1:6379> set name 张三 OK 127.0.0.1:6379> get name "\xe5\xbc\xa0\xe4\xb8\x89" 中文出现这样 我们就重新连接,后面加上 --raw [root@localhost bin]# ./redis-cli --raw 127.0.0.1:6379> get name 张三 127.0.0.1:6379> keys * name 127.0.0.1:6379> del name 1
退出就ctrl+c 或者 exit
步骤14:关闭redis服务 进入/usr/local/redis/bin/目录下执行./redis-cli shutdown 步骤15:修改配置文件 vim /usr/local/redis/etc/redis.conf daemonize 改为yes可以吧redis改为后台启动 修改完daemonize参数之后,redis就能够通过daemon方式启动了,那么下一步就是把redis加入到linux开机启动服务配置中了,具体步骤如下: 使用VI编辑器打开Linux开机启动服务配置文件/etc/rc.local,并在其中加入下面的一行代码: /usr/local/redis/bin/redis-server /etc/redis.conf 编辑完后保存,然后重启系统就OK了。 然后再次启动redis服务就可以了. reids搭建基本工作准备完成.
O(∩_∩)O哈哈~
------------------------ redis命令: 查看redis是否启动 netstat -tunpl | grep 6379
开启redis服务 进入/usr/local/redis/bin/目录下执行./redis-server /usr/local/redis/etc/redis.conf命令开启Redis服务。 注意:开启redis服务需要指定配置文件,如不指定配置文件则加载默认配置文件。
关闭redis服务 进入/usr/local/redis/bin/目录下执行./redis-cli shutdown
|