一、Postgres的一些注意事项和问题(解决方法)
1.Postgres服务会报时区错误
容器内部默认使用的是UTC(Coordinated Universal Time,协调世界时间,也称格林威治时间),但是在不经过任何操作的情况下,会出现以下错误在postgres错误日志中:
< 2024-03-06 01:54:21.803 GMT > LOG: invalid value for parameter "log_timezone": "UTC"
< 2024-03-06 01:54:21.803 GMT > LOG: invalid value for parameter "TimeZone": "UTC"
< 2024-03-06 01:54:21.803 GMT > FATAL: configuration file "/var/lib/pgsql/9.6/data/postgresql.conf" contains errors
前两条时区时间看似没什么太大的影响,但是在经过错误排查后发现他们是导致第三条报错的根本原因(看似是配置文件有问题,但是解决时区报错后就不会再有配置文件这条错误了)
有两种解决方法,一是直接改变整个容器的Timezone为本地服务器时间,比较麻烦,所以不采用
二是修改配置文件中Timezone:修改postgresql.conf文件449行log_timezone = ‘Asia/Shanghai’,555行time_zone = ‘Asia/Shanghai’
来源于:https://www.jianshu.com/p/ce482f0f218d
在修改之后退出并重启服务,可以看到服务正常启动了
< 2024-03-06 10:09:13.489 CST > LOG: database system was interrupted; last known up at 2024-03-06 10:05:25 CST
< 2024-03-06 10:09:13.606 CST > LOG: database system was not properly shut down; automatic recovery in progress
< 2024-03-06 10:09:13.626 CST > LOG: redo starts at 4/C2642268
< 2024-03-06 10:09:13.627 CST > LOG: invalid record length at 4/C2644A50: wanted 24, got 0
< 2024-03-06 10:09:13.627 CST > LOG: redo done at 4/C2644A28
< 2024-03-06 10:09:13.627 CST > LOG: last completed transaction was at log time 2024-03-06 10:06:27.447627+08
< 2024-03-06 10:09:13.666 CST > LOG: MultiXact member wraparound protections are now enabled
< 2024-03-06 10:09:13.669 CST > LOG: database system is ready to accept connections
< 2024-03-06 10:09:13.669 CST > LOG: autovacuum launcher started
2.一些启动Postgres服务的注意事项
1)一些不同的参数对重启的影响
[root@9fa74ddef7a5 data]# sudo -u postgres /usr/pgsql-9.6/bin/pg_ctl -D $PGDATA -m fast /var/lib/pgsql/9.6/data/ -l /var/log/pgsql.log restart
快速关闭服务,使用的是fast模式来停止服务(让已有的事务回滚,然后正常关闭数据库)
[root@9fa74ddef7a5 bin]# sudo -u postgres ./pg_ctl stop -D $PGDATA -m immediate
立刻结束所有进程并且关闭服务
[root@35d7ea1b9ccb html]# sudo -u postgres /usr/pgsql-9.6/bin/pg_ctl -D /var/lib/pgsql/9.6/data/ start
server starting
[root@35d7ea1b9ccb html]# < 2024-03-06 01:10:35.512 UTC > FATAL: could not create lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
< 2024-03-06 01:10:35.513 UTC > LOG: database system is shut down
这个命令可以更直观的看到运行命令以后的情况,以上为例,会立刻得到由于权限问题无法创建锁文件导致服务再次被关闭(省去审阅错误日志的时间,可以立刻得到运行结果)
2)查看和postgres有关的进程信息
[root@9fa74ddef7a5 bin]# ps aux | grep postgres
root 124 0.0 0.0 10692 976 pts/1 S+ 12:23 0:00 grep --color=auto postgres
3)如果端口被占用可以通过以下方法来查看端口占用情况
[root@9fa74ddef7a5 httpd]# ss -tuln | grep 5432
tcp LISTEN 0 128 *:5432 *:*
tcp LISTEN 0 128 :::5432 :::*
如果想要查看这些被占用的详细信息可以通过
[root@9fa74ddef7a5 httpd]# ss -tulnep | grep 5432
tcp LISTEN 0 128 *:5432 *:* uid:26 ino:100236237 sk:ffff8b94b6bb07c0 <->
tcp LISTEN 0 128 :::5432 :::* uid:26 ino:100236238 sk:ffff8b9fa0e18840 v6only:1 <->
二、Apache出现的问题和解决方法
1.httpd里面的一些小问题和注意事项
1)迁移时重启httpd遇到的一些问题和解决方法
[lbmethod_heartbeat:notice] [pid 21] AH02282: No slotmem from mod_heartmonitor
因为httpd.conf文件里面没有调用这个模块的代码,但是外面的modules里面有这个模块下载了,于是在文件里面加载这个模块,后续其他模块(watchdog、mpm)依然同样以同样的方式加载
LoadModule heartmonitor_module modules/mod_heartmonitor.so
PS:在成功加载一次模块以后,就在conf文件里注释掉这些行,否则会导致重新加载,加载失败等问题出现
在过程中还遇到了一个有关共享内存的问题。共享内存是用来存放一些httpd缓存和过程文件的,下面的问题是共享内存初始化失败等问题,
[Wed Mar 06 07:47:38.398577 2024] [auth_digest:error] [pid 22] (17)File exists: AH01760: failed to initialize shm - all nonce-count checking, one-time nonces, and MD5-sess algorithm disabled
[Wed Mar 06 07:47:40.515451 2024] [auth_digest:error] [pid 26] (17)File exists: AH01760: failed to initialize shm - all nonce-count checking, one-time nonces, and MD5-sess algorithm disabled
后经查询尝试发现以下步骤可以解决:
$ rm -rf /run/httpd
$ mkdir /run/httpd
$ chown root:apache /run/httpd
$ chmod 0710 /run/httpd
PS:在Apache启动过程中,由于未正常关闭可能会存在一些锁文件(pid文件),共享内存文件(shm文件)等,会导致这些文件已存在从而无法生成新的系统文件而导致启动后又shut down的问题,经测试,这两类文件删除后,在原目录下根据原文件权限调整后即可生成正确文件从而重新启动服务