首页 > 数据库 >Redis3主3从+pg1主2从

Redis3主3从+pg1主2从

时间:2024-02-19 20:33:34浏览次数:31  
标签:postgres redis Redis3 cluster pg pg1 root 11.146

目录

一、环境准备

节点类别 主机名 IP
主库 re_pg1 11.146.123.11
备库1 re_pg2 11.146.123.12
备库2 re_pg3 11.146.123.13

二、安装服务器部署redis集群

1. 安装需求

(1)获取Redis集群安装包(redis-cluster.tar.gz)。
(2)执行如下命令,创建Redis主目录,将安装包放入新建的主目录,并进行解压。
(3)在11.146.123.11/12/13上都需要执行,安装

2. 创建redis

groupadd redis
useradd -g redis redis 
passwd redis
redis123
mkdir -p /app/redis-cluster

3. 上传软件

chown -R redis:redis /app/redis-cluster
su - redis
cd /app/redis-cluster   
tar -xvf redis-cluster.tar.gz  #确保此时已经把安装包放在主目录下

4. 编译安装

4.1 编译安装 root用户编译 否则 问题一

 cd redis-5.0.5/
 make && make install

4.2 验证安装是否成功

redis-server

4.3 操作过程

[root@localhost redis-5.0.5]# su - redis
Last login: Tue Jul 11 13:30:25 CST 2023 on pts/0
[redis@localhost ~]$ cd /app/redis-cluster/redis-5.0.5/
[redis@localhost redis-5.0.5]$ redis-server
125639:C 11 Jul 2023 13:57:28.315 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
125639:C 11 Jul 2023 13:57:28.315 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=125639, just started
125639:C 11 Jul 2023 13:57:28.315 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 125639
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

125639:M 11 Jul 2023 13:57:28.316 # Server initialized
125639:M 11 Jul 2023 13:57:28.316 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
125639:M 11 Jul 2023 13:57:28.316 * Ready to accept connections
^C125639:signal-handler (1689055082) Received SIGINT scheduling shutdown...
125639:M 11 Jul 2023 13:58:02.997 # User requested shutdown...
125639:M 11 Jul 2023 13:58:02.997 * Saving the final RDB snapshot before exiting.
125639:M 11 Jul 2023 13:58:03.000 * DB saved on disk
125639:M 11 Jul 2023 13:58:03.000 # Redis is now ready to exit, bye bye...
[redis@localhost redis-5.0.5]$

如果成功,将显示以下画面
image.png
按Ctrl+C退出当前操作

5. 新建redis集群配置文件

5.1 新建配置文件目录,复制模板配置文件

cd /app/redis-cluster
mkdir -p cluster/7008
mkdir -p cluster/7009
mkdir -p run
cp redis-5.0.5/redis.conf cluster/7008/redis.conf
cp redis-5.0.5/redis.conf cluster/7009/redis.conf 

5.2 修改默认配置文件

cd /app/redis-cluster/cluster/7008

vi redis.conf
bind XXX.XXX.XXX.XXX     #69行,设置本机ip
port 7008                #92行,设置端口
masterauth dba_OPS_123  #293行,设置集群密码
requirepass dba_OPS_123   #507行,设置集群密码,必须与masterauth设置的保持一样 
pidfile /app/redis-cluster/run/redis_7008.pid   #158行,设置pid文件

6.部署步骤

6.1 启动redis集群节点

cd /app/redis-cluster/cluster/7008
redis-server redis.conf
cd /app/redis-cluster/cluster/7009
redis-server redis.conf

wps41a307804-38cc-45e6-a547-5eb8da74d3b5.jpg

6.2 验证节点是否启动成功

ps -ef|grep redis

image.png

6.3 创建redis集群

[redis@localhost 7009]$ redis-cli --cluster create 11.146.123.11:7008 11.146.123.12:7008 11.146.123.13:7008 11.146.123.11:7009 11.146.123.12:7009 11.146.123.13:7009 --cluster-replicas 1 -a dba_OPS_123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 11.146.123.12:7009 to 11.146.123.11:7008
Adding replica 11.146.123.13:7009 to 11.146.123.12:7008
Adding replica 11.146.123.11:7009 to 11.146.123.13:7008
M: 9d40978ae40e11d107bd84e8efbc3761ca7054a0 11.146.123.11:7008
   slots:[0-5460] (5461 slots) master
M: f83f8b6b2ada203748d13792f7cf5a523661bf9e 11.146.123.12:7008
   slots:[5461-10922] (5462 slots) master
