Nginx Websocket 配置

Nginx 支持websocket,可以用下面的example:

location / { 
       proxy_redirect off;
       proxy_pass http://127.0.0.1:26534; 
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_set_header Host $http_host;
}

26534表示任意端口

Krypt iON Benchmark

从hostloc 坛友那里收的, 20.19刀那一款,双向CN2 GIA,还是很不错的,做一个benchmark记录一下.

使用的程序:

wget -qO- bench.sh | bash

下面是结果:

----------------------------------------------------------------------
CPU model : Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz
Number of cores : 1
CPU frequency : 2499.996 MHz
Total size of Disk : 39.0 GB (4.7 GB Used)
Total amount of Mem : 1837 MB (365 MB Used)
Total amount of Swap : 1023 MB (1 MB Used)
System uptime : 43 days, 20 hour 23 min
Load average : 0.30, 0.08, 0.07
OS : CentOS 7.7.1908
Arch : x86_64 (64 Bit)
Kernel : 3.10.0-1062.9.1.el7.x86_64
----------------------------------------------------------------------
I/O speed(1st run) : 632 MB/s
I/O speed(2nd run) : 669 MB/s
I/O speed(3rd run) : 553 MB/s
Average I/O speed : 618.0 MB/s
----------------------------------------------------------------------
Node Name IPv4 address Download Speed
CacheFly 205.234.175.175 66.1MB/s
Linode, Tokyo2, JP 139.162.65.37 21.6MB/s
Linode, Singapore, SG 139.162.23.4 13.3MB/s
Linode, London, UK 176.58.107.39 16.9MB/s
Linode, Frankfurt, DE 139.162.130.8 15.8MB/s
Linode, Fremont, CA 50.116.14.9 90.9MB/s
Softlayer, Dallas, TX 173.192.68.18 61.6MB/s
Softlayer, Seattle, WA 67.228.112.250 60.3MB/s
Softlayer, Frankfurt, DE 159.122.69.4 11.3MB/s
Softlayer, Singapore, SG 119.81.28.170 10.1MB/s
Softlayer, HongKong, CN 119.81.130.170 12.3MB/s
----------------------------------------------------------------------

 

阿里云ECS的坑 – 系统硬件时间

用了这么久 的阿里云ecs,也是今天无意间才发现的,更准确的说应该是centos 7的坑,在centos 6上那样直接修改时区的办法不行了

1)拿到了阿里云的ecs,第一件事就是应该修改系统的hwclock,这是因为阿里云的ecs默认使用的是hwclock 是cst,也就是中国时区。这个可以是可以,但是国际上通用的办法是使用UTC时间,这更能避免很多问题:

timedatectl set-local-rtc 0

2) 第二个坑就是因为有了第一个问题以后,在centos 6上我经常使用下面的办法修改时区(个人习惯,所有的服务器都是UTC或者EST时区):

cp /usr/share/zoneinfo/America/New_York /etc/localtime

在centos 7上我也继续这么使用,在国外的服务器上没有一点问题,但是在阿里云ecs上就会出现下面的情况:

[root@sz ~]# timedatectl
Local time: Wed 2020-01-29 07:57:08 EST
Universal time: Wed 2020-01-29 12:57:08 UTC
RTC time: Wed 2020-01-29 20:57:07
Time zone: Asia/Shanghai (EST, -0500)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
DST active: no
Last DST change: DST ended at
Sun 2019-11-03 01:59:59 EDT
Sun 2019-11-03 01:00:00 EST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2020-03-08 01:59:59 EST
Sun 2020-03-08 03:00:00 EDT

Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.

重点是timezone 那一行, Asia/Shanghai 变成了EST了,明显不对, 我们需要用下面的命令修改一下:

timedatectl set-timezone "America/New_York"

重启以后,系统的各种时间才会恢复正常.

为什么要这么做?因为如果你不这么做,系统的时间和mysql 的时间会发生冲突,当你需要重启mysql服务的时候,就会出现:

