CentOS7中升级gcc

先情提要

Centos 7 默认 gcc 版本为 4.8,根本满足不了实际需求,使用 yum 也只会更新到维护期 15 年版本

实施过程

1、安装 centos-release-scl

sudo yum install centos-release-scl-rh

2、安装 devtoolset,注意,如果想安装 7.版本的,就改成 devtoolset-7-gcc,以此类推,这里安装 Version 9

sudo yum install devtoolset-9*

3、激活对应的 devtoolset

scl enable devtoolset-9 bash

4、注册 devtoolset

进入/opt/rh 目录,source ./devtoolset-9/enable

记得注册成开机启动(/etc/rc.d/rc.local)

source /opt/rh/devtoolset-9/enable

5、替换旧版 gcc

1
2
3
4
5
6
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-9/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-9/root/bin/g++ /usr/bin/g++
gcc --version
g++ --version

6、二次确认安装是否就绪

查看当前 gcc

which gcc

/opt/rh/devtoolset-9/root/usr/bin/gcc

在 yum 查看 gcc 资讯

yum info devtoolset-9-gcc-c++

Installed Packages

Name : devtoolset-9-gcc-c++

Arch : x86_64

Version : 9.3.1

Release : 2.2.el7

Size : 31 M

Repo : installed

From repo : centos-sclo-rh

Summary : C++ support for GCC version 9

URL : http://gcc.gnu.org

License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD

Description : This package adds C++ support to the GNU Compiler Collection

        : version 9.  It includes support for most of the current C++ specification

        : and a lot of support for the upcoming C++ specification.

查看 gcc 版本

gcc -v

Thread model: posix

gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)

若无误,则升级成功。

倘若服务器被入侵了,要检查哪些地方?

其实可以一句话概括:

检查可疑网络链接,可疑进程,可疑文件,可疑脚本任务

整体来说建议重装,重装可以解决 99%问题。

1.查看异常进程活动-查找是否有异常进程和端口占用

1.1 查找占用 cpu 最多的进程

运行 top 命令后,键入大写字母 P 按 cpu 排序

1.2 查找占用内存最多的进程

运行 top 命令后,键入大写字母 M

ps aux | sort -k4nr

1.3 查找进程对应的文件

ls -la /proc/$pid/exe

ls -la /proc/$pid

1.4 跟踪异常进程运行情况

strace -tt -T -e trace=all -p $pid

1.5 查看进程打开的文件

lsof -p $pid

1.6 查看进程端口情况

查看所有端口

netstat -anltp

查看指定进程的端口

netstat -anltp | grep $pid

netstat -apn|more

1.7 清除恶意进程

清除可疑进程的进程链: ps -elf | grep [pid] kill -9 [pid]

2.查看账号安全

2.1 查看是否有存在新增异常账号

查找特权用户

awk -F ":" '$3==0{print $1}' /etc/passwd

查找可以远程登录的账号信息

awk '/\$1|\$6/{print $1}' /etc/shadow

查找 sudo 权限账户

cat /etc/sudoers | grep -v "^#\|^$" | grep "ALL=(ALL)"

2.2 查看是否有账号异常登录情况

查看当前登录用户和其行为

w

查看所有用户最后一次登录的时间

lastlog

查看错误登陆信息

lasstb

查看所有用户的登录注销信息及系统的启动、重启及关机事件

last

查看登录成功的日期、用户名及 ip

grep "Accepted " /var/log/secure* | awk '{print $1,$2,$3,$9,$11}'

查看试图爆破主机的 ip

grep refused /var/log/secure* | awk {'print $9'} | sort | uniq -c |sort -nr | more

grep "Failed password" /var/log/secure* | grep -E -o "(([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}))" | uniq -c

查看有哪些 ip 在爆破主机的 root 账号
grep "Failed password for root" /var/log/secure | awk '{print $11}' | sort

查看爆破使用的用户名字典
grep "Failed password" /var/log/secure | awk {'print $9'} | sort | uniq -c | sort -nr

3.检查开机启动项

一般通过crontab -l命令即可检测到定时任务后门。不同的 linux 发行版可能查看开机启动项的文件不大相同,Debian 系 linux 系统一般是通过查看/etc/init.d目录有无最近修改和异常的开机启动项。而 Redhat 系的 linux 系统一般是查看/etc/rc.d/init.d或者/etc/systemd/system等目录。

依次排查:

