macbook pro的无线大坑

这周一直在给macbook pro 重装系统,可恶的天朝网络,时断时续,经常从十几MB的下载速度掉到几十KB, 还有动不动can’t download items..

今天无意间在抽屉里发现当初买macbook时赠送的thunderbolt2转网线的接口,就无意识的插上网线一试发现reload system时,速度竟然能够一直保持在几十MB每秒, 6.05GB的macos Mojave,只需要5分钟就可以下载完毕..

看来再好的无线wifi硬件,在稳定性上还是不如ethernet

Macbook通过恢复功能重新安装macOS

大家都知道在开机的时候,按住Command+R可以重装系统,但是其实这里还有另外两个选项:

Option + Command + R, 也可以通过internet自动重装系统,但是是自动安装最新版本的macOS

Shift + Option +Command + R, 通过internet自动重装买这台macbook时安装的系统,如果这个系统太老并且不再被苹果所支持了,那么会通过internet安装正在支持的最为接近这个旧系统的macOS

防止阿里云备案被撤销

鉴于国内BT的备案的制度,阿里云更为甚之。。。

在阿里云备案的域名,如果没有把IP指向阿里云,也被会阿里云警告

因此最好的办法就是把IP只想阿里云并且模拟一些流量

打开centos 的crontab,可以设置如下crojob,来模拟真实的流量:

0 2 * * * curl -s www.domain1.com > /dev/null 2>&1 >/dev/null 2>&1
0 3 * * * curl -s www.domain2.com > /dev/null 2>&1 >/dev/null 2>&1
0 4 * * * curl -s www.domain3.cn > /dev/null 2>&1 >/dev/null 2>&1
0 5 * * * curl -s www.domain4.cn > /dev/null 2>&1 >/dev/null 2>&1

国内cloud安装军哥LNMP1.6

02-18-2019 Updated: 军哥已经修复了这个问题. 

 

军哥的LNMP准时在1月1号更新了,之前一直在国外的cloud上安装,所以没有遇到任何问题

但是今天在阿里云的深圳机房上安装,确发现了一个小的问题

具体说来就是在LNMP1.6上安装boost的时候,boost 的安装被写入了mysql 的config,mysql 会自动从internet上下boost并且安装配置boost.

问题就出现这里,mysql下载boost,是从sourceforge上下载boost

下载地址:

http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

阿里云连sourceforge速度超慢,时间一长就会被程序自动timeout了, 不得不说这是国内的悲哀。。。

解决这个办法还是比较简单的,就是提前下载号boost1.59到/root/lnmp1.6/src下面,也就是你的lnmp文件夹下面的src里面就可以了

下载地址:

http://soft.vpser.net/lib/boost/

需要注意的是,lnmp1.6需要是tar.bz2的boost

删除阿里云自带的云盾,监控服务等等

其他的系统我不太清楚,但是aliyun的centos模板自带许多阿里云的服务,比如说云盾,cloudwatch等等,而这些往往是我们不愿意透露出去的,因此需要一上来就删掉这些服务,而这些服务往往还像牛皮癣,很难删的完完整整

下面的操作都是在aliyun 深圳机房的一台安装了centos 7的轻量云上操作的

卸载阿里云监控

wget http://update.aegis.aliyun.com/download/uninstall.sh
chmod +x uninstall.sh
sudo ./uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh
chmod +x quartz_uninstall.sh
sudo ./quartz_uninstall.sh

其实quartz的uninstall中已经包含了aegis的卸载命令

删除残留

sudo pkill aliyun-service
sudo rm -rf /etc/init.d/agentwatch /usr/sbin/aliyun-service
sudo rm -rf /usr/sbin/aliyun*
sudo rm -rf /etc/systemd/system/aliyun.service
sudo rm -rf /usr/local/aegis*

 

屏蔽云盾IP

如果用iptables,可用如下命令

