赞
踩
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum -y install gcc && yum -y install gcc-c++
yum-utils
软件包yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl start docker && ps -aux | grep docker
在本地找不到,会到远程仓库查找镜像
docker run hello-world
systemctl stop docker && ps -aux | grep docker
systemctl enable docker && systemctl is-enabled docker
https://cr.console.aliyun.com/cn-beijing/instances
mkdir -p /etc/docker && tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://s0qrw5u9.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker && ps -aux | grep docker
docker pull redis:6.0.8
mkdir -p /app/redis
cd /opt && tar -zxvf redis-6.0.8.tar.gz
cp /opt/redis-6.0.8/redis.conf /app/redis/redis.conf
ll /app/redis
vim /app/redis/redis.conf
docker run -p 6480:6379 --name redis-cluster --privileged=true \
-v /app/redis/redis.conf:/etc/redis/redis.conf \
-v /app/redis/data:/data -d redis:6.0.8 \
redis-server /etc/redis/redis.conf
docker exec -it redis-cluster /bin/bash
redis-cli -p 6379 -a
systemctl start firewalld && firewall-cmd --permanent --add-port=6480/tcp && firewall-cmd --reload && firewall-cmd --query-port=6480/tcp
https://cr.console.aliyun.com/cn-beijing/instance/repositories
docker commit -m="[提交的信息]" -a="[作者名字]" [ImageId] [名称:版本号]
docker commit -m="redis集群基础镜像" -a="sun" 85e0dc53515f redis-cluster:1.0
docker login --username=aliyun8104181328 registry.cn-beijing.aliyuncs.com
docker tag [ImageId] registry.cn-beijing.aliyuncs.com/sunxiansheng/redis-cluster:[镜像版本号]
docker tag 5f123e2adb2c registry.cn-beijing.aliyuncs.com/sunxiansheng/redis-cluster:1.0
docker push registry.cn-beijing.aliyuncs.com/sunxiansheng/redis-cluster:[镜像版本号]
docker push registry.cn-beijing.aliyuncs.com/sunxiansheng/redis-cluster:1.0
docker pull registry.cn-beijing.aliyuncs.com/sunxiansheng/redis-cluster:[镜像版本号]
docker pull registry.cn-beijing.aliyuncs.com/sunxiansheng/redis-cluster:1.0
rm -rf /app/redis
docker rm -f redis-cluster
mkdir -p /app/redis && touch /app/redis/redis.conf
docker run -p 6480:6379 --name redis-cluster --privileged=true \
-v /app/redis/redis.conf:/etc/redis/redis.conf \
-v /app/redis/data:/data -d registry.cn-beijing.aliyuncs.com/sunxiansheng/redis-cluster:1.0 \
redis-server /etc/redis/redis.conf
docker pull redis:6.0.8
mkdir -p /app/redis
scp 源用户@源ip:源文件 目标用户@目标ip:目标文件夹
docker run -p 6480:6379 --name redis-cluster --privileged=true \
-v /app/redis/redis.conf:/etc/redis/redis.conf \
-v /app/redis/data:/data -d redis:6.0.8 \
redis-server /etc/redis/redis.conf
docker exec -it redis-cluster /bin/bash
redis-cli -p 6379 -a
systemctl start firewalld && firewall-cmd --permanent --add-port=6480/tcp && firewall-cmd --reload && firewall-cmd --query-port=6480/tcp
vim /app/redis/redis.conf
docker restart redis-cluster
systemctl start firewalld && firewall-cmd --permanent --add-port=16480/tcp && firewall-cmd --reload && firewall-cmd --query-port=16480/tcp
docker rm -f redis-cluster
docker run -d --name redis-node-1 --net=host --privileged=true \
-v /app/redis/data:/data \
-v /app/redis/redis.conf:/etc/redis/redis.conf \
redis:6.0.8 \
redis-server /etc/redis/redis.conf \
--cluster-enabled yes \
--appendonly yes \
--dir /data \
--port 6480 \
--cluster-config-file /data/nodes.conf \
--cluster-node-timeout 5000
ll /app/redis/data/
docker exec -it redis-node-5 /bin/bash
redis-cli -p 6480 --askpass
redis-cli --cluster create --cluster-replicas 1 --askpass
redis-cli -c -p 6480 --askpass
CLUSTER INFO
CLUSTER NODES
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sun.redis</groupId> <artifactId>redis_springboot</artifactId> <version>1.0-SNAPSHOT</version> <name>Archetype - redis_springboot</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.6</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <!-- 说 明 : 如 果 这 里 是 spring-boot-start 就 改 成 如 下 spring-boot-start-web--> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- spring2.X 集成 redis 所需 common-pool--> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <!--不要带版本号,防止冲突--> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.13.2.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
# redis集群配置 spring: redis: password: # Redis服务器密码 database: 0 # 默认数据库为0号 timeout: 10000ms # 连接超时时间是10000毫秒 lettuce: pool: max-active: 8 # 最大活跃连接数,使用负值表示没有限制,最佳配置为核数*2 max-wait: 10000ms # 最大等待时间,单位为毫秒,使用负值表示没有限制,这里设置为10秒 max-idle: 200 # 最大空闲连接数 min-idle: 5 # 最小空闲连接数 cluster: nodes:
package com.sun.redis.config; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import java.time.Duration; /** * Description: * * @Author sun * @Create 2024/4/29 21:29 * @Version 1.0 */ @EnableCaching @Configuration public class RedisConfig extends CachingConfigurerSupport { @Bean public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { RedisTemplate<String, Object> template = new RedisTemplate<>(); System.out.println("template=>" + template); RedisSerializer<String> redisSerializer = new StringRedisSerializer(); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.activateDefaultTyping( LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY); jackson2JsonRedisSerializer.setObjectMapper(om); template.setConnectionFactory(factory); // key 序列化方式 template.setKeySerializer(redisSerializer); // value 序列化 template.setValueSerializer(jackson2JsonRedisSerializer); // value hashmap 序列化 template.setHashValueSerializer(jackson2JsonRedisSerializer); return template; } @Bean public CacheManager cacheManager(RedisConnectionFactory factory) { RedisSerializer<String> redisSerializer = new StringRedisSerializer(); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); // 解决查询缓存转换异常的问题 ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.activateDefaultTyping( LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY); jackson2JsonRedisSerializer.setObjectMapper(om); // 配置序列化(解决乱码的问题),过期时间 600 秒 RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() .entryTtl(Duration.ofSeconds(600)) .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)) .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)) .disableCachingNullValues(); RedisCacheManager cacheManager = RedisCacheManager.builder(factory) .cacheDefaults(config) .build(); return cacheManager; } }
vim /app/redis/redis.conf
docker restart 。。。
docker run -d --name redis-node-7 --net=host --privileged=true \
-v /app/redis/nodes7data:/data \
-v /app/redis/redis.conf:/etc/redis/redis.conf \
redis:6.0.8 \
redis-server /etc/redis/redis.conf \
--cluster-enabled yes \
--appendonly yes \
--dir /data \
--port 6481 \
--cluster-config-file /data/nodes7.conf \
--cluster-node-timeout 5000
systemctl start firewalld && firewall-cmd --permanent --add-port=6481/tcp && firewall-cmd --reload && firewall-cmd --query-port=6481/tcp && systemctl start firewalld && firewall-cmd --permanent --add-port=16481/tcp && firewall-cmd --reload && firewall-cmd --query-port=16481/tcp
docker run -d --name redis-node-8 --net=host --privileged=true \
-v /app/redis/nodes8data:/data \
-v /app/redis/redis.conf:/etc/redis/redis.conf \
redis:6.0.8 \
redis-server /etc/redis/redis.conf \
--cluster-enabled yes \
--appendonly yes \
--dir /data \
--port 6482 \
--cluster-config-file /data/nodes8.conf \
--cluster-node-timeout 5000
systemctl start firewalld && firewall-cmd --permanent --add-port=6482/tcp && firewall-cmd --reload && firewall-cmd --query-port=6482/tcp && systemctl start firewalld && firewall-cmd --permanent --add-port=16482/tcp && firewall-cmd --reload && firewall-cmd --query-port=1648
2/tcp
docker exec -it redis-node-7 /bin/bash
redis-cli --cluster add-node --askpass
redis-cli --cluster check --askpass
redis-cli --cluster reshard --askpass
redis-cli --cluster check --askpass
redis-cli --cluster add-node --cluster-slave --cluster-master-id a9d42be282f99864cf95500ca909ae55dab5eb6b --askpass
redis-cli --cluster check --askpass
redis-cli --cluster check --askpass
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。