1
2
3
4
5
6
7
8
9
/var/spool/cron/*
/etc/crontab
/etc/cron.d/*
/etc/cron.daily/*
/etc/cron.hourly/*
/etc/cron.monthly/*
/etc/cron.weekly/
/etc/anacrontab
/var/spool/anacron/*

其后键入

cat /etc/rc.local

cat /etc/init.d/rc.local

chkconfig --list

ls -alt /etc/init.d

查看 anacron 异步定时任务 cat/etc/anacrontab

枚举主机所有服务 service--status-all

4.查找异常文件

4.1 查看最近一段时间内被修改的系统文件

查找find /etc/ /usr/bin/ /usr/sbin/ /bin/ /usr/local/bin/ -type f -mtime -T | xargs ls -la

4.2 按时间排序,确认最近是否有命令被替换,可以结合 rpm -Va 命令

ls -alt /usr/bin /usr/sbin /bin /usr/local/bin

rpm -Va>rpm.log

4.3 查看指定目录下文件时间的排序

ls -alt | head -n 10

4.4 使用 find 指令查找限定时间范围的文件

sudo find ./ -cmin -10 -name "*.php"

5.排查恶意 alias

检查 ~/.bashrc和~/.bash_profile

6.排查恶意 ssh 公钥

/etc/.ssh/AuthorizedKeys

~/.ssh/AuthorizedKeys

7.系统文件被替换的情况下使用busybox

被替换的系统文件通常为 ld.so.preload

busybox ps -ef|grep watchdogs

busybox ps -ef|grep ksoftirqds

8.借助工具查杀病毒和 rootkit

8.1 查杀 rootkit

chkrootkit

(下载地址:http://www.chkrootkit.org)
rkhunter

(下载地址:http://rkhunter.sourceforge.net)

8.2 查杀病毒

clamav

(下载地址:http://www.clamav.net/download.html)

8.3 查杀 webshell

cloudwalker

(下载地址:http://github.com/chaitin/cloudwalker)

9. 添加命令审计

为历史的命令增加登录的 IP 地址、执行命令时间等信息

9.1 保存 1 万条命令:

sed -i 's/^HISTSIZE=1000/HISTSIZE=10000/g' /etc/profile

9.2 在/etc/profile 的文件尾部添加如下行数配置信息

1
2
3
4
5
6
7
8
9
USER_IP=`who -u am i 2>/dev/null | awk '{print $NF}' | sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi

export HISTTIMEFORMAT="%F %T $USER_IP `whoami` "
shopt -s histappend
export PROMPT_COMMAND="history -a"

写在最后

RootKit Hunter 後端偵測軟體之架設與執行

emergency-response-checklist

关于移动端压测工具

一、APP 自动化测试工具

Appium

官网:http://appium.io/

Github 地址:https://github.com/appium/appium

介绍:

Appium 是一个开源的、跨平台的自动化测试工具。支持自动化 iOS,Android 和 Windows 桌面平台上的原生、移动 Web 和混合应用。 开发者可以使用 WebDriver 兼容的任何语言编写测试脚本,如 Java,OC,JS,PHP,Python,Ruby,C#,Clojure 和 Perl 语言。是做 UI 自动化测试必须要掌握的工具之一。

Airtest

官网:http://airtest.netease.com/
介绍:
Airtest 是网易游戏推出的一个 UI 自动化测试工具,适用于游戏和应用,支持的平台为 Windows,Android 和 iOS。Airtest 提供了跨平台的 API,包括安装应用、模拟输入、断言等。 基于图像识别技术定位 UI 元素,你无需嵌入任何代码即可进行自动化测试。 并且测试脚本运行后可以自动生成详细的 HTML 测试报告。

uiautomator2 (python)

Github 地址:https://github.com/openatx/uiautomator2
介绍:

uiautomator2 是一个可以使用 Python 对 Android 设备进行 UI 自动化的库。其底层基于 Google uiautomator,Google 提供的 uiautomator 库可以获取屏幕上任意一个 APP 的任意一个控件属性,并对其进行任意操作。

二、APP 稳定性测试工具

Monkey

地址:https://developer.android.google.cn/studio/test/monkey

介绍:

Monkey 是一个在模拟器或设备上运行的程序,可生成伪随机用户事件(例如点击、轻触或手势)流以及很多系统级事件。使用 Monkey 以随机且可重复的方式对正在开发的应用进行压力测试。

MonkeyRunner

地址:https://developer.android.google.cn/studio/test/monkeyrunner

介绍:

monkeyrunner 工具提供了一个 API,用于编写可从 Android 代码外部控制 Android 设备或模拟器的程序。使用 monkeyrunner,可以编写一个 Python 程序去安装 Android 应用或测试软件包,运行它,向其发送按键,截取其界面的屏幕截图,并将屏幕截图存储到工作站中。monkeyrunner 工具主要用于在功能/框架级测试应用和设备以及运行单元测试套件,但也可以自由地将其用于其他目的。

Maxim

Github 地址:https://github.com/zhangzhao4444/Maxim

介绍:

Maxim 是基于 monkey 做的二次开发,相较原生 monkey,相对智能。除了保留原生 monkey 已有的功能外,可深度遍历控件,可自定义黑白名单,可设定执行时长,增加防睡眠/防假死机制、防跳出/防误点状态栏及下拉状态栏等。

UICrawler

Github 地址:https://github.com/lgxqf/UICrawler

介绍:
基于 Appium 的 App UI 遍历 & Monkey 工具,支持 Android 和 Ios 移动 App,或 H5 或微信等应用。v2.3 版已支持 Appium 1.16.0, Java-client 7.3.0。

三、APP 性能测试工具

GT

官网:https://gt.qq.com/

介绍:

腾讯开源的 APP 的随身调测平台,支持 ios 和 android。直接运行在手机上,可对 APP 进行快速的性能测试(CPU、内存、流量、电量、帧率/流畅度等等)、开发日志的查看、Crash 日志查看、网络数据包的抓取、APP 内部参数的调试、真机代码耗时统计等。

Perfdog

官网:https://perfdog.qq.com/

介绍:

腾讯游戏部门开发的移动全平台 iOS/Android 性能测试、分析工具平台。手机无需 ROOT/越狱,手机硬件、游戏及应用 APP 也无需做任何修改,极简化即插即用。

PerfDog 支持 iOS 和 Android,支持移动平台所有应用程序(游戏、APP 应用、浏览器、小程序、小游戏、H5、后台系统进程等)、Android 模拟器、云真机等性能测试。PC 上 PerfDog 可多开,单 PC 可同时测试多台手机。目前免费体验,谁用谁香。

SoloPi

Github 地址:https://github.com/alipay/SoloPi

介绍:
SoloPi 是一个无线化、非侵入式的 Android 自动化工具。除了公测版的录制回放、性能测试、一机多控三项主要功能之外,SoloPi 还提供了数据 Mock,性能加压、网络模拟、智能 Monkey 等功能,能为测试开发人员节省宝贵时间。

四、APP 弱网测试&抓包工具

QNET

官网:https://wetest.qq.com/product/qnet

介绍:

QNET 是腾讯 wetest 服务平台推出了一款 App 弱网测试工具,该工具无需 ROOT 手机,无需连接数据线,以独立 app 的方式,为用户提供给快捷、可靠、功能完善的弱网络模拟服务(2G 网络、极差网络、连续丢包、正常网络、4G 网络、100%丢包等)。另外 QNET 还支持 TCP/UDP 网络协议抓包。

Fiddler

官网:https://www.telerik.com/fiddler

介绍:

Fiddler 是一款大家熟知且功能强大的抓包工具。通过设置代理,能够记录客户端与服务器端所有 http(s)通讯。可以针对捕获到的请求进行分析、设置断点、篡改请求及返回数据,还可以设置网络丢包和延时进行弱网络模拟等等。

Charles

官网: https://www.charlesproxy.com/

介绍:

Charles 是 HTTP 代理/ HTTP 监视器/反向代理,可以查看其计算机与 Internet 之间的所有 HTTP 和 SSL / HTTPS 通信。可对截取的请求及响应进行分析、支持修改请求参数、支持弱网络模拟。

五、APP 兼容性测试工具

TestIn

官网:https://www.testin.cn/

介绍:

Testin 是国内较早涉足云测试领域的平台之一。终端种类及数量都比较全面。提供远程真机测试、标准/深度/遍历兼容测试、自动化测试、测试专家驻场等。支持 Android 与 iOS 系统。但目前仅少部分服务为免费,绝大多数服务为收费项目。

腾讯优测

官网:https://utest.21kunpeng.com/home

介绍:

腾讯旗下的云测试服务平台,拥有超过 3000 台真机实验室,覆盖市面 99%主流机型。拥有十年终端测试服务经验,提供兼容性测试、自动化测试、云真机、设备分享等多种服务方式。

百度 MTC

官网:http://mtc.baidu.com/

介绍:

百度 MTC 是百度开放平台旗下的移动云测试中心。提供超过 1500 款热门机型。提供的测试服务种类有兼容性测试、性能测试、功能测试。并且提供了脚本录制工具,类似 Testin。

百度 MTC 的服务目前主要为收费服务。

阿里 MQC

官网:https://www.aliyun.com/product/mqc

介绍:

阿里 MQC 是阿里巴巴旗下的移动测试平台。提供大量热门机型,支持 Android 及 iOS 系统。提供兼容性测试、功能测试、性能测试以及稳定性测试。

六、APP 安全测试工具

OWASP ZAP

官网:https://owasp.org/www-project-zap/

介绍:

OWASP ZAP 是目前最流行的免费 APP 移动安全测试工具,由全球数百个志愿者管理维护。该工具支持多种脚本语言类型,易安装,可以在 APP 的开发和测试阶段自动查找安全漏洞。

Drozer

Github 地址:https://github.com/FSecureLABS/drozer

介绍:

Drozer 是一个由 MWR 安全团队维护开源的软件,该软件是针对 Android 平台的安全审计和攻击框架。安全人员可通过 drozer 自身提供的一些 module 完成一些基础的安全测试功能,同时也可以根据需求实现自己的 module,甚至可以在利用 drozer 提供的框架实现一些自动化审计功能。

MobSF

Github 地址:https://github.com/MobSF/Mobile-Security-Framework-MobSF
介绍:

MobSF 是一款自动化移动 App 安全测试工具,适用于 iOS 和 Android,可熟练执行动态、静态分析和 Web API 测试。可用于对 Android 和 iOS 应用进行快速安全分析。

QARK

Github 地址:https://github.com/linkedin/qark

介绍:

QARK 是一个静态代码分析工具,旨在识别基于 Java 的 Android 应用程序的潜在安全漏洞和关注点。QARK 还试图提供动态生成的 ADB(Android 调试桥)命令,以帮助验证其检测到的潜在漏洞。它甚至可以动态地创建一个定制的测试应用程序,以即用 APK 的形式,确定潜在问题。

WRK

Github 地址:https://github.com/wg/wrk/tree/master

介绍:

wrk 是一个测试并发的工具,类似 adb(ab -c 100 -n 100 http://192.168.2.56:19015/index.html)原理(wrk -t12 -c400 -d30s http://192.168.2.56:19015/index.html)

利用Socat实现单端口转发中继

前言:

oracle cloud 提供的云 mysql 通过外网链接是需要填写指定 CIDR 范围的白名单 IP,然而这个白名单 IP 不支持 0.0.0.0/24 全域,因此提供几个中继思路进行解决。

解决

Socat

假设需求是:PC1(192.168.1.215) 需要使用 PC1 3306 端口直接跳到 PC2 的 MySQL(192.168.1.91)

开始安装

Centos 系统:yum install -y socat

Debian/Ubuntu 系统:apt-get update apt-get install -y socat

成功后即可可以使用

socat -d -d -lh -v -lf /home/mysql.log tcp-l:3306,fork,reuseaddr tcp:192.168.1.91:3306

参数解析

-lh 将主机名添加到日志消息

-v 详细数据流量,文本

-x 详细数据流量,十六进制

-d 增加详细程度(最多使用 4 次;建议使用 2 次)

-lf 记录到文件

但是该命令键入后有个问题,那便是不能持久化运行,初步考虑在命令前添加 nohup 或注册 systemctl

以 debian11 为例,在目录/etc/systemd/system/下创建一个新的 service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[Unit]
Description=socat mysqli to tcp
Documentation=https://blog.catooilg.com
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=always

; User and group the process will run as.
User=root
Group=root

ExecStart=/usr/bin/socat -d -d -lh -v -lf /home/mysql.log tcp-l:3306,fork,reuseaddr tcp:192.168.1.91:3306

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576
; Unmodified caddy is not expected to use more than that.
LimitNPROC=512

[Install]
WantedBy=multi-user.

重载服务systemctl daemon-reload

启动服务 systemctl start nginx

即可完成注册

iptables

1
2
3
4
5
6
iptables -I INPUT -p tcp -m tcp --dport 转发机监听端口 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 转发机监听端口 -j DNAT --to-destination c2 ip:c2 port
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -I FORWARD -j ACCEPT
iptables -P FORWARD ACCEPT
sysctl net.ipv4.ip_forward=1

Apache

假设需求是:PC1(192.168.1.215) 需要使用 PC1 IP 直接跳到 mywbg.com

1
2
3
4
5
6
apt-get install apache2
a2enmod rewrite headers proxy proxy_http ssl cache
a2dismod -f deflate
a2ensite default-ssl
a2dissite 000-default
service apache2 reload

配置/etc/apache2/sites-enabled/default-ssl.conf 添加如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<Directory "/var/www/html">
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
LogLevel alert rewrite:trace5

# Enable SSL
SSLEngine On
# Enable SSL Proxy
SSLProxyEngine On
# Trust Self-Signed Certificates generated by CobaltStrike
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off

修改/etc/apache2/ports.conf,注释 80 端口监听,然后执行以下命令

1
2
3
4
5
6
git clone https://github.com/threatexpress/cs2modrewrite
cd cs2modrewrite
python3 cs2modrewrite.py -i default.profile -c https://192.168.1.215:8080 -r https://www.baidu.com > /var/www/html/.htaccess
-i 表示所使用的c2配置文件
-c 根据监听器配置设置
-r 表示非法访问重定向url

同时在对机添加以下参数

1
2
3
http-config {
set trust_x_forwarded_for "true";
}

trust_x_forwarded_for 选项决定 Cobalt Strike 是否使用 X-Forwarded-For HTTP 头来确定外部 ip。使用 HTTP 重定向器开启此选项,可以让 CS 显示外部 ip 的时候不再显示为代理服务器的。

如果你需要自定义 apache ssl 证书则需要修改/etc/apache2/sites-enabled/default-ssl.conf

1
2
3
SSLCertificateFile	/etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
#请尽量使用真实的ssl证书

以上配置中如果你需要使用 http 服务来转发你可以不关闭 80 端口

如果需要修改相关规则可以自行修改/var/www/html/.htaccess

Nginx

假设需求是:PC1(192.168.1.215) 需要使用 PC1 IP 直接跳到 mywbg.com

安装

apt-get install nginx nginx-extras

添加新模块

git clone https://github.com/threatexpress/cs2modrewrite

编译

python3 ./cs2nginx.py -i default.profile -c https://192.168.1.215:8080 -r https://www.baidu.com -H mywbg.com >/etc/nginx/nginx.conf

参数解析

-i 表示所使用的 c2 配置文件

-c 根据监听器配置设置

-r 表示非法访问重定向 url

-H 指向代理主机的域名

修改/etc/nginx/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
#将80端口注释关闭http
#listen 80;
#listen [::]:80;

#取消443端口注释开启https
listen 443 ssl;
listen [::]:443 ssl;

#取消ssl证书设置注释配置ssl证书
ssl_certificate /root/server.crt;
ssl_certificate_key /root/server.key;

配置完成后重启 nginx,开始配置 CS

CS 配置 C2 文件的时候在 C2 文件里加入如下选项

1
2
3
http-config {
set trust_x_forwarded_for "true";
}

trust_x_forwarded_for 选项决定 Cobalt Strike 是否使用 X-Forwarded-For HTTP 头来确定外部 ip。使用 HTTP 重定向器开启此选项,可以让 CS 显示外部 ip 的时候不再显示为代理服务器。

引用

利用 Socat 实现单端口 中继(中转/端口转发)加速

socat 链接持久的最佳方法是什么

CentOS7中升级Curl

先情提要

在部署 php7.4 的时候,发现 make 错误,翻看日志提示 curl 版本不支持几个函数,原来是机器部署的 curl 版本过低 curl 7.54.1_2017 (x86_64-pc-linux-gnu)

遂开始着手升级至最新 8.0.30

实施过程

先看看目前curl 版本,是否可以使用

yum update curl

因为部分第三方云已经把内核替换成自家(华为云与火山引擎)不行,则需要自己手工更新

1、首先安装 epel-release

yum -y install epel-release

2、下载并安装 curl 的 rpm 包

wget http://mirror.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/city-fan.org-release-3-8.rhel7.noarch.rpm

rpm -ivh city-fan.org-release-2-2.rhel7.noarch.rpm

3、将[city-fan.org]的 enable 值修改为 1

vim /etc/yum.repos.d/city-fan.org.repo

1
2
3
4
5
6
7
[city-fan.org]
name=city-fan.org repository for Red Hat Enterprise Linux (and clones) $releasever ($basearch)
#baseurl=http://mirror.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/$basearch
mirrorlist=http://mirror.city-fan.org/ftp/contrib/yum-repo/mirrorlist-rhel$releasever
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org

4、更新 curl

yum update curl --enablerepo=city-fan.org -y

5、安装完成,检查版本,完成升级

curl -V

6、同时移除 city-fan.org.repo 并删除

cp /etc/yum.repos.d/city-fan.org.repo /etc/yum.repos.d/city-fan_bak.org.repo -a

如果此方法不能正常升级,请确认系统是否安装了多个 curl

which curl

whereis curl

如果无法确认,可以选择编译安装,然后重新系统指向

1
2
3
4
5
6
7
wget https://curl.haxx.se/download/curl-7.76.1.tar.gz
tar -xvf curl-7.76.1.tar.gz
cd ./curl-7.76.1
./buildconf
./configure --with-ssl=/opt/openssl --with-nghttp2=/usr/local --disable-file --without-pic --disable-shared
make
sudo make install

重新指向

echo "export PATH=/usr/local/curl/bin:$PATH" >> /etc/profile

刷新系统变量

source /etc/profile

再次查询 curl 版本

curl --version

curl 7.76.1 (x86_64-unknown-linux-gnu) libcurl/7.76.1 OpenSSL/1.1.1w zlib/1.2.7

Release-Date: 2021-04-14

Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp

Features: alt-svc AsynchDNS HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSocket

这里需要注意的是 curl 的版本号是否和 libcurl 一样,不一样则去浏览

vim /etc/ld.so.conf

资源库是否正确软连接

1
2
include /etc/ld.so.conf.d/*.conf
/usr/local/lib # 正确的curl的资源应该在此软连接到安装目录,64位系统为lib64

更改完毕记得刷新配置文件

sudo ldconfig -v

sudo ldconfig

同时注意有无出现 WARNING

记录问题

Q: curl: symbol lookup error: curl: undefined symbol: curl_mime_free

Q: curl: symbol lookup error: curl: undefined symbol: curl_url_cleanup

Q: curl: symbol lookup error: curl: undefined symbol: curl_url

这类问题是 libcurl 软连接缺失,建议先去确认/usr/local/lib 等地方的 libcurl.so 文件是否链接到正确的地方。

1
2
3
4
5
6
sudo ldconfig -v
# ***
#/usr/local/lib:
# libcurl.so.4 -> libcurl.so.4.4.0
# libpcre.so.1 -> libpcre.so.1.2.10
# 打个比方这里的libcurl就是错误链接了,理应是/usr/local/curl/lib/libcurl.so.4.7.0

记CentOS编译nginx事务

环境须知

Nginx 版本:1.22.1

实施过程

开始编译 Nginx 之前,先参考编译语句

./configure arguments: --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log  --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-openssl=../openssl-1.0.2k --add-module=../lua-nginx-module-0.10.24 --add-module=../ngx_devel_kit-0.3.1

lua 是一个小巧的脚本语言,利用 lua-nginx-module 模块可以使用 lua 处理 nginx 请求

预先准备好 lua-nginx-module 和 ngx_devel_kit 在上级目录,注意版本号,且无需安装

1
2
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.24.tar.gz
tar zxvf v0.10.24.tar.gz
1
2
wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1.tar.gz
tar zxvf v0.3.1.tar.gz

到这里可以真正开始编译,并键入make

倘若你本来就有 Nginx,现在是更新或覆盖安装,注意千万不要make install,不然就覆盖安装现有 nginx 了

正常情况下,会弹出以下错误

./configure: error: unsupported LuaJIT version; ngx_http_lua_module requires LuaJIT 2.x.

原因是缺少 LuaJIT 环境

1
2
3
wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20220915.tar.gz
tar zxvf luajit2-2.1-20220915.tar.gz
sudo make install PREFIX=/usr/local/LuaJITL

然后再修改 lua-nginx-module 的 config 文件

1
2
3
# 直接声明这两个变量
LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.1
LUAJIT_LIB=/usr/local/LuaJIT/lib

然后继续开始 make 如无意外成功编译

问题

Q:使用 openresty 时 failed to load the resty.core module

问题是找不到 lualib 库和 resty 模块,默认到/usr/local/lib/ 去找 lualib,然而在编译安装 OpenResty 时 lualib 库默认放到/usr/local/openresty/lualib

如何使用atop监控工具

使用场景

atop 是一款用于监控 Linux 系统资源与进程的工具,能够报告所有进程的活动。其以一定的频率记录系统和进程活动,采集的数据包含 CPU、内存、磁盘、网络的资源使用情况和进程运行情况,并能以日志文件的方式保存在磁盘中。对于每个进程,会显示 CPU 使用率、内存增长、磁盘使用率、优先级、用户名、状态和退出码等。当 ECS 实例出现问题后,您可以获取相应的 atop 日志文件进行分析。

安装过程

sudo yum install atop

安装成功后,进入 atop 配置目录编辑变量

vim /etc/sysconfig/atop

其中

LOGINTERVAL:监控周期,建议将默认的监控周期 600s 修改为 30s。

LOGGENERATIONS:日志保留时间,为避免 atop 长时间运行占用太多磁盘空间,建议将默认的日志保留时间 28 天修改为 7 天。

1
2
3
4
LOGOPTS=""
LOGINTERVAL=30
LOGGENERATIONS=7
LOGPATH=/var/log/atop

键入:wq 保存退出

atop -u

激活 atop 监控

假设需要激活网络监控,则需要 netatop 模块,这里安装 3.1 版本,也是支持 Centos7 的最后一个版本,也相对较稳定。

sudo apt install zlib1g-dev

执行如下命令,继续下载 netatop 安装包。

sudo wget [https://www.atoptool.nl/download/netatop-3.1.tar.gz](https://www.atoptool.nl/download/netatop-3.1.tar.gz) --no-check-certificate

开始解压,并进入目录

tar -zxvf netatop-3.1.tar.gz

编译与安装

sudo make && sudo make install

假设编译失败,出现了[Module]: /lib/modules/3.10.0-693.11.1.el7.x86_64/一般是开发包没有安装就绪,继续安装模块开发包(注意包头和模块库必须和内核相同)

sudo yum install kernel-devel-uname -r``

安装过程中,如果在源中找不到需要的模块开发包,请到以下地址下载:

https://www.central.org/dl/linuxdev/centos7/x86_64/

https://mirror.netcologne.de/oracle-linux-repos/ol7_latest/getPackage/

例如,要安装 3.10.0-693.11.1.el7.x86_64,请运行以下命令:

rpm -ivh kernel-devel-3.10.0-693.11.1.el7.x86_64.rpm

最后别忘记服务启动

sudo systemctl start netatop

atop -n

后注

筛选指引

c 按照进程 CPU 使用率进行降序筛选。
m 按照进程内存使用率进行降序筛选。
d 按照进程磁盘使用率进行降序筛选。
a 按照进程资源综合使用率进行降序筛选。
n 按照进程网络使用率进行降序筛选。
t 跳转到下一个监控采集点。
T 跳转到上一个监控采集点。
b 指定时间点,格式为 YYYYMMDDhhmm。

参数说明

ATOP 行 主机名、信息采样日期和时间点。
PRC 行 进程整体运行情况。
+ sys、user:分别代表进程在内核态和用户态的运行时间。
+ #proc:进程总数。
+ #trun:处于 running 状态进程数。
+ #tslpi:处于 sleeping interruptible 状态的进程数。
+ #tslpu:处于 sleeping uninterruptible 状态的进程数。
+ #zombie:僵死进程的数量。
+ #exit:atop 采样周期内退出的进程数。
CPU 行 CPU 整体的使用情况,即多核 CPU 作为一个整体 CPU 资源的使用情况。CPU 行各个字段数字相加结果为 N*100%,其中 N 为 CPU 的核数。
+ sys、user:CPU 在用于处理进程时,进程在内核态及用户态所占 CPU 的时间比例。
+ irq:CPU 用于处理中断的时间比例。
+ idle:CPU 处在完全空闲状态的时间比例。
+ wait:CPU 处在进程等待磁盘 IO 导致 CPU 空闲状态的时间比例。
CPL 行 CPU 负载情况。
+ avg1、avg5 和 avg15:分别代表过去 1 分钟、5 分钟和 15 分钟内运行队列中的平均进程数量。
+ csw:上下文切换次数。
+ intr:中断发生次数。
MEM 行 内存的使用情况。
+ tot:物理内存总量。
+ free:空闲内存的大小。
+ cache:用于页缓存的内存大小。
+ buff:用于文件缓存的内存大小。
+ slab:系统内核占用的内存大小。
SWP 行 交换空间的使用情况。
+ tot:交换区总量。
+ free:空闲交换空间大小。
PAG 行 虚拟内存分页情况。
swin、swout:分别代表换入和换出内存页数。
DSK 行 磁盘使用情况,每一个磁盘设备对应一列,如果有 vdb 设备,那么将会增加一行 DSK 信息。
+ vda:磁盘设备标识。
+ busy:磁盘处于 busy 状态的时间比例。
+ read、write:分别代表读、写请求数量。
NET 行 多列 NET 展示了网络状况,包括传输层 TCP 和 UDP、IP 层以及各活动的网口信息。
+ ****i:各层或活动网口接手包大小。
+ ****o:各层或活动网口发送包大小。

浅谈Meta Keywords

前言

Meta Keywords 是一个 HTML 页面中的元素,它包含了关于页面内容的关键字。它帮助搜索引擎了解页面的内容,并对搜索结果进行分类。Meta Keywords 在网页的 head 部分,可以通过的方式添加,关键字的内容通常为页面的主题或内容相关的词语。然而,许多搜索引擎已经忽略了 Meta Keywords 元素,因为其内容可以被滥用。

因此,通过 Meta Keywords 实现非常大的 SEO 作用,显然是假象,应该落在重点关注其他搜索引擎优化技巧,注意不要被骗了。

百度 - 非关键衡量指标

作为中文地区一言堂的百度,显然通过广告躺着赚钱不香吗?个人觉得百度仍是将 Meta Keywords 作为评定标准之一,不过 2018 年,一名来自中国的中文 SEO 专家写了一篇博客,援引 2013 年时一名百度搜索工程师公开发表的观点。

Meta Keywords 早就进了历史的垃圾堆了,我们会直接忽略。

Why You shouldn’t Use Meta Keywords Tag for Baidu SEO Anymore - Jinray China SEO Diary, 2018 年 7 月 4 日

Google - 完全忽略

谷歌公司自 2009 年以来就不再使用 Meta Keywords 标签作为衡量 Ranking 的因素;Google 还会对滥用 Meta Keywords 的网站进行降权惩罚。

Our web search (the well-known search at Google.com that hundreds of millions of people use each day) disregards keyword metatags completely. They simply don’t have any effect in our search ranking at present.

Google does not use the keywords meta tag in web ranking - Google Search Central Blog, 2009 年 9 月 21 日

Unsupported tags and attributes - Google Search Central Documentation

Bing - 完全忽略

Microsoft Bing 于 2014 年正式公开宣布,Meta Keywords 对于 Bing SEO 来说毫无价值:

Today, it’s pretty clear the meta keyword tag is dead in terms of SEO value. Sure, it might have value for contextual ad systems or serve as a signal to ‘bots plying the web looking for topics to target, but as far as search goes, that tag flat lined years ago as a booster.

2020 年,Microsoft Bing 时任 CEO 在 Twitter 上回推时再次表示,Bing 会无视、忽略、排除 Meta Keywords。

Blame The Meta Keyword Tag - Microsoft Bing Blog, 2014 年 10 月 4 日

The meta keyword tag is dead in terms of SEO value for @BingWMC. We exclude it and ignore it - ChristiJOlson, Head of Paid Search at Microsoft, 2020 年 5 月 29 日

Yahoo - 几乎不用

在 2009 年 Search Marketing Expo 大会上,Yahoo 时任搜索部门负责人 Cris Pierry 在问答环节上表示,Yahoo 其实早就不再将 Meta Keywords 作为一个指标。Search Engine Land 于是进行了一项测试,发现 Yahoo 仍然会索引 Meta Keywords 的信息。

Yahoo 官方对此的回复是,当 Yahoo 无法从网页的标题、description、链接、媒体文件等获取有关网页的信息时,Yahoo 仍然会使用 Meta Keywords 作为最后的稻草。

Yahoo Search No Longer Uses Meta Keywords Tag, 2009 年 10 月 6 日 The news came during the Ask The Search Engines session atSMX East in New York today. The search engines were all asked about their support of the tag. Moderator Danny Sullivan noted that only Yahoo provided support of the tag — prompting Cris Pierry, senior director of search at Yahoo, to announce that support actually had been ended unannounced “several” months ago.

Sorry, Yahoo, You DO Index The Meta Keywords Tag, 2009 年 10 月 14 日 What changed with Yahoo’s ranking algorithms is that while we still index the meta keyword tag, the ranking importance given to meta keyword tags receives the lowest ranking signal in our system.
Words that appear in any other part of documents, including the body, title, description, anchor text etc., will take priority in ranking the document – the re-occurrence of these words in the meta keyword tag will not help in boosting the signal for these words. Therefore, keyword stuffing in the keyword tag will not help a page’s recall or ranking, it will actually have less effect than introducing those same words in the body of the document, or any other section.

Yandex - 非关键衡量指标

俄罗斯最大的搜索引擎 Yandex 也是为数不多仍然使用 Meta Keywords 作为衡量指标之一的搜索引擎,但是许多来自俄罗斯的 SEO 专家都曾表示过 Meta Keywords 对改善 Yandex SEO 收效甚微。

Meta tags that Yandex takes into account

“Officially” they say they still do, but I think this is a very low weight factor, even for яндекс. This is the consensus among most of us who have done SEO in Russian :) - orun bhuiyan on Twitter, 2020 年 5 月 30 日

nginx报错问题汇总

Q:No input file specified. nginx 报错解决

“No input file specified.”原因在于使用的 PHP5.6 是 fast_cgi 模式,而在某些情况下,不能正确识别 path_info 所造成的错误。

Q:在 nginx 上启用 http2,开启 ssl,开启 HSTS

1.1 检查 OpenSSL

如果系统的 openssl 版本较低,比如低于 1.0.2 ,先升级下

wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
tar -zxvf openssl-1.0.2k.tar.gz
进入目录编译安装 ./config
make && make install

移除旧版本 OpenSSL

mv /usr/bin/openssl /tmp/
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

检查是否为新版本了 openssl version

OpenSSL 1.0.2k  25 May 2017

1.2 检查 nginx

这里使用的是 v1.22.0 通过 yum 安装的 nginx 版本虽然支持 http2 了,但由于使用的 openssl 版本还是低版本,所以要重新编译安装下,准备必要工具

yum -y install libxml2 libxml2-devel libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data gperftools-devel
下载解压

wget https://nginx.org/download/nginx-1.22.0.tar.gz
tar zxvf nginx-1.22.0.tar.gz

1.3 配置编译 nginx

1
./configure --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-openssl=../openssl-1.0.2k

编译安装 make && make install
查看下是否是新版本了nginx -V
关键配置文件如下,注意替换下相应的参数

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
#开启HSTS
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
listen 443 ssl http2 default_server;
server_name xiaoxiaoguo.cn www.xiaoxiaoguo.cn; #这里替换成实际的域名
ssl on;
ssl_certificate cert/214212024460825.pem; #注意证书名称
ssl_certificate_key cert/214212024460825.key;#注意证书名称
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
}

启用新配置,并验证systemctl reload nginx即可

Q:如何把 Apache htaccess 伪静态规则转换成 nginx

可以使用工具进行转换

Q:缺少 lua-nginx-module

安装 LuaJIT2,为 Nginx 添加 Lua 模块的前提需要安装 LuaJIT,这里使用的是 openresty 的 luajit2

1
2
3
4
git clone https://github.com/openresty/luajit2
cd luajit2
make
make install PREFIX=/usr/local/src/LuaJIT

看到 Successfully built LuaJIT 即成功部署,开始配置环境

1
2
3
4
5
export LUAJIT_LIB=/usr/local/LuaJIT/lib
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.1

source /etc/profile
ln -s /usr/local/LuaJIT/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

nginx: [alert] detected a LuaJIT version which is not OpenResty’s; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty’s LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html))

部分查阅 nginx error 信息反馈 luajit 问题的一般都是安装错了过期版本,并不是 luajit2

现在开始安装 2 个 Nginx Module,分别是ngx_devel_kit: NDK(nginx development kit)模块和lua-nginx-module模块。

编译 Nginx

1
2
3
cd /home/nginx-1.22.0
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_v2_module --with-pcre --with-ld-opt=-Wl,-rpath,/usr/local/src/LuaJIT/lib --add-module=../ngx_devel_kit-0.3.1 --add-module=../lua-nginx-module-0.10.21
make && make install

参考:

1、Nginx 官方说明文档
2、Nginx_dynamic_module

3、Nginx 添加 Lua 模块

4、Nginx 安装 lua-nginx-module

5、Nginx 编译安装 lua-nginx-module

善用PicHome管理你的百宝袋

何为 PicHome

欧奥 PicHome 是用于欧奥图文档系统的图片展示门户,图片搜索引擎。也能够用于 Eagle 和 Billfish 等其他图库软件的图片展示门户。

综上所述,这是一个颇为强大的图库系统,我们可以很好的拓展全终端管理查看我们的素材库。

安装与部署

Pichome 部署程序