Centos7安装Redis-单节点
1、安装 gcc 编译环境
由于 Redis 使用 C 语言开发,所以官网下载的源码需要进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装。
[root@CentOS ~]# yum -y install gcc
2、下载 redis 安装包
[root@CentOS local]# wget http://download.redis.io/releases/redis-4.0.8.tar.gz
3、解压安装包
[root@CentOS local]# tar -zxvf redis-4.0.8.tar.gz # 解压安装包 redis-4.0.8/ redis-4.0.8/.gitignore redis-4.0.8/00-RELEASENOTES redis-4.0.8/BUGS redis-4.0.8/CONTRIBUTING redis-4.0.8/COPYING redis-4.0.8/INSTALL redis-4.0.8/MANIFESTO ......(略去内容)...... [root@CentOS local]# ll # 查看目录文件信息 总用量 1696 drwxr-xr-x. 2 root root 6 2月 24 16:18 bin drwxr-xr-x. 2 root root 6 11月 5 2016 etc drwxr-xr-x. 2 root root 6 11月 5 2016 games drwxr-xr-x. 2 root root 6 11月 5 2016 include drwxr-xr-x. 2 root root 6 11月 5 2016 lib drwxr-xr-x. 2 root root 6 11月 5 2016 lib64 drwxr-xr-x. 2 root root 6 11月 5 2016 libexec drwxrwxr-x. 6 root root 4096 2月 3 00:39 redis-4.0.8 # 该目录为解压后的目录 -rw-r--r--. 1 root root 1729973 2月 3 00:40 redis-4.0.8.tar.gz drwxr-xr-x. 2 root root 6 11月 5 2016 sbin drwxr-xr-x. 5 root root 49 1月 30 14:30 share drwxr-xr-x. 2 root root 6 11月 5 2016 src [root@CentOS local]#
4、编译并安装文件
[root@CentOS local]# cd redis-4.0.8/ # 进入解压后的目录 [root@CentOS redis-4.0.8]# make # 执行编译 ......(略去内容)...... CC lazyfree.o CC module.o CC evict.o CC expire.o CC geohash.o CC geohash_helper.o CC childinfo.o CC defrag.o CC siphash.o CC rax.o LINK redis-server INSTALL redis-sentinel CC redis-cli.o LINK redis-cli CC redis-benchmark.o LINK redis-benchmark INSTALL redis-check-rdb INSTALL redis-check-aof Hint: It's a good idea to run 'make test' ;) # 如果编译成功,会看到此行信息提示 make[1]: 离开目录“/usr/local/redis-4.0.8/src” [root@CentOS redis-4.0.8]# make install # 执行安装,默认会安装到 /usr/local/bin 目录中 cd src && make install make[1]: 进入目录“/usr/local/redis-4.0.8/src” CC Makefile.dep make[1]: 离开目录“/usr/local/redis-4.0.8/src” make[1]: 进入目录“/usr/local/redis-4.0.8/src” Hint: It's a good idea to run 'make test' ;) # 如果安装成功,会看到此行信息提示 INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install make[1]: 离开目录“/usr/local/redis-4.0.8/src” [root@CentOS redis-4.0.8]#
5、将 redis 设置为系统服务,并开机启动
[root@CentOS redis-4.0.8]# ./utils/install_server.sh # 执行 install_server.sh 脚本,之后一直回车确认采用默认配置即可 Welcome to the redis service installer This script will help you easily set up a running redis server 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] 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] Selected config: Port : 6379 Config file : /etc/redis/6379.conf # redis实例默认的配置文件 Log file : /var/log/redis_6379.log # redis实例的日志文件 Data dir : /var/lib/redis/6379 # redis实例的数据存储目录 Executable : /usr/local/bin/redis-server # redis_server 执行路径 Cli Executable : /usr/local/bin/redis-cli # 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! # 提示已安装成功 [root@CentOS redis-4.0.8]#
6、编辑 redis 实例默认的配置文件,修改配置项如下
daemonize yes # 将 redis 实例作为后台进程运行 bind 0.0.0.0 # 允许任何远程主机访问 requirepass 123456 # 登录密码
7、重启 redis 服务,并将 6379 端口添加到防火墙中
[root@CentOS redis-4.0.8]# service redis_6379 restart # 重启 redis 服务 Stopping ... Redis stopped Starting Redis server... [root@CentOS redis-4.0.8]# firewall-cmd --zone=public --add-port=6379/tcp --permanent # 添加 6379 端口到防火墙中 success [root@CentOS redis-4.0.8]# firewall-cmd --reload # 重新载入防火墙信息 success [root@CentOS redis-4.0.8]#
艺无止境,诚惶诚恐, 感谢开源贡献者的努力!!