InnoDB: Waiting for page_cleaner to finish flushing of buffer pool

让你需要最起码5分钟以上才能完全重启mysql服务或者重启服务器。。。

下午遇到了问题,一台新装的ecs服务器需要最少5分钟才能重启。。。刚开始以为是smokeping 重启过慢,仔细debug了开机启动,发现是关机速度太慢。。。然后看log 发现是mysql shutdown 时间太长,InnoDB需要清空buffer。。。再继续debug才发现这是系统时间的问题。。。

浪费了整整一下午。。。

Ubuntu Server安装图形桌面并且开启远程RDP访问

近期有项目需要使用图形桌面来完成,windows server肯定是最好的选择,但是昂贵的授权费用以及不低的硬件配置,让我想到了Ubuntu. Linux 系主要使用centos,debian系虽然也在用,但是确实不熟悉,因此debug确实耗费了不少时间.

主要步骤:

  1. 安装ubuntu 18.04 x64,这个没有什么,直接在你的云服务商上选择就可以了
  2. 安装updates
      apt update
      apt upgrade

3. 安装图形桌面

       apt install ubuntu-desktop

这里不建议使用tasksel来安装,过于复杂,安装时间太长,而且安装了很多没有必要的东西,对于配置低的cloud来说浪费资源,而且tasksel默认安装了很多和xrdp冲突的组件, 我对ubuntu不熟悉,实在没有办法修改

4. 安装xrdp

需要注意的是,ubuntu repo里面的xrdp 的版本有问题,参见这里:

http://c-nergy.be/blog/?p=13390

所以正确步骤是:

apt install xserver-xorg-core
apt install xserver-xorg-input-all
apt install xorgxrdp
apt install xrdp

5. 创建用户远程登录, 这点是和centos不一样的地方,centos 的root 可以干很多事情,debian系的root虽然权限最大,但是很多功能都被锁定了,debian 系推荐的办法是创建一个新的用户,在需要root权限的时候,用sudo提权。假如我们要创建的用户名是ccc,那么步骤是:

adduser ccc(中间会提示你设置密码)
usermod -aG sudo ccc (将ccc加入sudo group, 这样ccc就可以用sudo提权)

 

然后我们就可以用windows的RDP远程登录这台ubuntu服务器了

默认的情况下,这个GUI只有最基本的程序,大部分经常使用的app需要安装,最好是通过command line来安装,比如说安装firefox

apt install firefox

 

 

 

国行三星S8+ 打开wifi calling

刚把我的美国电话号码port到google fi了,本来把fi 的sim 卡插到了iPhone 上,但是没有想到Google Fi 不支持在iPhone上使用wifi calling。

对Google Fi 的wifi calling 支持最好的是他们自家卖的手机, designed for google fi系列,基本都是pixel,水果机支持google fi,但是不支持wifi calling. 三星的机器支持google fi, 也支持wifi calling,想起来了我还有个国行三星s8 plus,但是按照国内手机的尿性,不知道会不会阉割wifi calling。

今天早上和google fi 的客服聊了一个小时,确认国行三星s8 plus, model number 是SM-G9550, 支持google fi 的wifi calling,但是一般来说国行会缺少某些组件. 几个关键点:

  1. 你的登录google fi 的google play账号必须是美国,任何其他国家的都不行,就是这个原因,debug了整整一个早上
  2. Google Fi 的wifi calling 只支持安卓,在安卓手机上必须安装Google Fi应用,并且在里面打开wifi calling. Wifi Calling 在”Phone Setting”里面.
  3. 你的手机里必须安装有google fi,carrier service, google play services, google connectivity services,hangouts, 并且全部权限都打开, “Background data” 和”Unrestricted data usage” 也必须打开. 国行的手机可能没有carrier service,必须得从google play上下载,如果这样的话,google connectivity services就不需要安装了
  4. 安卓手机必须打开wifi calling选项,路径为”Open the Phone app > tap More (three dots icon) > Settings > Calls > Wi-Fi calling”