M: e42135e33cfe73108801cd233e04d17b092629e1 11.146.123.13:7008
   slots:[10923-16383] (5461 slots) master
S: c76beeb83e023e9a1926c20a3a464dab6164e8ab 11.146.123.11:7009
   replicates e42135e33cfe73108801cd233e04d17b092629e1
S: 3ef880fa4fae670b23238ca4ec5a8ec04b42f882 11.146.123.12:7009
   replicates 9d40978ae40e11d107bd84e8efbc3761ca7054a0
S: 8b435200588fbc37cd44f6d1d01b13dd908dbf04 11.146.123.13:7009
   replicates f83f8b6b2ada203748d13792f7cf5a523661bf9e
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...
>>> Performing Cluster Check (using node 11.146.123.11:7008)
M: 9d40978ae40e11d107bd84e8efbc3761ca7054a0 11.146.123.11:7008
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: f83f8b6b2ada203748d13792f7cf5a523661bf9e 11.146.123.12:7008
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: e42135e33cfe73108801cd233e04d17b092629e1 11.146.123.13:7008
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 3ef880fa4fae670b23238ca4ec5a8ec04b42f882 11.146.123.12:7009
   slots: (0 slots) slave
   replicates 9d40978ae40e11d107bd84e8efbc3761ca7054a0
S: 8b435200588fbc37cd44f6d1d01b13dd908dbf04 11.146.123.13:7009
   slots: (0 slots) slave
   replicates f83f8b6b2ada203748d13792f7cf5a523661bf9e
S: c76beeb83e023e9a1926c20a3a464dab6164e8ab 11.146.123.11:7009
   slots: (0 slots) slave
   replicates e42135e33cfe73108801cd233e04d17b092629e1
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

6.4 查看集群状态

cd /home/redis-cluster/
redis-cli -c -h xxxxxxxxxxx -p 7008
cluster info

[redis@localhost 7009]$  redis-cli -c -h 11.146.123.11 -p 7008
11.146.123.11:7008> auth dba_OPS_123
OK
11.146.123.11:7008> cluster nodes
f83f8b6b2ada203748d13792f7cf5a523661bf9e 11.146.123.12:7008@17008 master - 0 1689063345000 2 connected 5461-10922
e42135e33cfe73108801cd233e04d17b092629e1 11.146.123.13:7008@17008 master - 0 1689063344957 3 connected 10923-16383
3ef880fa4fae670b23238ca4ec5a8ec04b42f882 11.146.123.12:7009@17009 slave 9d40978ae40e11d107bd84e8efbc3761ca7054a0 0 1689063344000 5 connected
8b435200588fbc37cd44f6d1d01b13dd908dbf04 11.146.123.13:7009@17009 slave f83f8b6b2ada203748d13792f7cf5a523661bf9e 0 1689063345960 6 connected
c76beeb83e023e9a1926c20a3a464dab6164e8ab 11.146.123.11:7009@17009 slave e42135e33cfe73108801cd233e04d17b092629e1 0 1689063344557 4 connected
9d40978ae40e11d107bd84e8efbc3761ca7054a0 11.146.123.11:7008@17008 myself,master - 0 1689063344000 1 connected 0-5460
11.146.123.11:7008>

6.5 关闭redis

[redis@localhost redis-5.0.5]$ redis-cli -c -h 11.146.123.11 -p 7008
11.146.123.11:7008> cluster info
NOAUTH Authentication required.
11.146.123.11:7008>  auth dba_OPS_123
OK
11.146.123.11:7008> shutdown
not connected>
not connected> exit
[redis@localhost redis-5.0.5]$ redis-cli -c -h 11.146.123.11 -p 7009
11.146.123.11:7009> shutdown
(error) NOAUTH Authentication required.
11.146.123.11:7009>  auth dba_OPS_123
OK
11.146.123.11:7009> shutdown
not connected>

三、安装pg主从复制

1. 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

2. 关闭selinux

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
cat /etc/selinux/config
setenforce 0

3. 配置YUM

[root@localhost ~]# cd /app
[root@localhost app]# cd redis-cluster
[root@localhost redis-cluster]# cd iso/
[root@localhost iso]# ll
total 10491904
-rw-r--r-- 1 root root 10743709696 Jul 11 18:27 CentOS-7-x86_64-Everything-1810.iso
[root@localhost iso]#  mkdir /media/cdrom

