当前位置: 首页 > news >正文

做网站需要企业/网站文章优化技巧

做网站需要企业,网站文章优化技巧,山东阳信建设局网站,东莞 塑胶 网站建设文章目录一、下载安装包二、解压并安装三、软连接四、主从配置五、部署Sentinel节点六、springboot 与 redis sentinel整合七、使用lettuce与 redis sentinel整合,手动创建连接八、使用redisson与 redis sentinel整合,手动创建连接一、下载安装包 去red…

文章目录

  • 一、下载安装包
  • 二、解压并安装
  • 三、软连接
  • 四、主从配置
  • 五、部署Sentinel节点
  • 六、springboot 与 redis sentinel整合
  • 七、使用lettuce与 redis sentinel整合,手动创建连接
  • 八、使用redisson与 redis sentinel整合,手动创建连接

一、下载安装包

去redis官网下载最新的consul版本,地址:
redis官方下载地址

不需要下载到自己的客户机上,直接在服务器里面用wget下载更快

拷贝下载链接

cd /home/download
wget http://download.redis.io/releases/redis-5.0.0.tar.gz

二、解压并安装

tar xzf redis-5.0.0.tar.gz
cd redis-5.0.0
make PREFIX=/usr/local/redis install

三、软连接

ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/redis-cli
ln -s /usr/local/redis/bin/redis-sentinel /usr/local/bin/redis-sentinel
ln -s /usr/local/redis/bin/redis-server /usr/local/bin/redis-server

四、主从配置

  • 1、修改配置文件
cd redis-5.0.0
cp redis.conf /etc/redis/redis_6001.conf
cp redis.conf /etc/redis/redis_6002.conf
cp redis.conf /etc/redis/redis_6003.conf

6001端口作为主服务

cd /etc/redis/
# 需要改动的配置
protected-mode no
port 6001
daemonize yes
logfile "6001.log"
dbfilename "dump-6001.rdb"
dir "/var/redis/data"
requirepass "123456"
masterauth "123456"

如果想用redis客户端工具远程连接,必须要protected-mode设为no

从节点在主节点的基础上改端口,并加上配置:

slaveof 127.0.0.1 6001
  • 2、启动:
redis-server redis-6001.conf 
redis-server redis-6002.conf 
redis-server redis-6003.conf 
  • 3、测试:
redis-cli -h 127.0.0.1 -p 6001 -a 123456 ping
redis-cli -h 127.0.0.1 -p 6002 -a 123456 ping
redis-cli -h 127.0.0.1 -p 6003 -a 123456 ping
  • 4、确认主从关系:

主节点视角

redis-cli -h 127.0.0.1 -p 6001 -a 123456 INFO replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6002,state=online,offset=85,lag=0
slave1:ip=127.0.0.1,port=6003,state=online,offset=85,lag=0
......

从主节点视角

redis-cli -h 127.0.0.1 -p 6002 -a 123456 INFO replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6001
master_link_status:up
......

五、部署Sentinel节点

  • 1、配置文件
cd /home/download/redis/redis-5.0.0
cp sentinel.conf /etc/redis/sentinel_17001.conf
cp sentinel.conf /etc/redis/sentinel_17002.conf
cp sentinel.conf /etc/redis/sentinel_17003.conf

3个Sentinel节点的部署方法是相同的(端口不同),以17001为例

protected-mode no
port 17001
daemonize yes
logfile "17001.log"
dir "/var/redis/data"
# 当前Sentinel节点监控 127.0.0.1:6001 这个主节点
# 2代表判断主节点失败至少需要2个Sentinel节点节点同意
# mymaster是主节点的别名
sentinel monitor mymaster 127.0.0.1 6001 2
sentinel auth-pass mymaster 123456
  • 2、启动
redis-sentinel sentinel-17001.conf
redis-sentinel sentinel-17002.conf
redis-sentinel sentinel-17003.conf
  • 3、测试
redis-cli -h 127.0.0.1 -p 17001 INFO Sentinel# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=35.234.13.166:6001,slaves=2,sentinels=3
redis-cli -h 127.0.0.1 -p 17001 
127.0.0.1:17001> sentinel masters 1) "name"2) "mymaster"3) "ip"4) "127.0.0.1"5) "port"6) "6001"7) "runid"8) "e8f4febb12cbb2f2c42ccc732db7d6abef8181ac"9) "flags"10) "master"11) "link-pending-commands"12) "0"13) "link-refcount"14) "1"......127.0.0.1:17001> sentinel slaves mymaster
#略
  • 4、拓补图如下:
    在这里插入图片描述

六、springboot 与 redis sentinel整合

springboot2.0 默认用的redis连接是 lettuce

配置如下:

#redis
spring.redis.sentinel.nodes=ip:17001,ip:17002,ip:17003
spring.redis.sentinel.master=mymaster
spring.redis.password=123456

