一、环境
主机:win10 64位
虚拟机:Ubuntu 16.04
二、安装
- $ cd /usr/local
- $ mkdir redis
- $ wget http://download.redis.io/releases/redis-5.0.0.tar.gz
- $ tar -zxvf redis-5.0.0.tar.gz
- $ cd redis-5.0.0
- $ make
编译完成后,创建bin目录,建立我们需要使用的文件
- $ make PREFIX=/usr/local/redis install
- $ cd ..
- $ ll
此时我们可以看到创建的bin目录
- $ cd bin
- $ ll
接下来介绍第一种Redis 的启动方式---前端启动
- $ ./redis-server
结果如下:
32422:C 06 Nov 2018 16:28:41.594 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 32422:C 06 Nov 2018 16:28:41.594 # Redis version=5.0.0, bits=32, commit=00000000, modified=0, pid=32422, just started 32422:C 06 Nov 2018 16:28:41.594 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf 32422:M 06 Nov 2018 16:28:41.595 * Increased maximum number of open files to 10032 (it was originally set to 1024). 32422:M 06 Nov 2018 16:28:41.596 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now. _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.0 (00000000/0) 32 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 32422 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 32422:M 06 Nov 2018 16:28:41.597 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 32422:M 06 Nov 2018 16:28:41.597 # Server initialized 32422:M 06 Nov 2018 16:28:41.597 # 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. 32422:M 06 Nov 2018 16:28:41.597 # 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. 32422:M 06 Nov 2018 16:28:41.597 * Ready to accept connections
服务端启动,我们在启动客户端,进行数据交互:
- $ ./redis-cli
- 127.0.0.1:6379>set QQ WeChat
- ok
- 127.0.0.1:6379>get QQ
- "WeChat"
接下来介绍第二种Redis 的启动方式:
- $ cd redis-5.0.0
- $ vim redis.conf
修改成如下数据:
136 daemonize yes
- $ cp redis.conf /usr/local/redis/bin
- $ cd ..
- $ cd bin
- $ ./redis-server redis.conf
此时redis 已经在后台启动,我们可以通过 ps -aux|grep redis 查看是否启动,运行结果如下图:
从上图结果中可以看出来,redis-server 已经在后台启动了
启动多个redis进程
方法1:
启动时指定端口可在一台服务器启动多个redis进程。
cd /usr/local/redis/bin
./redis-server ./redis.conf --port 6380
方法2(推荐此方法):
创建多个redis目录,以端口号命名,比如:创建6379、6380两个目录,将redis的安装文件bin和conf拷贝至这两个目录。
修改6379目录下的redis.conf设置端口号为6379
修改6380目录下的redis.conf设置端口号为6380
启动6379和6380目录下的redis-server程序:
cd 6379
./redis-server . /redis.conf
cd 6380
./redis-server . /redis.conf
查询当前redis的进程:
redis停止
强行终止Redis进程可能会导致redis持久化数据丢失。正确停止Redis的方式应该是向Redis发送SHUTDOWN命令,方法为:
cd /usr/local/redis
./bin/redis-cli shutdown
至此 Redis 的倆zhog种启动方式都介绍完了
Linux Ubuntn环境下---Redis缓存的安装和启动
最新推荐文章于 2024-04-05 23:40:56 发布