[root@localhost iso]# mount -o loop CentOS-7-x86_64-Everything-1810.iso /media/cdrom
mount: /dev/loop0 is write-protected, mounting read-only
[root@localhost iso]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   3.8G     0  3.8G   0% /dev
tmpfs                      3.9G     0  3.9G   0% /dev/shm
tmpfs                      3.9G   13M  3.8G   1% /run
tmpfs                      3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/RootVg-rootlv   10G   81M   10G   1% /
/dev/mapper/RootVg-usrlv    10G  4.0G  6.1G  40% /usr
/dev/sda1                  497M  178M  320M  36% /boot
/dev/mapper/RootVg-varlv    10G  599M  9.5G   6% /var
/dev/mapper/RootVg-optlv    10G  105M  9.9G   2% /opt
/dev/mapper/RootVg-applv    50G   11G   40G  21% /app
tmpfs                      781M     0  781M   0% /run/user/0
/dev/loop0                  11G   11G     0 100% /media/cdrom
[root@localhost iso]#


[root@localhost iso]#  cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
total 40
-rw-r--r--  1 root root  721 Jun  2  2021 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 Apr  8  2020 CentOS-Base.repo_bak
-rw-r--r--. 1 root root 1309 Apr  8  2020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Apr  8  2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Apr  8  2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Apr  8  2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Apr  8  2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 7577 Apr  8  2020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 Apr  8  2020 CentOS-x86_64-kernel.repo
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]#  mv * bak/

[root@observer1 yum.repos.d]# vi enmo.repo 
[Server]
name=local.repo
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0

4. yum依赖包

mount /dev/cdrom /mnt
yum install -y cmake make gcc zlib gcc-c++ perl readline readline-devel zlib zlib-devel perl python36 tcl openssl ncurses-devel openldap pam
yum -y groupinstall "Development Tools"
yum -y install yum-utils openjade docbook-dtds docbook-style-dsssl docbook-style-xsl

5. 修改主机名

   hostnamectl set-hostname re_pg1
   hostnamectl set-hostname re_pg2
   hostnamectl set-hostname re_pg3

6. 配置/etc/hosts

echo "11.146.123.11 re_pg1">> /etc/hosts
echo "11.146.123.12 re_pg2">> /etc/hosts
echo "11.146.123.13 re_pg3">> /etc/hosts

7. 安装pg15

groupadd postgres

useradd -g postgres postgres 

passwd postgres
postgres




mkdir -p /app/postgresql/{pgdata,archive,scripts,backup,pg15,soft}
上传软件pg15
chown -R postgres:postgres /app/postgresql
chmod -R 775 /app/postgresql
su - postgres
cd /app/postgresql/soft
tar zxvf postgresql-15.0.tar.gz
cd postgresql-15.0/
./configure --prefix=/app/postgresql/pg15 --without-readline

gmake && gmake install

make world && make install-world

8. 安装一主一从

export PGPORT=5432
export PGDATA=/app/postgresql/pgdata
export LANG=en_US.utf8
export PGHOME=/app/postgresql/pg15
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:
export PGDATABASE=postgres

/app/postgresql/pg15/bin/initdb -D /app/postgresql/pgdata -E UTF8 --locale=en_US.utf8 -U postgres

vi /app/postgresql/pgdata/postgresql.conf

listen_addresses = '*'        
port = 5432                      
max_connections = 100   
logging_collector = on  
log_directory = 'pg_log' 
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' 
log_file_mode = 0600  
log_truncate_on_rotation = on 
wal_level = replica 
archive_mode = on    
archive_command = 'test ! -f /postgresql/archive/%f && cp %p /postgresql/archive/%f'   
wal_sender_timeout = 60s  
max_wal_senders = 10  


create role repuser login encrypted password 'repuser123' replication;
 
vi pg_hba.conf
host all all 0.0.0.0/0 md5
host replication repuser 0.0.0.0/0 md5
 
 pg_ctl stop
 [postgres@node1 ~]$ 
[postgres@node1 ~]$ su - root
Password: 
Last login: Sat Nov  5 18:57:37 CST 2022 on pts/1
[root@node1 ~]# cd /tmp
[root@node1 tmp]# tar -zcvf pg.tar.gz postgresql

[root@node1 tmp] #    pg_ctl start

