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

芜湖南陵网站建设网站开发毕业任务书

芜湖南陵网站建设,网站开发毕业任务书,网站建设百科,最近比较火的关键词1 首先要在Linux虚拟机上安装redis # 安装包存放目录 cd /usr/local/redis # 下载最新稳定版 wget https://download.redis.io/releases/redis-6.2.6.tar.gz # 解压 tar -zxvf redis-6.2.6.tar.gz # 进入解压后的目录 cd /usr/local/redis/redis-6.2.6/ # 编译 make # 执行 make install 默认会安装到 /usr/local/bin,可通过PREFIX指定安装路径 make install PREFIX/usr/local/redis # 测试是否安装成功,执行下面命令 /usr/local/redis/bin/redis-server下载安装好的文件 测试启动看是否能够正常运行 2 主从及哨兵配置 简要过程 三个redis-server服务都运行在我们虚拟机上我这里的设置的IP地址都为192.168.159.100根据自己的IP地址定义端口分别为6380、6381、6382以6380作为主节点6381、6382作为从节点 1主从复制masterslave 配置redis.conf运行文件 先创建一个 redis-cluster 文件夹 拷贝三份redis.conf文件到 redis-cluster 文件夹目录下 配置文件可在解压后的源码文件根目录中找到这里以从节点 6381 配置文件为例其余两个配置文件几乎一致。首先将配置文件redis.conf拷贝到/usr/local/redis/redis-clusterredis-cluster文件夹需要手动创建拷贝三份然后进行下面的修改 # (1)设置允许外部ip访问,需要注释掉bind配置,并关掉保护模式 # bind 127.0.0.1 -::1 protected-mode no# (2)修改端口号 port 6381# (3)修改为以守护进程模式后台运行 daemonize yes# (4)修改pid文件名,以守护进程运行的时候,会产生pid文件,默认位置为 /run/redis.pid # 因为这里在同一台机器上运行多个实例,所以需要指定 pidfile /usr/local/redis/redis-cluster/redis_6381.pid# (5)修改日志文件位置 logfile /usr/local/redis/redis-cluster/redis_6381.log# (6)修改rdb快照文件位置 dir /usr/local/redis/redis-cluster dbfilename dump_6381.rdb# (7)修改主节点地址,在部分旧版本中是slaveof命令,主节点6380配置文件中不要加这一行 replicaof 192.168.159.100 6380# (8)aof可按需要开启,这里我们使用.rdb文件的存储方式,以下不进行配置 appendonly yes appendfilename appendonly_6381.aof 在上面的配置中6381与6382的.conf一致改一下其中的端口及地址就可以了其中6380作为主节点没有第7步骤。建议三服务运行在不同的文件夹下方便查看日志以及数据的输出。为了省去切换文件目录的时间都放在一个文件夹下了 配置完成后根据配置文件分别启动三个redis-server服务 [rootvinjcent redis-cluster]# /usr/local/redis/bin/redis-server ./redis-6380.conf [rootvinjcent redis-cluster]# /usr/local/redis/bin/redis-server ./redis-6381.conf [rootvinjcent redis-cluster]# /usr/local/redis/bin/redis-server ./redis-6382.conf 启动成功后产生的持久化、日志文件如下图 进入主节点查看实例主从状况 # 运行redis客户端 -p 代表进入的是那个端口 [rootvinjcent redis-cluster]# /usr/local/redis/bin/redis-cli -p 6380 # 查看主从信息 127.0.0.1:6380 info replication # Replication role:master connected_slaves:2 slave0:ip192.168.159.100,port6381,stateonline,offset490,lag0 slave1:ip192.168.159.100,port6382,stateonline,offset490,lag0 master_failover_state:no-failover master_replid:efa9c1b74416340cf0a5cc2b02272fedd6344570 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:490 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:490测试主从复制 2哨兵配置Sentinel 简要过程 需要启动三个redis-sentinel服务分别运行于26380、26381、26382三个端口同样也需要配置.conf文件运行服务 首先需要在/usr/local/redis/redis-6.2.6目录下拷贝三份sentinel.conf文件到redis-cluster文件夹下 # 拷贝文件sentinel.conf [rootvinjcent redis-6.2.6]# cp sentinel.conf ../redis-cluster/sentinel-26380.conf [rootvinjcent redis-6.2.6]# cp sentinel.conf ../redis-cluster/sentinel-26381.conf [rootvinjcent redis-6.2.6]# cp sentinel.conf ../redis-cluster/sentinel-26382.conf修改所拷贝的配置文件以sentinel-26380.conf为例配置信息如下其余两个配置文件基本上一致改一下端口以及pidfile、logfile即可 # 配置端口 port 26380 daemonize yes pidfile /usr/local/redis/redis-cluster/sentinel-26380.pid logfile /usr/local/redis/redis-cluster/sentinel-26380.log# 监控192.168.159.100:6380的主节点,实例取名为mymaster,当有两个哨兵认为该服务下线后,自动进行故障转移 # 后面的数字1,代表主机宕机了后,slave投票看让谁接替成为主机,票数最多的,就会成为主机,默认是2 sentinel monitor mymaster 192.168.159.100 6380 1 # 设置主节点多长时间没有响应就代表挂了,默认是30s sentinel down-after-milliseconds mymaster 30000 # 故障转移的时间上限,默认是三分钟 sentinel failover-timeout mymaster 180000 # 此配置值在发生故障时,最多可以有几个slave同时对新的master进行同步,这个数字越小完成故障处理的时间越短 sentinel parallel-syncs mymaster 1分别启动三个哨兵服务 [rootvinjcent redis-cluster]# /usr/local/redis/bin/redis-sentinel sentinel-26380.conf [rootvinjcent redis-cluster]# /usr/local/redis/bin/redis-sentinel sentinel-26381.conf [rootvinjcent redis-cluster]# /usr/local/redis/bin/redis-sentinel sentinel-26382.conf 随意连接一个哨兵查看哨兵监控信息 [rootvinjcent redis-cluster]# ../bin/redis-cli -p 26381查看6380节点的哨兵日志 [rootvinjcent redis-cluster]# tail -200f sentinel-26380.log1 测试哨兵模式 关闭主节点6380再看哨兵日志 从上面的日志文件中我们可以看到哨兵投票选举master以及切换主节点的大概过程这时候主节点已经切换到6381节点了 这时候再重新启动6380节点也就是之前的主节点这个节点会被哨兵自动加入到集群中作为从节点sentinel会打印如下日志 可以看到6380这个节点由主节点转换成了从节点 在整合springboot之前首先要开放redis集群的防火墙端口不然连接不上我们的redis服务 # 开放端口 firewall-cmd --zonepublic --add-port6380/tcp --permanent firewall-cmd --zonepublic --add-port6381/tcp --permanent firewall-cmd --zonepublic --add-port6382/tcp --permanent firewall-cmd --zonepublic --add-port26380/tcp --permanent firewall-cmd --zonepublic --add-port26381/tcp --permanent firewall-cmd --zonepublic --add-port26382/tcp --permanent # 重启防火墙 systemctl restart firewalld.service # 查看端口 firewall-cmd --list-ports3 springboot配置redis集群及读写分离 创建一个springboot项目 导入依赖 pom.xml !--redis-- dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId /dependency !--连接池依赖-- dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-pool2/artifactId /dependency !--web-- dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId /dependency !--lombok-- dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.24/version /dependency配置文件 application.yml server:port: 3035 spring:redis:# redis哨兵配置sentinel:# 主节点名称master: mymasternodes:- 192.168.159.100:26380- 192.168.159.100:26381- 192.168.159.100:26382 # # 集群的部署方式 # cluster: # nodes: # - 192.168.158.100:6380 # - 192.168.158.100:6381 # - 192.168.158.100:6382 # # #最大重定向次数由于集群中数据存储在多个节点,所以在访问数据时需要通过转发进行数据定位 # max-redirects: 2 # lettuce: # pool: # max-idle: 10 # 连接池中的最大空闲连接 # max-wait: 500 # 连接池最大阻塞等待时间使用负值表示没有限制 # max-active: 8 # 连接池最大连接数使用负值表示没有限制 # min-idle: 0 # 连接池中的最小空闲连接# 服务应用名application:name: redis-cluster logging:pattern:console: %date{yyyy-MM-dd HH:mm:ss.SSS} | %highlight(%5level) [%green(%16.16thread)] %clr(%-50.50logger{49}){cyan} %4line -| %highlight(%msg%n)level:root: infoio.lettuce.core: debugorg.springframework.data.redis: debug配置读写分离以及json序列化 package com.vinjcent.config;import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; import io.lettuce.core.ReadFrom; import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisSentinelConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;import java.text.SimpleDateFormat; import java.util.HashSet;Configuration public class RedisConfiguration {/**** 配置redis序列化json* param redisConnectionFactory* return*/BeanPrimary //若有相同类型的Bean时优先使用此注解标注的Beanpublic RedisTemplateString, Object redisTemplate(RedisConnectionFactory redisConnectionFactory) {// 为了开发方便,一般直接使用String, ObjectRedisTemplateString, Object template new RedisTemplate();template.setConnectionFactory(redisConnectionFactory);// 配置具体的序列化方式// JSON解析任意对象Jackson2JsonRedisSerializer jackson2JsonRedisSerializer new Jackson2JsonRedisSerializer(Object.class);ObjectMapper om new ObjectMapper();// 指定要序列化的域,field,get和set,以及修饰符范围ANY是都有包括private和publicom.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);// 指定序列化输入的类型类必须是非final修饰的final修饰的类比如String,Integer等会跑出异常om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);// 设置日期格式om.setDateFormat(new SimpleDateFormat(yyyy-MM-dd HH:mm:ss));jackson2JsonRedisSerializer.setObjectMapper(om);// String的序列化StringRedisSerializer stringRedisSerializer new StringRedisSerializer();//key采用String的序列化template.setKeySerializer(stringRedisSerializer);//hash的key也采用String的序列化template.setHashKeySerializer(stringRedisSerializer);//value的序列化方式采用jacksontemplate.setValueSerializer(jackson2JsonRedisSerializer);//hash的value序列化方式采用jacksontemplate.setHashValueSerializer(jackson2JsonRedisSerializer);//设置所有配置template.afterPropertiesSet();return template;}/*** 配置读写分离* param redisProperties* return*/Beanpublic RedisConnectionFactory lettuceConnectionFactory(RedisProperties redisProperties) {// 配置哨兵节点以及主节点RedisSentinelConfiguration redisSentinelConfiguration new RedisSentinelConfiguration(redisProperties.getSentinel().getMaster(), new HashSet(redisProperties.getSentinel().getNodes()));// 配置读写分离LettucePoolingClientConfiguration lettuceClientConfiguration LettucePoolingClientConfiguration.builder()// 读写分离,这里的ReadFrom是配置Redis的读取策略,是一个枚举,包括下面选择// MASTER 仅读取主节点// MASTER_PREFERRED 优先读取主节点,如果主节点不可用,则读取从节点// REPLICA_PREFERRED 优先读取从节点,如果从节点不可用,则读取主节点// REPLICA 仅读取从节点// NEAREST 从最近节点读取// ANY 从任意一个从节点读取.readFrom(ReadFrom.REPLICA_PREFERRED).build();return new LettuceConnectionFactory(redisSentinelConfiguration, lettuceClientConfiguration);}}编写一个测试的Bean package com.vinjcent.serivce;import com.vinjcent.utils.RedisUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component;import java.util.concurrent.TimeUnit;SuppressWarnings(all) Slf4j RequiredArgsConstructor Component public class RedisInit implements ApplicationRunner {Autowiredprivate RedisUtils redisUtils;Overridepublic void run(ApplicationArguments args) throws Exception {for (int i 0; i 300; i) {try {redisUtils.set(k i, v i);log.info(set value success: {}, i);Object val redisUtils.get(k i);log.info(get value success: {}, val);TimeUnit.SECONDS.sleep(1);} catch (Exception e) {log.error(error: {}, e.getMessage());}}log.info(finished...);} }封装redis工具类《RedisTemplate序列化RedisUtils工具类》 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils;import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit;SuppressWarnings(all) Component public final class RedisUtils {// ...... }启动该工程 可以在控制台看到写入是在6380端口的redis服务端而读取是在6382端口的redis服务端 随便进入一个redis-cli客户端可以看到主从复制实现成功 测试哨兵模式 停止主节点6380的redis服务端查看控制台 可以看到我们的主节点变成了6381端口的redis服务端由从节点成为主节点实现写的功能而从节点是6382端口的服务端
http://www.pierceye.com/news/731583/