iptables -I INPUT -s 140.205.201.0/28 -j DROP
iptables -I INPUT -s 140.205.201.16/29 -j DROP
iptables -I INPUT -s 140.205.201.32/28 -j DROP
iptables -I INPUT -s 140.205.225.192/29 -j DROP
iptables -I INPUT -s 140.205.225.200/30 -j DROP
iptables -I INPUT -s 140.205.225.184/29 -j DROP
iptables -I INPUT -s 140.205.225.183/32 -j DROP
iptables -I INPUT -s 140.205.225.206/32 -j DROP
iptables -I INPUT -s 140.205.225.205/32 -j DROP

如果用防火墙,可以直接屏蔽下面的IP

140.205.201.0/28
140.205.201.16/29
140.205.201.32/28
140.205.225.192/29
140.205.225.200/30
140.205.225.184/29
140.205.225.183/32
140.205.225.206/32
140.205.225.205/32

最后删除云监控cloudwatch 需要注意的是,centos安装的是go版本的云监控

可以参考这个官方页面

http://help.aliyun.com/document_detail/97929.html

也可以直接使用下面的命令:

/usr/local/cloudmonitor/CmsGoAgent.linux-amd64 stop && \
/usr/local/cloudmonitor/CmsGoAgent.linux-amd64 uninstall && \
rm -rf /usr/local/cloudmonitor

如果你的centos安装的是java版本的话,可以使用

/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh stop
/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh remove && \
rm -rf /usr/local/cloudmonitor

Nginx安装Sectigo 的essential SSL

以前一直使用的是rapid SSL,但是rapid SSL 最近爆出了一些问题,因此开始转向我以前不是很喜欢的comodo,也就是现在的sectigo.

安装过程和rapid ssl 大同小异,有些不同的地方在rapid ssl 的intermediate certificate 只有一个文件,而comodo sectigo essential 的 chain files 确有三个, 需要注意的是chain files 根据时间的流逝,可能会有新的chain files产生, 而sectigo 的官方support 更新比较慢,建议自己从email 中合成chain file

chain file 从上到下,应该是SectigoRSADomainValidationSecureServerCA,USERTrustRSAAddTrustCA,AddTrustExternalCARoot

在nginx下,crt 是需要和chain file 合在一起的,因此在最后的crt中,应包含的证书,从上到下是 CRT, SectigoRSADomainValidationSecureServerCA,USERTrustRSAAddTrustCA,AddTrustExternalCARoot

 

 

现代Linux系统的swap空间

以前的资料上的东西,都是以RAM很小为前提,但是现在的server,RAM动不动就是32G,64G什么的,内存要大不少

下面的内容是从fedora 28的安装文档上看到的。Fedora 28安装指南定义了有关swap 空间分配的思路。需要注意的是,fedora的分配思路可能与其他Linux发行版略有不同,但是和REHL,Centos是一摸一样的,这些建议自从Fedora19以来就没有变过

Fedora的建议:

RAM<=2GB, SWAP = 2X RAM

2GB < RAM < 8GB, SWAP = RAM

8GB < RAM < 64GB, 4G<=SWAP<=0.5XRAM

RAM> 64GB, SWAP>=4GB

但是根据多年专业的运维人员的经验来说,

RAM <= 2GB, SWAP = 2X RAM

2GB < RAM < 8GB, SWAP = RAM

SWAP > 8GB, SWAP = 8GB

nginx 带query string argument 的URL 跳转

nginx 自带的三个命令,  return, rewrite, try-files功能非常强大,基本可以完成各式各样的跳转, 比如下面的:

server {

    listen 80;

   server_name example.com;

   return 301 https://www.example.com$uri;

}

这样就完成了一个不带www的domain转向带SSL以及www前缀的domain的跳转

$uri: 按照nginx官方文档的话来说,就是current normalized URI in REQUEST

$request_uri: full original request URI (with arguments)

这里很明显就看到了$uri和$request_uri的区别,$uri 是 normalized的,换句话说,就是

  1. 去除了?以及后面的query参数
  2. encoded URL被 decoded