备库:
$ 
[postgres@node2 ~]$ su -  root
Password: 
Last login: Sat Nov  5 18:20:55 CST 2022 on pts/0
[root@node2 ~]# cd /tmp
[root@node2 tmp]#  scp re_pg1:/home/postgres/pg.tar.gz  ./
The authenticity of host 'node1 (192.168.3.3)' can't be established.
ECDSA key fingerprint is SHA256:jPtFDnb9chze1xKLufd71ZoE7y3aET7QcIlehcbmB48.
ECDSA key fingerprint is MD5:33:e3:c2:a9:12:3e:8a:6e:ae:e1:07:28:10:0f:bf:a6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node1,192.168.3.3' (ECDSA) to the list of known hosts.
root@node1's password: 
pg.tar.gz                                                                                                                                                                                                                                                                 100%   86MB  53.9MB/s   00:01    
[root@node2 tmp]# cd /
[root@node2 /]# tar -zvxf  /tmp/pg.tar.gz 
postgresql/
postgresql/pgdata/
postgresql/pgdata/pg_wal/
postgresql/pgdata/pg_wal/archive_status/
postgresql/pgdata/pg_wal/000000010000000000000003
 [postgres@node2 ~]$  cd /app/
[postgres@node2 ~]$ rm -rf /postgresql/pgdata
[postgres@node2 ~]$ pg_basebackup -D /postgresql/pgdata -F p -P -R -h 192.168.3.3 -p 5432 -U repuser -l backup20221105
Password: 
22988/22988 kB (100%), 1/1 tablespace
[postgres@node2 ~]$ cd /postgresql/soft
[postgres@node2 soft]$ cd ..
[postgres@node2 postgresql]$ ls
archive  backup  pg15  pgdata  scripts  soft
[postgres@node2 postgresql]$ 
[postgres@node2 postgresql]$ 
[postgres@node2 postgresql]$ cd pgdata/
[postgres@node2 pgdata]$ ll
total 200
-rw------- 1 postgres postgres    214 Nov  5 19:29 backup_label
-rw------- 1 postgres postgres 137860 Nov  5 19:29 backup_manifest
drwx------ 5 postgres postgres     33 Nov  5 19:29 base
-rw------- 1 postgres postgres     47 Nov  5 19:29 current_logfiles
drwx------ 2 postgres postgres   4096 Nov  5 19:29 global
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_commit_ts
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_dynshmem
-rw------- 1 postgres postgres   4925 Nov  5 19:29 pg_hba.conf
-rw------- 1 postgres postgres   1636 Nov  5 19:29 pg_ident.conf
drwx------ 2 postgres postgres    166 Nov  5 19:29 pg_log
drwx------ 4 postgres postgres     68 Nov  5 19:29 pg_logical
drwx------ 4 postgres postgres     36 Nov  5 19:29 pg_multixact
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_notify
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_replslot
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_serial
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_snapshots
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_stat
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_stat_tmp
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_subtrans
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_tblspc
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_twophase
-rw------- 1 postgres postgres      3 Nov  5 19:29 PG_VERSION
drwx------ 3 postgres postgres     60 Nov  5 19:29 pg_wal
drwx------ 2 postgres postgres     18 Nov  5 19:29 pg_xact
-rw------- 1 postgres postgres    332 Nov  5 19:29 postgresql.auto.conf
-rw------- 1 postgres postgres  29483 Nov  5 19:29 postgresql.conf
#-rw------- 1 postgres postgres      0 Nov  5 19:29 standby.signal                         《《《《《《《《《《《《《《《
 [postgres@node2 ~]$ 
[postgres@node2 ~]$ rm -rf /postgresql/pgdata
[postgres@node2 ~]$ pg_basebackup -D /postgresql/pgdata -F p -P -R -h 192.168.3.3 -p 5432 -U repuser -l backup20221105
Password: 
22988/22988 kB (100%), 1/1 tablespace
[postgres@node2 ~]$ cd /postgresql/soft
[postgres@node2 soft]$ cd ..
[postgres@node2 postgresql]$ ls
archive  backup  pg15  pgdata  scripts  soft
[postgres@node2 postgresql]$ 
[postgres@node2 postgresql]$ 
[postgres@node2 postgresql]$ cd pgdata/
[postgres@node2 pgdata]$ ll
total 200
-rw------- 1 postgres postgres    214 Nov  5 19:29 backup_label
-rw------- 1 postgres postgres 137860 Nov  5 19:29 backup_manifest
drwx------ 5 postgres postgres     33 Nov  5 19:29 base
-rw------- 1 postgres postgres     47 Nov  5 19:29 current_logfiles
drwx------ 2 postgres postgres   4096 Nov  5 19:29 global
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_commit_ts
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_dynshmem
-rw------- 1 postgres postgres   4925 Nov  5 19:29 pg_hba.conf
-rw------- 1 postgres postgres   1636 Nov  5 19:29 pg_ident.conf
drwx------ 2 postgres postgres    166 Nov  5 19:29 pg_log
drwx------ 4 postgres postgres     68 Nov  5 19:29 pg_logical
drwx------ 4 postgres postgres     36 Nov  5 19:29 pg_multixact
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_notify
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_replslot
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_serial
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_snapshots
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_stat
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_stat_tmp
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_subtrans
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_tblspc
drwx------ 2 postgres postgres      6 Nov  5 19:29 pg_twophase
-rw------- 1 postgres postgres      3 Nov  5 19:29 PG_VERSION
drwx------ 3 postgres postgres     60 Nov  5 19:29 pg_wal
drwx------ 2 postgres postgres     18 Nov  5 19:29 pg_xact
-rw------- 1 postgres postgres    332 Nov  5 19:29 postgresql.auto.conf
-rw------- 1 postgres postgres  29483 Nov  5 19:29 postgresql.conf
-rw------- 1 postgres postgres      0 Nov  5 19:29 standby.signal