相关文章:

  • 校园文化建设图片网站浅析图书馆门户网站建设
  • 网站开发与应用案例教程哈尔滨自助建站系统
  • 网站关键词排名seo百度网址链接是多少
  • 电子商务网站的建设收益直播软件的app
  • 遵义在百度做个网站多少钱如何建立企业网站
  • 我想做个网站手机网站建设优势
  • 网站制作毕业设计滁州市建设局网站
  • saas建站和开源建站的区别比较高端的网页
  • 新公司董事长致辞做网站wordpress二次开发手册chm
  • 网站显示建设中大型企业网站制作
  • 长沙自动化网站建设wordpress 自定义栏目 调用
  • 吉大建设工程学院官方网站wordpress 文章图片插件
  • 赤峰中国建设招标网站网页设计素材网站推荐
  • 天津网站建设电焊机wordpress主题jenney
  • 个人网站制作wordpress英文注册查询网站
  • 哪里有免费网站空间申请wordpress重定向插件
  • 福州微网站开发什么样的网站快速盈利
  • 吉首市建设局官方网站一对一直播软件开发定制
  • 网站开发验收单做的网站如何被百度搜到
  • 网站的数据库是什么两学一做网站链接
  • 做窗帘网站济南网络科技公司排名
  • 广东省住房城乡建设部网站哪个网站可以做加工代理的
  • dede网站源码打包下载wordpress登不进后台
  • 建设内部网站目的国内贸易在那个网站上做
  • 用什么建设网站注册深圳公司代理
  • 网站平台建设方案书百度云资源搜索入口
  • 网站 团队博罗网站建设哪家便宜
  • wordpress列表分页枣庄seo外包
  • 知了网站后台推广形式有哪几种
  • 成品图片的网站在哪里找wordpress开启防盗链