Study hard and make progress every day!

2021-01-15
MacOS下复制快捷键失效问题

不知道从哪个版本的OSX系统开始,复制快捷键Command + C就开始不怎么灵,有时候按一下复制不成功,需要多按几下才有效。
之前网上查找没找到什么可靠的说法。就一直以为是系统的Bug。
这么多年已经习惯每次复制时,按两下Command + C了。

直到今天无意间看到公众号上的一个评论,说可能是第三方词典app的划词功能导致的。
试了一下,关闭了电脑上欧路词典的划词搜索后,瞬间豁然开朗, Command + C如丝般柔顺,再也没出现过拷贝不生效的情况了。

不禁再次反思自己,懊恼自己这么多年的妥协,16年知乎上就有帖子Mac OS复制粘贴功能经常失效,问题出在哪里?有何解决办法?回答过这个问题了,而我却一直忍受了这个问题到2021年。

相同的一例反思, 也是词典APP导致的不兼容: Mac下Word不能双击格式刷重复刷的问题

阅读此文

2020-11-11
如何让Nginx支持带点的header

起因

公司有个比较久远的遗留APP项目,服务端用的是之前公司自己写的一个HTTP的服务器。最近这个项目被要求升级使用https。
但自研的HTTP服务器自身不支持https, 老代码了也已经没人没精力去再开发了。
一合计,就决定在前面架一个Nginx来做反向代理,用来终止SSL再转发请求给自写的HTTP服务器。

问题

咵咵咵,三下五除二,申请了https证书,配置了nginx,项目就跑起来了。
可测试阶段,发现有个别请求会失败。一检查,发现是服务端接收到的请求中,有一个Header的值没有获取到。

结果过程

挠了挠头皮,调查了下。发现这个自定义的header比较奇怪,名字中带有., 类似user.token
上网一通找,找到几个文章

大意就是虽然RFC中没有规定带.的header是非法的,但Nginx默认就是不支持带.的header的。如果需要支持,可以考虑使用ignore_invalid_headers来实现。
尝试着修改了nginx配置,添加了ignore_invalid_headers off;后, 解决了该问题。

云厂商负载均衡服务的行为

Cloudflare

Cloudflare会丢弃带.的header

Cloudflare strips any header that contains dots (.) from origin web server responses. For example, the origin web server header test.header:data is removed by Cloudflare’s proxy.
来自: How does Cloudflare handle HTTP Request headers?

AWS

待调查,参考资料

Reference

阅读此文

2020-11-07
在CentOS 7中使用kubeadm搭建kubernetes集群

在CentOS 7上使用kubeadm安装kubernetes cluster的方法。

安装公共组件

1
sudo yum install -y wget net-tools vim

安装Docker

CentOS 7中安装docker参见之前文章Docker基础

安装Kubernetes

添加kubenetes的yum源

在Master和Node中同时添加阿里云的yum源。

1
2
3
4
5
6
7
8
9
sudo cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

阅读此文

2020-10-24
AWS RDS PostgreSQL版本升级

起因

海外AWS中有一套系统采用的是PostgreSQL 9.5, 因为PG 9.5在2021年2月11号之后不再被PG社区所支持了, PG社区对版本的支持参见Versioning Policy。因此AWS发送了邮件,提示我们尽快升级到9.6。并且介于PG 9.6在2020年11月11号之后也会停止支持,AWS建议直接升级到PostgreSQL 12或以上版本。

基于直接从9.5升级到12,中间跨越版本太大,可能会有问题。因此决定先暂时升级到9.6。等后续完整测试12后,再升级到12。

升级步骤

AWS升级,可以在Web Console中点击几个按钮就可以升级。但升级时,Event提示升级失败,PreUpgrade checks Fails。报错如下:

1
2
3
4
5
The instance could not be upgraded from 9.5.22.R1 to 9.6.19.R1 because of following reasons. Please take appropriate action on databases that have usages incompatible with requested major engine version upgrade and try again.
Following usages in database 'xxxxx' need to be corrected before upgrade:
-- The instance could not be upgraded because there are one or more databases with an older version of PostGIS extension or its dependent extensions (address_standardizer, address_standardizer_data_us, postgis_tiger_geocoder, postgis_topology) installed. Please upgrade all installations of PostGIS and drop its dependent extensions and try again.
Following usages in database 'nest_demo' need to be corrected before upgrade:

提示升级检查失败,原因是PostGIS的版本存在问题。

阅读此文

2020-10-22
wkhtmltopdf支持中文字体

问题

CentOS 7.8环境中,要使用wkhtmltopdf来从网页中生成PDF。
没有使用rpm包来安装wkhtmltopdf命令,而是使用了gem 'wkhtmltopdf-binary'在Rails项目下安装了wkhtmltopdf