[postgres@node2 pgdata]$ vi postgresql.conf 
 primary_conninfo = 'host=192.168.3.3 port=5432 user=repuser passowrd=repuser123'
[postgres@node2 pgdata]$ pg_ctl start
waiting for server to start....2022-11-05 19:40:27.609 CST [18318] LOG:  redirecting log output to logging collector process
2022-11-05 19:40:27.609 CST [18318] HINT:  Future log output will appear in directory "pg_log".
 done
server started
[postgres@node2 pgdata]$ 


[root@node1 tmp]# su - postgres 
Last login: Sat Nov  5 19:18:23 CST 2022 on pts/1
Last failed login: Sat Nov  5 19:18:26 CST 2022 on pts/2
There was 1 failed login attempt since the last successful login.
[postgres@node1 ~]$ psql
psql (15.0)
Type "help" for help.

postgres=# \d
Did not find any relations.
postgres=#  select * from pg_stat_replication;
  pid  | usesysid | usename | application_name | client_addr | client_hostname | client_port |         backend_start         | backend_xmin |   state   | sent_lsn  | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state |          reply_time           
-------+----------+---------+------------------+-------------+-----------------+-------------+-------------------------------+--------------+-----------+-----------+-----------+-----------+------------+-----------+-----------+------------+---------------+------------+-------------------------------
 29097 |    16388 | repuser | walreceiver      | 192.168.3.4 |                 |       20583 | 2022-11-05 19:40:28.307421+08 |              | streaming | 0/5000148 | 0/5000148 | 0/5000148 | 0/5000148  |           |           |            |             0 | async      | 2022-11-05 19:42:08.343567+08
(1 row)

postgres=# 


9. 1主2从(加从库)扩容

[postgres@node3 ~]$ 
[postgres@node3 ~]$ 
[postgres@node3 ~]$ rm -rf /app/postgresql/pgdata
[postgres@node3 ~]$ 
[postgres@node3 ~]$ 
[postgres@node3 ~]$ cd /tmp
[postgres@node3 tmp]$ 
[postgres@node3 tmp]$ 
[postgres@node3 tmp]$ pg_basebackup -D /postgresql/pgdata -F p -P -R -h 192.168.3.3 -p 5432 -U repuser -l backup20221105
Password: 
22989/22989 kB (100%), 1/1 tablespace
[postgres@node3 tmp]$


primary_conninfo = 'host=192.168.3.3 port=5432 user=repuser passowrd=repuser123'          
"postgresql.conf" 813L, 29541C written                                                                                                                                                                                                                                                    
[postgres@node3 pgdata]$ 
[postgres@node3 pgdata]$ 
[postgres@node3 pgdata]$ pg_ctl start
waiting for server to start....2022-11-05 20:04:37.402 CST [18560] LOG:  redirecting log output to logging collector process
2022-11-05 20:04:37.402 CST [18560] HINT:  Future log output will appear in directory "pg_log".
 done
server started
[postgres@node3 pgdata]$ 

主:

[postgres@re_pg1 ~]$
[postgres@re_pg1 ~]$
[postgres@re_pg1 ~]$ psql
WARNING: password file "/home/postgres/.pgpass" has group or world access; permissions should be u=rw (0600) or less
psql (15.0)
Type "help" for help.

postgres=# select * from pg_stat_replication;
  pid  | usesysid | usename | application_name |  client_addr  | client_hostname | client_port |        backend_start         | backend_xmin |   state   | sent_lsn  | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_la