因此这里就出现了一个问题: exapmle.com/test.php?a=b 会跳转到https://www.example.com/test.php, query string丢失了,解决的办法很简单

return 301 https://www.example.com$uri$is_args$args
或者
return 301 https://www.example.com$request_uri

$is_args is an emprt string if there are no arguments, or a ? to signify the start of the query string.

$args then adds the arguments,

CentOS7安装Smokeping2.7.3

准备把国内的一些服务外迁,这里正好做个网络监控来监控以下,smokeping部署在aliyun Hong Kong B区

首先需要删除ECS Centos7中自带的一些阿里云监控

卸载安骑士以及监控:

wget http://update.aegis.aliyun.com/download/uninstall.sh
chmod +x uninstall.sh
./uninstall.sh

 

wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh
chmod +x quartz_uninstall.sh
./quartz_uninstall.sh

可以使用

ps -aux |grep aliyun

来查看是否还有活动的aliyun 服务进程

删除残留服务:

pkill aliyun-service
rm -rf /etc/init.d/agentwatch
rm -rf /usr/sbin/aliyun*
rm -rf /usr/local/aegis*
rm -rf /etc/systemd/system/aliyun*

检查是否有cloudmonitor

cd /usr/local/cloudmonitor/
ls
/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh stop
/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh remove
rm -rf /usr/local/cloudmonitor

这样才算基本完成删除的aliyun的残留服务

某些文章上还会写有屏蔽云盾的IP,有时间还是得看看log来查看是不是有必要屏蔽云盾的IP

iptables -I INPUT -s 140.205.201.0/28 -j DROP
iptables -I INPUT -s 140.205.201.16/29 -j DROP
iptables -I INPUT -s 140.205.201.32/28 -j DROP
iptables -I INPUT -s 140.205.225.192/29 -j DROP
iptables -I INPUT -s 140.205.225.200/30 -j DROP
iptables -I INPUT -s 140.205.225.184/29 -j DROP
iptables -I INPUT -s 140.205.225.183/32 -j DROP
iptables -I INPUT -s 140.205.225.206/32 -j DROP
iptables -I INPUT -s 140.205.225.205/32 -j DROP
iptables -I INPUT -s 140.205.225.195/32 -j DROP
iptables -I INPUT -s 140.205.225.204/32 -j DROP

这篇文章到了这里才算是完成了服务器的初始清理工作

在安装之前我们需要关闭selinux, firewall, 同步一下时间

yum -y install ntpdate
ntpdate 0.pool.ntp.org
sestatus

或者从www.ntppool.org中选择一个

下面开始进入安装工作 ,其实在作者的官方网站把过程写的清清楚楚:

https://oss.oetiker.ch/smokeping/doc/smokeping_install.en.html
  1. 安装epel package
yum install epel-release -y

    2. 安装development tools

yum groupinstall "Development tools" -y

     3. 安装fping (smokeping 2.7.2以上需要fping4.0以上,因此需要手动编译)

cd ~
wget https://fping.org/dist/fping-4.2.tar.gz
tar -zxvf fping-4.2.tar.gz
cd fping-4.2
./configure
make
make install

安装好的fping位于/usr/local/sbin/fping

      4. 安装echoping (预防以后需要做tcp ping)

cd ~
wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz
tar -zxvf echoping-6.0.2.tar.gz
cd echoping-6.0.2
yum install -y popt-devel openssl openssl-devel
./configure --with-ssl --without-libidn
make
make install

安装好的echoping位于/usr/local/bin/echoping

        5 安装需要的package

cd ~
yum install rrdtool rrdtool-perl curl bind-utils gcc make vim gcc-c++ -y
yum install perl-core -y

5.5 开启SSL支持

yum install perl-LWP-Protocol-https

6. 安装apache, 注意smokeping是fcgi程序,因此apache 需要安装mod_fcgid, http的版本是2.4.6,