运行后发现,网页中的中文在PDF中没法显示。

解决办法

调查后发现是因为系统中缺少中文字体的支持,使用如下命令安装字体后,可以解决。两者选其一。

1
2
3
sudo yum install -y wqy-microhei-fonts
# 或者
sudo yum install -y xorg-x11-fonts-75dpi
阅读此文

2020-10-14
MacOS下使用iTunes删除iphone备份磁盘空间没回收

记一次有趣的经历。

事情经过

为了能用Watch 6,升级了手机系统到IOS 14。升级之前在电脑上用itunes备份了下(没错,是itunes,我mac系统还在用10.14,所以还是itunes,不是Finder),占了几十个G的空间,电脑上磁盘空间一下子紧张了。手机升级完毕后,看了下没啥问题,就准备把电脑上的iphone备份给删了。

以前删备份都是打开Terminal, 进入~/Library/Application\ Support/MobileSync/Backup/后手动rm -r xxx的。可这次不知道为啥,鬼使神差的用了itunes自带的删除备份的功能。就是下面这个界面。

device_backup_on_itunes.jpg

一通操作,在界面上把备份删除了。

然后信心满满地敲下了df -h来查看回收了多少磁盘空间。

命令一敲,啥情况。怎么空间没有被回收?

猜想,可能是itune的Bug,文件没有被删除吧。算了算了,还是手动删一下吧。打开Terminal,潇洒的敲击cd ~/Library/Application\ Support/MobileSync/Backup/,熟练的敲击du -sh ./*来查看是哪个目录没有被回收。

一敲下去,发现不对劲,怎么显示Backup占用的磁盘空间是0B?

1
2
3
$ du -sh ./*
0B ./00008020-000464E03BD8002E
$
阅读此文

2020-08-04
AWS LightSail Tips

如何跨区域迁移LightSail

步骤:

  1. 现在源区域中对LightSail Instance做snapshot
  2. 然后对该snapshot进行”Copy to another Region”的操作,选择目标Region进行拷贝
  3. 在目标Region中选择拷贝来的snapshot,选择”Create new instance”

官网介绍操作的两篇文章, 清晰易懂。

LightSail

和EC2 Instance不同,LightSail在stopped状态时也是会收费的。参照官方fAQ

Q: When am I getting charged for a plan?

Your Lightsail instances are charged only when they’re in the running or stopped state. If you delete your Lightsail instance before the end of the month, we only charge you a prorated cost, based on the total number of hours that you used your Lightsail instance. For example, if you use the least expensive Lightsail plan for 100 hours in a month, you will be charged 47 cents (100*0.0047).

Understanding Lightsail Pricing这个文章还介绍了LightSail的计费方式。

阅读此文

2020-08-01
Nginx RTMP服务器配置

前言

本篇是CentOS 7中搭建基础的Nginx RMPT服务器的续篇,记录了Nignx RTMP使用过程中的一些有用的配置和一些坑。
下面的内容,是以文章CentOS 7中搭建基础的Nginx RMPT服务器中的配置为基准进行的修改。

配置stat

nginx-rtmp-module自身提供了统计的功能。按照Github上官方例子进行配置就行。https://github.com/arut/nginx-rtmp-module
首先,拷贝nginx-rtmp-module源码中的stat.xls到nginx默认主目录/usr/local/nginx/html/中。
再配置rtmp的stat, 在默认server中添加如下配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
# Use this stylesheet to view XML as web page
# in browser
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root html;
}

阅读此文

2020-07-29
CentOS 7中搭建基础的Nginx RMPT服务器

介绍下如何在本地CentOS 7中使用nginx-rtmp-module来搭建基本的RTMP和HLS直播服务器。
基于如下情况进行搭建:

  • 系统版本: CentOS 7.6 Minimal
  • 虚拟机IP地址: 192.168.168.199
  • Nginx版本:1.14.2
  • Nginx Rtmp模块: nginx-rtmp-module
  • 如下安装步骤,如果没有特别说明,都是基于root用户进行安装。

安装nginx

首先更新CentOS系统

1
yum update

安装编译nginx所需的开发包

1
2
3
4
yum install gcc
yum install pcre pcre-devel pcre-static pcre-tools
yum install openssl openssl-static openssl-devel
yum install wget unzip

阅读此文

2020-07-03
Redis基础

Redis基础知识

Redis CentOS7下安装

Redis的安装,有epel和remi两个yum源可选。当然也可以选择从源码安装。
如下介绍epel和remi的两种安装方式。

EPEL安装

CentOS 7中EPEL中redis最新的版本是3.2.12-2

安装命令如下:

1
2
3
4
5
sudo yum install epel-release yum-utils
sudo yum install redis
sudo systemctl start redis
sudo systemctl enable redis
sudo systemctl status redis

阅读此文