g | sync_priority | sync_state |          reply_time
-------+----------+---------+------------------+---------------+-----------------+-------------+------------------------------+--------------+-----------+-----------+-----------+-----------+------------+-----------+-----------+----------
--+---------------+------------+-------------------------------
 54297 |    16388 | repuser | walreceiver      | 11.146.123.12 |                 |       49604 | 2023-07-12 10:25:08.60997+08 |              | streaming | 0/5000060 | 0/5000060 | 0/5000060 | 0/5000060  |           |           |
  |             0 | async      | 2023-07-12 10:45:31.365139+08
 55280 |    16388 | repuser | walreceiver      | 11.146.123.13 |                 |       40278 | 2023-07-12 10:44:33.4829+08  |              | streaming | 0/5000060 | 0/5000060 | 0/5000060 | 0/5000060  |           |           |
  |             0 | async      | 2023-07-12 10:45:33.548448+08
(2 rows)

postgres=#
postgres=#
postgres=#
postgres=# create table t (id int);
CREATE TABLE
postgres=# \d
        List of relations
 Schema | Name | Type  |  Owner
--------+------+-------+----------
 public | t    | table | postgres
(1 row)


postgres=# 
postgres=# 
postgres=# 

 cat >> ~/.pgpass << EOF
# hostname:port:database:username:password
11.146.123.11:5432:replication:repuser:repuser123
11.146.123.12:5432:replication:repuser:repuser123
11.146.123.13:5432:replication:repuser:repuser123
EOF

10. 安装pg_trgm

[postgres@re_pg1 ~]$ psql
WARNING: password file "/home/postgres/.pgpass" has group or world access; permissions should be u=rw (0600) or less
psql (15.0)
Type "help" for help.
## 二级标题
postgres=# create extension pg_trgm ;
CREATE EXTENSION
postgres=#
postgres=#
postgres=# \dx
                                    List of installed extensions
  Name   | Version |   Schema   |                            Description
---------+---------+------------+-------------------------------------------------------------------
 pg_trgm | 1.6     | public     | text similarity measurement and index searching based on trigrams
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
(2 rows)

四、遇到问题

1. 问题1、make && make install

    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/app/redis-cluster/redis-5.0.5/src'
cd src && make install
make[1]: Entering directory `/app/redis-cluster/redis-5.0.5/src'
    CC Makefile.dep
make[1]: Leaving directory `/app/redis-cluster/redis-5.0.5/src'
make[1]: Entering directory `/app/redis-cluster/redis-5.0.5/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
install: cannot create regular file ‘/usr/local/bin/redis-server’: Permission denied
make[1]: *** [install] Error 1
make[1]: Leaving directory `/app/redis-cluster/redis-5.0.5/src'
make: *** [install] Error 2
[redis@localhost redis-5.0.5]$ redis-server
bash: redis-server: command not found...
[redis@localhost redis-5.0.5]$

解决方法

make clean
用root 用户
make && make install

不清理会make不上

