Centos7 安装 redis 并配置外网访问

Redis 在Centos7 上安装
 
查看/关闭防火墙
firewall-cmd --state

如果状态为 running 关闭防火墙
systemctl stop firewalld.service  // 关闭防火墙
systemctl disable firewalld.service  // 禁止防火墙开机启动
下载安装
    
# 因为redis是c开发的需要先安装C环境
yum install gcc-c++
 
# 查看是否安装 wget 
rpm -qa | grep "wget"  // 如果已经安装会显示具体的信息 
  
yum -y install wget  // 如果上面已经 显示安装了就不需要再次安装了 
wget http://download.redis.io/releases/redis-4.0.2.tar.gz    或者 直接将下载好的包传到centos7上面
 
tar -zxvf redis-4.0.2.tar.gz  // 解压文件
 
cd redis-4.0.2   // 进入到此目录
 
# 编译Redis 
make MOLLOC=libc
# 安装
make install 
 
配置开机启动 
./utils/install_server.sh 
[root@edu-provider-01 redis-4.0.2]# ./utils/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
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!
 
 
开启外网访问 :
此处注意 上面在配置开机启动的是 已经制定了 启动是conf  我的是实用默认值 /etc/redis/6379.conf
#请根据自己的的启动时conf进行启动
 
# 注释掉bind
#bind 127.0.0.12
# 默认不是守护进程方式运行,这里可以修改  
daemonize no  // 在实际操作中 redis 一直没起来  改成 yes 就可以起来了  
#  禁用保护模式 
protected-mode no

 

 
Redis服务查看、开启、关闭:
a.通过ps -ef|grep redis命令查看Redis进程
b.开启Redis服务操作通过/etc/init.d/redis_6379 start命令,也可通过(service redis_6379 start)
c.关闭Redis服务操作通过/etc/init.d/redis_6379 stop命令,也可通过(service redis_6379 stop)
 
 
redis.conf 的配置信息
1、daemonize 如果需要在后台运行,把该项改为yes
2、pidfile 配置多个pid的地址 默认在/var/run/redis.pid
3、bind 绑定ip,设置后只接受来自该ip的请求
4、port 监听端口,默认是6379
5、loglevel 分为4个等级:debug verbose notice warning
6、logfile 用于配置log文件地址
7、databases 设置数据库个数,默认使用的数据库为0
8、save 设置redis进行数据库镜像的频率。
9、rdbcompression 在进行镜像备份时,是否进行压缩
10、dbfilename 镜像备份文件的文件名
11、Dir 数据库镜像备份的文件放置路径
12、Slaveof 设置数据库为其他数据库的从数据库
13、Masterauth 主数据库连接需要的密码验证
14、Requriepass 设置 登陆时需要使用密码
15、Maxclients 限制同时使用的客户数量
16、Maxmemory 设置redis能够使用的最大内存
17、Appendonly 开启append only模式
18、Appendfsync 设置对appendonly.aof文件同步的频率(对数据进行备份的第二种方式)
19、vm-enabled 是否开启虚拟内存支持 (vm开头的参数都是配置虚拟内存的)
20、vm-swap-file 设置虚拟内存的交换文件路径
21、vm-max-memory 设置redis使用的最大物理内存大小
22、vm-page-size 设置虚拟内存的页大小
23、vm-pages 设置交换文件的总的page数量
24、vm-max-threads 设置VM IO同时使用的线程数量
25、Glueoutputbuf 把小的输出缓存存放在一起
26、hash-max-zipmap-entries 设置hash的临界值
27、Activerehashing 重新hash
 
 补充知识 : 
1、Redis安装
   1.地址:http://www.nuget.org/packages/Redis-64/3.0.500,根据需要安装自己想要的版本
   2.Windows安装非常简单,解压文件夹,点击redis-server启动Redis
 
3.点击redis-client,就可以对Redis进行数据操作了
2、RedisStudio安装
地址:https://github.com/cinience/RedisStudio/releases,点击安装最新版的即可。
下载后,直接打开就OK,主界面如下,非常丑。。只有几个简单的按钮。
添加本地服务
查看数据,这里的key和value就是刚才我创建的数据了
 
当然Redis更高级的用法,如分布式领域,内部精巧设计,有待我未来好好研究一番
3 、vi实用命令
 
:$ 跳到文件最后一行
 
:0或:1 跳到文件第一行
 
  或 另外一组命令:
 
  gg 跳到文件第一行
 
Shift + g 跳到文件最后一行

 

posted on 2018-03-14 11:26  一月一本书  阅读(208)  评论(0)    收藏  举报

导航