logrotate只读文件系统问题
logrotate手动以root执行成功,但是自动运行失败。
logrotate手动以root执行成功,但是自动运行失败。
lxd reset/reinit with snap
first delete all container instances and all images
then execute:
1 | sudo snap remove --purge lxd |
then
1 | sudo snap install lxd --channel=4.0/stable |
last
1 | lxd init |
在笔记本上搭建好了hexo github pages博客,同时有用其他设备更新博客的需求,记录配置过程
越来越没有心思来管理一个独立的wordpress博客,linode慢出翔来好久了,还是把blog迁移到github pages吧,迁移过程做个简单的记录。
安装acme.sh
1 | $ curl https://get.acme.sh sh |
会自动添加cron任务
创建api token
acme.sh支持name.com,访问https://www.name.com/account/settings/api,随意设置token昵称acme_sh_dns,生成token
编辑~/.acme.sh/account.conf添加如下两行:
1 | export Namecom_Username="your_name_com_username" |
Namecom_Username指定你在name.com的用户名而不是token name
申请证书
1 | $ acme.sh --issue --dns dns_namecom -d g.openwares.net |
可以会有提示
1 | g.openwares.net:Verify error:DNS problem: SERVFAIL looking up CAA for openwares.net - the domain's nameservers may be malfunctioning |
忽略即可
安装证书
1 | $ acme.sh --install-cert -d g.openwares.net \\ |
自动更新
acme.sh自动安装了crontab入口,acme.sh会自动记录下申请证书和安装证书的命令,所以会在设定的周期内自动更新证书。
使用alacarte删除了几个菜单项后,再也打不开gnome main menu了,终端下运行alacarte出现错误:
1 | $ alacarte |
发现~/.config/menus目录下多了一个空白文件gnome-applications.menu,将其删除问题解决。
一、判断主备角色
有几个方法可以判断:
1、查看wal进程
1 | $ ps aux grep wal |
如果进程名有”postgres: 11/main: walwriter”字样,则为主库,walwriter为wal发送方。
如果进程名有”postgres: 11/main: walreceiver streaming 2A/ACAA1088”字样,则为备库,walreceiver为wal接收方。
2、pg_is_in_recovery函数
1 | $ sudo -u postgres psql |
显示f说明是主库,显示t说明为备库。
3、查看数据库控制信息
1 | $ sudo -u postgres /usr/lib/postgresql/11/bin/pg_controldata -D /var/lib/postgresql/11/main/ |
Database cluster state这行为in production说明位主库,为in archive recovery说明为备库。
4、通过recovery.conf 文件判断
一般的,备库才有recovery.conf,主库一般没有或是改名为recovery.done
二、主备切换
1、使用trigger文件切换
a. 在备库启动时在 recovery.conf 文件中加入一个触发文件的路径(新加则需要重启备库)
1 | trigger_file='/var/lib/postgresql/11/main/.postgresql.trigger' |
b. 关闭主库:
1 | $ sudo systemctl stop postgresql@11-main.service |
或者
先查看postgresql集群信息
1 | $ pg_lsclusters |
然后执行:
1 | $ sudo pg_ctlcluster 11 main stop |
c.在备库上创建trigger文件
1 | $ sudo touch /var/lib/postgresql/11/main/.postgresql.trigger |
可以看到备库上的recovery文件已经成为done了,此时备库已经被激活为主库,可以直接做读写操作了
在新主库上创建复制槽
d. 原主库搭建为新备库
准备recovery.conf文件,primary_conninfo指向新主库,使用合适的复制槽,然后重新启动数据库即可。
1 | recovery_target_timeline='latest' |
这里必须添加recovery_target_timeline=’latest’,因为主备切换时timeline更新了。
注意pg_hba_conf中对replication的权限设定
2、使用pg_ctlcluster命令切换
a. 停止应用程序,关闭主库
b. 备库提升为主库
备库端执行:
1 | $ sudo pg_ctlcluster 11 main promote |
c. 老主库上配置recovery.conf文件,启动原主库为新的备库
References:
[1]26.3. Failover
[2]PostgreSQL 流复制的主备切换
[3]PostgreSQL Switchover vs. Failover
[4]PostgreSQL主备切换
NFS通常情况下会使用动态端口,对于防火墙配置很不友好。
可以设置使用固定的几个端口。
修改以下配置文件:
/etc/default/nfs-common:
1 | STATDOPTS="--port 3000 --outgoing-port 3001" |
/etc/default/nfs-kernel-server:
1 | RPCMOUNTDOPTS="--manage-gids --port 3002" |
新添加配置文件:
/etc/sysctl.d/nfs-static-ports.conf:
1 | fs.nfs.nlm_tcpport = 3003 |
然后:
1 | $ sudo sysctl -p /etc/sysctl.d/nfs-static-ports.conf |
然后打通防火墙的TCP和UDP端口:111,2049,3000-3003就可以了。
如果出现错误:
1 | mount.nfs: access denied by server while mounting ... |
可以检查/etc/exports设置的访问网段是否正确,如果通过防火墙NAT方式访问,端口号会大约1024,需要添加insecure访问选项,比如(insecure,rw)
修改/etc/exports后,可以使用
1 | $ sudo exportfs -a |
重新导出文件系统
References:
[1]SecuringNFS
[2]Setting Up iptables for NFS on Ubuntu
References:
[1]Java Networking and Proxies