[root@localhost redis-5.0.5]#
[root@localhost redis-5.0.5]#
[root@localhost redis-5.0.5]#
[root@localhost redis-5.0.5]# make && make install
cd src && make all
make[1]: Entering directory `/app/redis-cluster/redis-5.0.5/src'

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/app/redis-cluster/redis-5.0.5/src'
cd src && make install
make[1]: Entering directory `/app/redis-cluster/redis-5.0.5/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/app/redis-cluster/redis-5.0.5/src'
[root@localhost redis-5.0.5]# make clean
cd src && make clean
make[1]: Entering directory `/app/redis-cluster/redis-5.0.5/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
make[1]: Leaving directory `/app/redis-cluster/redis-5.0.5/src'
[root@localhost redis-5.0.5]# make && make install
cd src && make all
make[1]: Entering directory `/app/redis-cluster/redis-5.0.5/src'
    CC Makefile.dep
make[1]: Leaving directory `/app/redis-cluster/redis-5.0.5/src'
make[1]: Entering directory `/app/redis-cluster/redis-5.0.5/src'

问题二、防火墙

[redis@localhost 7009]$ redis-cli --cluster create 11.146.123.11:7008 11.146.123.12:7009 11.146.123.12:7008 11.146.123.13:7009 11.14                                                                            6.123.13:7008 11.146.123.11:7009 --cluster-replicas 1 -a dba_OPS_123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 11.146.123.12:7009: No route to host
[redis@localhost 7009]$ exit
logout
[root@localhost ~]# systemctl status firedwall
Unit firedwall.service could not be found.
[root@localhost ~]# systemctl status firedwalld
Unit firedwalld.service could not be found.
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2023-07-05 10:11:12 CST; 6 days ago
     Docs: man:firewalld(1)
 Main PID: 843 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─843 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Jul 05 10:11:10 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Jul 05 10:11:12 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost ~]# systemctl stop firewalld.service
systemctl disable firewalld.service[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

Jul 05 10:11:10 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Jul 05 10:11:12 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Jul 11 15:12:28 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jul 11 15:12:29 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# su - redis
Last login: Tue Jul 11 15:04:44 CST 2023 on pts/1
[redis@localhost ~]$ cd /app/redis-cluster/
[redis@localhost redis-cluster]$ redis-cli --cluster create 11.146.123.11:7008 11.146.123.12:7009 11.146.123.12:7008 11.146.123.13:7009 11.146.123.13:7008 11.146.123.11:7009 --clust                           er-replicas 1 -a dba_OPS_123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 11.146.123.12:7008 to 11.146.123.11:7008
Adding replica 11.146.123.13:7008 to 11.146.123.12:7009
Adding replica 11.146.123.11:7009 to 11.146.123.13:7009
M: 8697a5fd014d8529335a617ab3cb35c041faf548 11.146.123.11:7008
   slots:[0-5460] (5461 slots) master
M: f7ce4d047d03ed20ed81be9f3b5a5777b30d6554 11.146.123.12:7009
   slots:[5461-10922] (5462 slots) master
S: 3a5b0518116db8adab94aaa451cbb1bc71e280df 11.146.123.12:7008
   replicates 8697a5fd014d8529335a617ab3cb35c041faf548
M: 02dadfd7eda184971291a15457b98d49cf2a61d5 11.146.123.13:7009
   slots:[10923-16383] (5461 slots) master
S: a829dca9d1a255b0e4a16a37604926b1f22f5342 11.146.123.13:7008
   replicates f7ce4d047d03ed20ed81be9f3b5a5777b30d6554
S: 0acd82b25995e8604df71d3f409e9e662b484f2e 11.146.123.11:7009
   replicates 02dadfd7eda184971291a15457b98d49cf2a61d5
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...
>>> Performing Cluster Check (using node 11.146.123.11:7008)
M: 8697a5fd014d8529335a617ab3cb35c041faf548 11.146.123.11:7008
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 02dadfd7eda184971291a15457b98d49cf2a61d5 11.146.123.13:7009
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: a829dca9d1a255b0e4a16a37604926b1f22f5342 11.146.123.13:7008
   slots: (0 slots) slave
   replicates f7ce4d047d03ed20ed81be9f3b5a5777b30d6554
S: 0acd82b25995e8604df71d3f409e9e662b484f2e 11.146.123.11:7009
   slots: (0 slots) slave
   replicates 02dadfd7eda184971291a15457b98d49cf2a61d5
S: 3a5b0518116db8adab94aaa451cbb1bc71e280df 11.146.123.12:7008
   slots: (0 slots) slave
   replicates 8697a5fd014d8529335a617ab3cb35c041faf548
M: f7ce4d047d03ed20ed81be9f3b5a5777b30d6554 11.146.123.12:7009
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[redis@localhost redis-cluster]$ redis-cli -c -h 11.146.123.11 -p 7008
11.146.123.11:7008> cluster info
NOAUTH Authentication required.
11.146.123.11:7008> auth dba_OPS_123
OK
11.146.123.11:7008> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:448
cluster_stats_messages_pong_sent:442
cluster_stats_messages_sent:890
cluster_stats_messages_ping_received:437
cluster_stats_messages_pong_received:448
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:890
11.146.123.11:7008> cluster nodes
02dadfd7eda184971291a15457b98d49cf2a61d5 11.146.123.13:7009@17009 master - 0 1689060037000 4 connected 10923-16383
a829dca9d1a255b0e4a16a37604926b1f22f5342 11.146.123.13:7008@17008 slave f7ce4d047d03ed20ed81be9f3b5a5777b30d6554 0 1689060036000 5 connected
8697a5fd014d8529335a617ab3cb35c041faf548 11.146.123.11:7008@17008 myself,master - 0 1689060037000 1 connected 0-5460
0acd82b25995e8604df71d3f409e9e662b484f2e 11.146.123.11:7009@17009 slave 02dadfd7eda184971291a15457b98d49cf2a61d5 0 1689060037557 6 connected
3a5b0518116db8adab94aaa451cbb1bc71e280df 11.146.123.12:7008@17008 slave 8697a5fd014d8529335a617ab3cb35c041faf548 0 1689060037658 3 connected
f7ce4d047d03ed20ed81be9f3b5a5777b30d6554 11.146.123.12:7009@17009 master - 0 1689060037055 2 connected 5461-10922
11.146.123.11:7008> exit
[redis@localhost redis-cluster]$
[redis@localhost redis-cluster]$
[redis@localhost redis-cluster]$ ll

标签:postgres,redis,Redis3,cluster,pg,pg1,root,11.146
From: https://www.cnblogs.com/xinxin1222/p/18021903

相关文章

  • PG14归档失败解决办法archiver failed on wal_lsn
    案例1:pg_wal下有wal_lsn文件案例1适用于以下场景:pg_wal下有该wal_lsn文件而归档目录下无该wal_lsn文件pg_wal和归档目录下同时都有该wal_lsn文件问题描述昨晚Repmgr+PG14主备主库因wal日志撑爆磁盘,删除主库过期wal文件重做备库后上午进行主备状态巡查,主库向备库发送wal文件正常,但......
  • 【Vagrant】 Build PG15 on rhel8
    vagrant创建一套singlePG15,同时创建一个新的数据库db_pg15(密同)Vagrant.configure("2")do|config|vms=[#{name:"app01",box:"centos-8",hostname:"app01",ip:"192.168.33.11"},#{name:"gitla......
  • Windows版Redis3.2X64部署教程
    1.使用的Redis-x64-3.2.100.ZIP解压版redis免安装版链接:https://pan.baidu.com/s/1MYmNxiY8JIOuXjVr0W_-5A 提取码:12342.下载完毕之后解压在你的安装目录内 3.启动服务端cmd进入文件夹中,执行:redis-serverredis.windows.conf如下就代表运行成功.如果失败重新解压尝试 ......
  • Docker|--E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of the
    错误apt-keyadv--keyserverkeyserver.ubuntu.com--recv-keys871920D1991BC93CE:gnupg,gnupg2andgnupg1donotseemtobeinstalled,butoneofthemisrequiredforthisoperation解决方案apt-getupdate&&apt-getinstall-ygnupg2#或者apt-getu......
  • pg10 安装pageinspect插件
    1.切换到源码包的contrib路径下,ls插件名称cd/data/soft/PostGreSQL/postgresql-10.20/contrib/pageinspect编译该插件makegcc-Wall-Wmissing-prototypes-Wpointer-arith-Wdeclaration-after-statement-Wendif-labels-Wmissing-format-attribute-Wformat-security-fn......
  • Docker|--E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of the
    错误apt-keyadv--keyserverkeyserver.ubuntu.com--recv-keys871920D1991BC93CE:gnupg,gnupg2andgnupg1donotseemtobeinstalled,butoneofthemisrequiredforthisoperation解决方案apt-getupdate&&apt-getinstall-ygnupg2#或者apt-getu......
  • repmgr+pg14实现自动切换
    一、环境配置三个节点安装数据库软件;三个节点安装repmgr软件;仅主库节点初始化数据库;三个节点修改repmgr配置文件(若未指出在主节点操作,其余操作均在三个节点进行)1.1软件准备软件下载https://www.postgresql.org/ftp/source/https://www.repmgr.org/PostgreSQL版本:postgre......
  • linux安装redis3.0
    linux安装redis3.01.把下载好的redis压缩包上传至app 解压完成之后,修改成redis文件夹 2.进入redis文件夹进行编译和安装cd /usr/local/redismakemakePREFIX=/usr/local/redisinstall/usr/local/redis目录下出现bin目录就是安装成功 3.修改配置文件可以修改端口......
  • POSTGRESQL PG15关于归档的新模式
    开头还是介绍一下群,如果感兴趣polardb,mongodb,mysql,postgresql ,redis等有问题,有需求都可以加群群内有各大数据库行业大咖,CTO,可以解决你的问题。加群请联系liuaustin3,在新加的朋友会分到3群(共810人左右1+2+3),这里需要注意,如果想和瑞典马工进行面对面的交流的同学,可......
  • 部署repmgr PG14集群<无autofailover>
    系统环境OS:CentOS7192.168.56.11node1192.168.56.12node2部署操作流程1.系统环境初始化echoredhat|passwdroot--stdinecho-e"192.168.56.11node1">>/etc/hostsecho-e"192.168.56.12node2">>/etc/hostsse......