分类 数据库 下的文章

https://www.macrozheng.com/blog/redis_cluster.html

在搭建Redis集群之前,我们需要修改下Redis的配置文件redis.conf,该文件的下载地址:https://github.com/antirez/redis/blob/5.0/redis.conf

# 开启集群功能
cluster-enabled yes
# 设置运行端口
port 6391
# 设置节点超时时间,单位毫秒
cluster-node-timeout 15000
# 集群内部配置文件
cluster-config-file "nodes-6391.conf"

然后我们需要编写docker-compose.yml文件用于编排6个Redis容器,具体属性的作用可以参考下面的注释;

version: "3"
services:
  redis-master1:
    image: redis:5.0 # 基础镜像
    container_name: redis-master1 # 容器名称
    working_dir: /config # 切换工作目录
    environment: # 环境变量
      - PORT=6391 # 会使用config/nodes-${PORT}.conf这个配置文件
    ports: # 映射端口,对外提供服务
      - 6391:6391 # redis的服务端口
      - 16391:16391 # redis集群监控端口
    stdin_open: true # 标准输入打开
    tty: true # 后台运行不退出
    network_mode: host # 使用host模式
    privileged: true # 拥有容器内命令执行的权限
    volumes:
      - /mydata/redis-cluster/config:/config #配置文件目录映射到宿主机
    entrypoint: # 设置服务默认的启动程序
      - /bin/bash
      - redis.sh
  redis-master2:
    image: redis:5.0
    working_dir: /config
    container_name: redis-master2
    environment:
      - PORT=6392
    ports:
      - 6392:6392
      - 16392:16392
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-master3:
    image: redis:5.0
    container_name: redis-master3
    working_dir: /config
    environment:
      - PORT=6393
    ports:
      - 6393:6393
      - 16393:16393
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-slave1:
    image: redis:5.0
    container_name: redis-slave1
    working_dir: /config
    environment:
      - PORT=6394
    ports:
      - 6394:6394
      - 16394:16394
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-slave2:
    image: redis:5.0
    working_dir: /config
    container_name: redis-slave2
    environment:
      - PORT=6395
    ports:
      - 6395:6395
      - 16395:16395
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-slave3:
    image: redis:5.0
    container_name: redis-slave3
    working_dir: /config
    environment:
      - PORT=6396
    ports:
      - 6396:6396
      - 16396:16396
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh

安装部署

sudo dnf update
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql14-server
#初始化
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl start postgresql-14

#修改数据库路径
sudo systemctl stop postgresql-14
sudo mv /var/lib/pgsql/14/data /data/pgsql
sudo ln -s /data/pgsql /var/lib/pgsql/14/data

#服务器IP绑定
#vi /data/pgsql/postgresql.conf 
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /data/pgsql/postgresql.conf 

#IP访问限制
#vi /data/pg_hba.conf
echo "host    all             all             192.168.1.0/24        md5" >> /data/pgsql/pg_hba.conf

#重新启动服务
sudo systemctl start postgresql-14
sudo systemctl enable postgresql-14
systemctl status postgresql-14

#密码修改
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'new_password';"

#防火墙
systemctl stop firewalld &&  systemctl disable firewalld

#常用命令
echo "sudo -u postgres pg_dump -U postgres -d $1 -f $1.sql" > /data/pgsql/backup/export.sh 
echo "sudo -u postgres psql -U postgres -d xxx_data < $1" > /data/pgsql/backup/inport.sh 
echo "sudo -u postgres psql -d xx_data" > /data/ssh/pgsql.sh 

参考地址

pgsql

CREATE DATABASE "gpt_data" WITH  OWNER = "postgres"  ENCODING = 'utF8';

mysql

CREATE DATABASE `cms_1` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';