Linux 的 stdin, stdout 以及stderr

今天终于有时间来仔细看下stdin,stdout和stderr了

标准输入重定向(STDIN,文件描述符为 0):默认从键盘输入,也可从其他文件或命令中输入。
标准输出重定向(STDOUT,文件描述符为 1):默认输出到屏幕。
错误输出重定向(STDERR,文件描述符为 2):默认输出到屏幕。

“stdout”按理来说应该表示为”1>”, 我们可以默认的写成”>”, 重定向stderr可以用”2>”来表示

./error.sh 2> capture.txt

表示把错误信息重定向到capture.txt

./error.sh 1> capture.txt 2> error.txt

表示把标准输出定向到capture.txt, 把错误定向到error.txt

./error.sh > capture.txt 2&>1

capture.txt 表示标准输出重定向到capture.txt,  2>&1, 表示“redirect stream 2, stderr, to the same destination that stream 1, stdout, is being redirected to”

总结一下:

输入重定向:
命令 < 文件 将文件作为命令的标准输入
命令 << 分隔符 从标准输入中读入,直到遇见分隔符才停止
命令 < A1 > A2 将文件A1作为命令的标准输入并将标准输出到文件A2

 

命令 > 文件 将标准输出重定向到一个文件中(清空原有文件的数据)
命令 2> 文件 将错误输出重定向到一个文件中(清空原有文件的数据)
命令 >> 文件 将标准输出重定向到一个文件中(追加到原有内容的后面)
命令 2>> 文件 将错误输出重定向到一个文件中(追加到原有内容的后面)
命令 >> 文件 2>&1 或 命令 &>> 文件 将标准输出与错误输出共同写入到文件中(追加到原有内容的后面)

askubuntu.com上面有个老外写了一个解释,非常的好记:

List:
command > output.txt
The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.

command >> output.txt
The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

command 2> output.txt
The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.

command 2>> output.txt
The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

command &> output.txt
Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, it gets overwritten.

command &>> output.txt
Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, the new data will get appended to the end of the file..

command | tee output.txt
The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, it gets overwritten.

command | tee -a output.txt
The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

(*)
Bash has no shorthand syntax that allows piping only StdErr to a second command, which would be needed here in combination with tee again to complete the table. If you really need something like that, please look at "How to pipe stderr, and not stdout?" on Stack Overflow for some ways how this can be done e.g. by swapping streams or using process substitution.

command |& tee output.txt
Both the standard output and standard error streams will be copied to the file while still being visible in the terminal. If the file already exists, it gets overwritten.

command |& tee -a output.txt
Both the standard output and standard error streams will be copied to the file while still being visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

DiscuzX 固定顶部格子广告的列数

DiscuzX的顶部的格式广告的列数,是再3,4,5之间自动变化的.

具体的代码位于:

source/class/adv/adv_text.php, 从97行开始:

 
$advcount = count($adids);
if($advcount > 5) {
		$minfillpercent = 0;
		for($cols = 5; $cols >= 5; $cols--) {
			if(($remainder = $advcount % $cols) == 0) {
				$advcols = $cols;
			break;
		} elseif($remainder / $cols > $minfillpercent)  {
			$minfillpercent = $remainder / $cols;
			$advcols = $cols;
		}
	}
} else {
	$advcols = $advcount;
	}
因此我们可以看到格子广告的列数再3,4,5之间动态变化,如果要固定列数,只需要把for循环的两个5改成4或者3就可以了

ERROR 2006 (HY000): MySQL server has gone away

当你要导入一个比较大的mysql数据库的时候,可能会产生这个错误:

mysql> source file.sql
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 2
Current database: *** NONE ***

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 3
Current database: *** NONE ***

这是因为max_allowed_packet设置的太小了,再/etc/my.cnf中,将这个参数设置为64M或者根据实际情况设为更大的值就可以了

max_allowed_packet=64M

mysql文档:

https://dev.mysql.com/doc/refman/5.5/en/replication-features-max-allowed-packet.html