yum install httpd httpd-devel
yum install mod_fcgid
systemctl enable httpd

        7. 安装nginx, nginx的版本是1.16

//or reference http://nginx.org/en/linux_packages.html#RHEL-CentOS
yum install nginx -y

systemctl enable nginx

service nginx start

    8 安装smokeping

cd ~

wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.3.tar.gz

tar -zxvf smokeping-2.7.3.tar.gz

cd smokeping-2.7.3

./configure --prefix=/opt/smokeping PERL5LIB=/usr/lib64/perl5/

/usr/bin/gmake install

 

注意,如果我们不加上 ./configure –prefix=/opt/smokeping PERL5LIB=/usr/lib64/perl5/,会提示下面的:

 

** Ready to install Smokeping ******************************

Settings:

PERL5LIB = not set
PERL = /usr/bin/perl

The Smokeping Makefiles use GNU make functionality.
Continue installation with

/usr/bin/gmake install

 

如果我们加上PERL5LIB=/usr/lib64/perl5的话,会显示如下:

** Ready to install Smokeping ******************************

Settings:

PERL5LIB = /usr/lib64/perl5/
PERL = /usr/bin/perl

The Smokeping Makefiles use GNU make functionality.
Continue installation with

/usr/bin/gmake install

9 初始化smokeping, 我们需要建立三个文件夹,data用来存放rrd文件,var用来存放smokeping的pid, log用来存放smokeping.log

cd /opt/smokeping

mkdir data var log

chmod 777 data var log

touch log/smokeping.log

rename config file and set permission

cd /opt/smokeping/etc/

for foo in *.dist; do cp $foo `basename $foo .dist`; done

chmod 600 /opt/smokeping/etc/smokeping_secrets.dist

配置config文件

编辑/opt/smokeping/etc/config, 配置从github上download

重启smokeping或者重载配置:

/opt/smokeping/bin/smokeping --reload
/opt/smokeping/bin/smokeping --restart

10 设置apache

把/opt/smokeping/htdoc下面的文件copy到/var/www/html去

同时在/var/www/html目录下

mkdir cache

chmod 777 cache

把smokeping.fcgi.dist改名为smokeping.fcgi放到cgi-bin下面

11 编辑apache 配置文件

设置Listen 80 为

Listen 8080

设置 /var/www/html

AllowOverride All

设置/var/www/cgi-bin

AllowOverride All

同时配置一下mod_fcgid的参数,否则可能会因为需要监测的hosts的数量太多,引起fcgid错误,比如说如下的错误:

[Mon jan 30 15:31:44.937317 2019] [fcgid:warn] [pid 17946] [client 127.0.0.1:53506] mod_fcgid: HTTP request length 135754 (so far) exceeds MaxRequestLen (131072)

编辑

vi /etc/httpd/conf.d/fcgid.conf

再最下面添加:

FcgidMaxRequestLen 4000000

12 配置nginx

配置文件:

server{
listen 80;
server_name www.xxxxxx.com;
index index.html index.htm index.php default.html default.htm default.php;
access_log off;
error_log /var/log/nginx/www.xxxxxx.com.error.log;
location / {
proxy_pass http://127.0.0.1:8080;
#Proxy Settings
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 128k;
proxy_buffers 6 32k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
client_max_body_size 50m;
}
}

13 进入/var/www/html, 设置.htaccess

RewriteEngine On
RewriteRule ^$ /cgi-bin/smokeping.fcgi [NC,L]

14. 写入smokeping自启动文件

编辑/etc/systemd/system/smokeping.service

[Unit]
Description=Latency Logging and Graphing System
After=syslog.target network.target

[Service]
ExecStart=/opt/smokeping/bin/smokeping
ExecReload=/bin/kill -HUP $MAINPID
StandardError=syslog
Type=forking
PIDFile=/opt/smokeping/var/smokeping.pid


[Install]
WantedBy=multi-user.target


