问题描述
目前,我有3台服务器:一台主服务器和2台客户端。我用PostgreSQL 9.6安装了redmine 3.3.1.stable,并在3台服务器上安装了起搏器。要同步数据库,请遵循documentation。在停止活动服务器之前,一切正常。 server2 redmine显示身份验证错误。
在连接服务器后尝试登录表单客户端时出现Redmine错误。
Completed 500 Internal Server Error in 11ms (ActiveRecord: 3.5ms)
ActiveRecord::StatementInvalid (PG::ReadOnlySqlTransaction: ERROR: cannot execute UPDATE in a read-only transaction
: UPDATE "users" SET "last_login_on" = '2020-08-17 13:05:11.001886' WHERE "users"."type" IN ('User','AnonymousUser') AND "users"."id" = $1):
app/models/user.rb:238:in `try_to_login'
app/controllers/account_controller.rb:204:in `password_authentication'
app/controllers/account_controller.rb:199:in `authenticate_user'
app/controllers/account_controller.rb:40:in `login'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
到目前为止,我对redmine的了解仅是允许server1访问权限。为什么Redmine无法授予对server2或server3的访问权限
下面我将提供到目前为止的详细信息。
pcs配置
pcs config
Cluster Name: mycluster
Corosync Nodes:
server1 server2 server3
Pacemaker Nodes:
server1 server2 server3
Resources:
Resource: MasterVip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: ip=101.226.189.208 nic=lo cidr_netmask=32 iflabel=pgrepvip
Meta Attrs: target-role=Started
Operations: start interval=0s timeout=20s (MasterVip-start-interval-0s)
stop interval=0s timeout=20s (MasterVip-stop-interval-0s)
monitor interval=90s (MasterVip-monitor-interval-90s)
Resource: Apache (class=ocf provider=heartbeat type=apache)
Attributes: configfile=/etc/apache2/apache2.conf statusurl=http://localhost/server-status
Operations: start interval=0s timeout=40s (Apache-start-interval-0s)
stop interval=0s timeout=60s (Apache-stop-interval-0s)
monitor interval=1min (Apache-monitor-interval-1min)
Stonith Devices:
Fencing Levels:
Location Constraints:
Resource: Apache
Enabled on: server1 (score:INFINITY) (role: Started) (id:cli-prefer-Apache)
Ordering Constraints:
Colocation Constraints:
Apache with MasterVip (score:INFINITY) (id:colocation-Apache-MasterVip-INFINITY)
Ticket Constraints:
Alerts:
No alerts defined
Resources Defaults:
migration-threshold: 5
resource-stickiness: 10
Operations Defaults:
No defaults set
Cluster Properties:
cluster-infrastructure: corosync
cluster-name: mycluster
dc-version: 1.1.16-94ff4df
have-watchdog: false
no-quorum-policy: ignore
stonith-enabled: false
Quorum:
Options:
主postgresql.conf
# Add settings for extensions here
listen_addresses = '*'
wal_level = hot_standby
synchronous_commit = local
archive_mode = on
archive_command = 'cp %p /var/lib/postgresql/9.6/main/archive/%f'
max_wal_senders = 10
wal_keep_segments = 30
synchronous_standby_names = 'server2'
synchronous_standby_names = 'server3'
hot_standby = on
主pg_hba.conf
# Localhost
host replication postgres 127.0.0.1/32 md5
# PostgreSQL Master IP address
host replication postgres 101.226.189.205/32 md5
# PostgreSQL SLave IP address
host replication postgres 101.226.189.206/32 md5
ho
st replication postgres 101.226.189.207/32 md5
从主服务器复制配置到客户端
pg_basebackup -h server1 -U postgres -D /var/lib/postgresql/9.6/main -X stream -P
数据库连接状态
postgres@oreo:/etc/postgresql/9.6/main$ psql -x -c "select * from pg_stat_replication;"
-[ RECORD 1 ]----+------------------------------
pid | 18174
usesysid | 10
usename | postgres
application_name | server3
client_addr | 101.226.189.207
client_hostname |
client_port | 35236
backend_start | 2020-08-17 15:56:40.687282+02
backend_xmin |
state | streaming
sent_location | 0/7005430
write_location | 0/7005430
flush_location | 0/7005430
replay_location | 0/7005430
sync_priority | 1
sync_state | sync
-[ RECORD 2 ]----+------------------------------
pid | 18175
usesysid | 10
usename | postgres
application_name | server2
client_addr | 101.226.189.206
client_hostname |
client_port | 45862
backend_start | 2020-08-17 15:56:40.717087+02
backend_xmin |
state | streaming
sent_location | 0/7005430
write_location | 0/7005430
flush_location | 0/7005430
replay_location | 0/7005430
sync_priority | 0
sync_state | async
解决方法
我找到了问题的答案。我错过了心脏起搏器资源的一步。
pgsqld定义了PostgreSQL实例的属性:它的位置,二进制文件,配置文件,如何监视它,等等。
pgsql-ha资源控制集群中所有PostgreSQL实例pgsqld,决定在哪里升级主数据库以及在哪里启动备用数据库。
pcs resource create pgsqld ocf:heartbeat:pgsqlms \
bindir="/usr/lib/postgresql/9.6/bin" \
pgdata="/etc/postgresql/9.6/main" \
datadir="/var/lib/postgresql/9.6/main" \
pghost="/var/run/postgresql" \
recovery_template="/etc/postgresql/9.6/main/recovery.conf.pcmk" \
op start timeout=60s \
op stop timeout=60s \
op promote timeout=30s \
op demote timeout=120s \
op monitor interval=15s timeout=10s role="Master" \
op monitor interval=16s timeout=10s role="Slave" \
op notify timeout=60s
pcs resource master pgsql-ha pgsqld notify=true
pcs resource cleanup
pcs status