接下来springboot 会自动用lettuce连接redis,从而生成RedisTemplate来操作redis

七、使用lettuce与 redis sentinel整合,手动创建连接

直接上代码:

@Configuration
public class RedisConfig {@Bean(name = "lettucePool")public GenericObjectPool lettucePool(RedisProperties redisProperties) {RedisURI redisURI = null;if (redisProperties.getSentinel() != null) {RedisURI.Builder builder = RedisURI.builder();builder.withPassword(redisProperties.getPassword());builder.withDatabase(12);RedisProperties.Sentinel sentinel = redisProperties.getSentinel();builder.withSentinelMasterId(sentinel.getMaster());List<String> nodes = sentinel.getNodes();nodes.forEach(node -> {builder.withSentinel(HostAndPort.parse(node).getHostText(), HostAndPort.parse(node).getPort());});redisURI = builder.build();} else {redisURI = RedisURI.create(redisProperties.getHost(), redisProperties.getPort());redisURI.setDatabase(12);redisURI.setPassword(redisProperties.getPassword());}RedisClient client = RedisClient.create(redisURI);GenericObjectPoolConfig config = new GenericObjectPoolConfig();config.setJmxEnabled(false);GenericObjectPool<StatefulRedisConnection> lettucePool = ConnectionPoolSupport.createGenericObjectPool(() -> client.connect(), config);return lettucePool;}

八、使用redisson与 redis sentinel整合,手动创建连接

直接上代码:

@Configuration
public class RedisConfig {@Beanpublic RedissonClient redisson(RedisProperties redisProperties) {Config config = new Config();if (redisProperties.getSentinel() != null) { //sentinelSentinelServersConfig sentinelServersConfig = config.useSentinelServers();sentinelServersConfig.setMasterName(redisProperties.getSentinel().getMaster());List<String> nodes = redisProperties.getSentinel().getNodes();String[] strings = new String[nodes.size()];String schema = redisProperties.isSsl() ? "rediss://" : "redis://";for (int i = 0; i < nodes.size(); i++) {strings[i] = schema + nodes.get(i);}sentinelServersConfig.addSentinelAddress(strings);sentinelServersConfig.setDatabase(0);if (redisProperties.getPassword() != null) {sentinelServersConfig.setPassword(redisProperties.getPassword());}} else { //single serverSingleServerConfig singleServerConfig = config.useSingleServer();String schema = redisProperties.isSsl() ? "rediss://" : "redis://";singleServerConfig.setAddress(schema + redisProperties.getHost() + ":" + redisProperties.getPort());singleServerConfig.setDatabase(0);if (redisProperties.getPassword() != null) {singleServerConfig.setPassword(redisProperties.getPassword());}}return Redisson.create(config);}

大功告成!

http://www.lbrq.cn/news/1327465.html

相关文章:

  • 企业网站界面 优帮云/seo查询源码
  • 北京市网站开发/关键词app
  • 美国纽约网站建设费用/网站热度查询
  • 网站赚取广告费/徐州seo顾问
  • ssm框架做电影网站/农业推广
  • 美工首页设计/宁波优化推广选哪家
  • 推广网站企业/360搜索引擎的特点
  • 做木马的网站/怎样和政府交换友链
  • 网站的页面设计/个人网站设计作品
  • 汕头建设局网站/潍坊seo推广
  • 敦煌网站做外贸怎样/福州网站开发公司
  • 绍兴网络公司网站建设/百度网盘下载速度
  • 幼儿园网站建设总结/简述seo的基本步骤
  • 中国建设教育网站/google下载安装
  • 电子商务网站建设与管理期末考试题/n127网推广
  • 做公众号必了解的网站/搜索引擎关键词排名
  • 给被k的网站做友链/做网站推广需要多少钱
  • 网站建设费用选网络专业/金泉网做网站多少钱
  • 网站建设寻求/郑州粒米seo顾问
  • 网站开发维护岗位职责/推广普通话内容
  • 长春网站运做思路/济南网站设计
  • 企业网站模板 简洁/青岛seo排名扣费
  • 网站 网络架构/关键词推广价格
  • 建设网站必须要配置apache吗/网络游戏营销策略
  • 网站建设套餐价格/整站关键词快速排名
  • wordpress支持论坛/济南seo整站优化招商电话
  • 网站聊天室怎样做炫彩马甲/免费发广告的软件
  • 东莞整合网站建设开发/今日财经新闻
  • 横沥镇做网站/长沙官网seo推广
  • 重庆建设工程信息网官网入口查询/seo的中文含义是
  • 自动化框架pytest
  • 新一代PLC控制软件平台EsDA-AWStudio
  • GitPython08-源码解读
  • 【neo4j】跨版本升级数据库
  • k8s-master03加入集群失败解决方法之一
  • 今日矩阵系列