设置完整个以后

别忘了重启daemon

systemctl daemon-reload

下面主要是slave的安装设置:

15) 对于slave来说, 基本过程和上面一样,但是apache 和nginx 是不需要安装的, 也就是跳过步骤6和7

然后如下:

cd ~

wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.3.tar.gz

tar -zxvf smokeping-2.7.3.tar.gz

cd smokeping-2.7.3

./configure --prefix=/opt/smokeping PERL5LIB=/usr/lib64/perl5/

/usr/bin/gmake install

cd /opt/smokeping

mkdir data var cache

chmod 777 data var cache

设置slave的密码文件,路径为/opt/smokeping/etc/secret.txt

vi /opt/smokeping/etc/secret.txt

为了方便后面的教程,假设slave的密码是gcphongkong,我们这里在secret.txt里面只需要写入gcphongkong,其他的都不需要

chmod 600 /opt/smokeping/etc/secret.txt

这里如果不设置600,会被报错

slave 需要提供一个hostname,为了方便,这个name可以不是这个服务器的真实的hostname,可以在启动文件中添加slave name,这里我们设置为gcphk

16) 启动文件也因此需要做一些修改, 编辑/etc/systemd/system/smokeping.service, 重点关注 –slave-name 这个配置

[Unit]
Description=Latency Logging and Graphing System
After=syslog.target network.target

[Service]
ExecStart=/opt/smokeping/bin/smokeping --master-url=http://xxx.xxx.xxx/cgi-bin/smokeping.fcgi --cache-dir=/opt/smokeping/cache/ --slave-name=gcphk --shared-secret=/opt/smokeping/etc/secret.txt --pid-dir=/opt/smokeping/var --logfile=/opt/smokeping/smokeping.log
ExecReload=/bin/kill -HUP $MAINPID
StandardError=syslog
Type=forking
PIDFile=/opt/smokeping/var/smokeping.pid


[Install]
WantedBy=multi-user.target

设置完systemd以后,我们需要重启daemon

systemctl daemon-reload

这样我们就配置完成了slave,配置了slave 先不要启动,必须得先在master上配置完以后再启动slave,这样才能读取配置

17) slave的hostname的解释

slave 的hostname 需要和master 的secret.txt相对应

这里的hostname 可以不是服务器真正的hostname,只要master认为是就可以了,具体设置可以看16,如果不在启动配置上添加”–slave-name”参数,那么就需要服务器真正的hostname与master上的文件相对应

18)

在Master上的设置:

在/opt/smokeping/etc/config 中添加slave 部分:

*** Slaves ***
secrets=/opt/smokeping/etc/smokeping_secrets

+gcphk
display_name = GCP_HK
location = HK
color = ff0000

在底部target这里,加上

*** Targets ***

slaves = gcphk

这个配置简单易懂,然后 smokeping_secrets里面配置secrets,格式是host:secrets

如果按照图上的slave来说,就应该是

gcphk:gcphongkong

同时smokeping_secrets的权限应该设置为600,否则会被slave 报错, 同时apache也要有权限read smokeping_secrets, 因此可以这样

chown apache:apache smokeping_secrets
chown apache:apache config

chmod 600 smokeping_secrets

然后reload smokeping和httpd

systemctl reload smokeping

systemctl reload httpd

然后再slave 启动smokeping

systemctl start smokeping

systemctl enable smokeping

 

FAQ:

  1. Q: Slave端正常,但是不显示slave的数据;新增监控点不显示数据;

这是因为slave 是通过apache或者nginx写入数据到/opt/smokeping/data 的,如果slave的数据不显示,则是apache或者nginx对data 文件夹以及里面的文件没有写入权限,因此可以这样:

chown apache:apche /opt/smokeping/data -R

chown nginx:nginx /opt/smokeping/data -R

在centos下通过编译安装的smokeping,都是以root运行的,因此修改data 下面的文件夹以及文件权限,是没有任何问题的