BlueXIII's Blog

热爱技术,持续学习

0%

参考文档

常规操作

1
2
3
4
5
6
7
8
9
10
# 配置文件
vi /etc/chrony.conf

# 查看同步状态
timedatectl

# 开机自启
systemctl status chronyd
systemctl start chronyd
systemctl enable chronyd

服务端配置

1
2
3
4
driftfile /var/lib/chrony/drift
local stratum 8
manual
allow 0.0.0.0/0

客户端配置

1
2
3
4
server master iburst
driftfile /var/lib/chrony/drift
logdir /var/log/chrony
log measurements statistics tracking

参考文档

配置健康测试端点

修改Nacos配置,在application-dev.yml中添加management.endpoint.health.show-details参数,注意低版本的SpringBoot中endpoint没有’s’

1
2
3
4
5
6
7
8
management:
endpoint:
health:
show-details: "ALWAYS"
endpoints:
web:
exposure:
include: '*'

健康测试:

1
2
curl http://10.133.0.63:30508/actuator/health/ping
{"status":"UP"}

修改K8S配置添加readinessProbe

1
2
3
4
5
6
7
readinessProbe:
httpGet:
scheme: HTTP
path: /actuator/health/ping
port: 4000
initialDelaySeconds: 10
periodSeconds: 5

本机安装kubectl

1
brew install kubectl 

配置kubeconfig

vi ~/.kube/config

1

拷贝文件

https://kubernetes.io/docs/reference/kubectl/cheatsheet/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 查询所有命名空间
kubectl get namespaces

# 查询所有Deployment
kubectl get deployments -n dubhe-test

# 查询Pods
kubectl get pods -n dubhe-test | grep dubhe-metadata-deploy

# 进入容器
kubectl exec -it -n dubhe-test dubhe-metadata-deploy-758df87bfd-wqhs2 -- /bin/bash

# 得到容器内日志路径
cd /dubhe-metadata-biz/logs

# 拷贝目录到本机
kubectl cp -n dubhe-test dubhe-metadata-deploy-758df87bfd-wqhs2:/dubhe-metadata-biz/logs ./

说明

  • 针对老项目,多个模块共用一个git仓库的情况,识别出每次push的变更,只构建对应的模块
  • 如果配置多个git地址相同的Jenkins流水线,他们的hook地址也是相同的,无法单独触发其中一个流水线。所以要配置多个镜像仓库。
  • 使用原始方式配置最便捷,不使用gitlab、gogs
  • 当使用ssh协议对外暴露git时,由于jenkins的bug?,可以手工构建但无法通过hook触发。所以必须再配置httpd服务通过http对外暴露。

git镜像仓库配置

参考文档

https://blog.csdn.net/mxdzchallpp/article/details/80597126

  • 使用http协议对外暴露,搭建方式不再赘述
  • 为一个仓库配置多个镜像时,可以用ln -s软链接方式实现

Jenkins流水线配置

为每个模块配置独立的流水线,使用独立的仓库

自动构建测试:

1
curl http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-alert

Git镜像库同步脚本

使用后台进程while do循环方式,每10秒pull一次

sync.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh

GIT_PATH=/dubhe/git/develop
BASE_PATH=/dubhe/git/sync-dev
SLEEP_SEC=10

while :
do
echo Git同步开始 `date +"%Y/%m/%d %H:%M:%S"` | tee -a sync.log

# 拉取git仓库更新日志到sync.dat
cd $GIT_PATH
oldsha=`git rev-parse HEAD`
git pull
git diff --name-only $oldsha | tee -a "$BASE_PATH/sync.dat" "$BASE_PATH/sync.log"

# 判断发生变更的模块并发送通知到Jenkins
cd $BASE_PATH
cat sync.cfg|while read line
do
module=`echo $line|awk -F ' ' '{print $1}'`
hook=`echo $line|awk -F ' ' '{print $2}'`
count=`cat sync.dat | grep "$module"|wc -l`
#echo $module $hook $count

if test $count -gt 0
then
echo 触发构建 $module 模块 | tee -a sync.log
curl -s $hook >/dev/null
fi
done

echo Git同步完成 `date +"%Y/%m/%d %H:%M:%S"` | tee -a sync.log

# 清空dat文件
> sync.dat
echo "" | tee -a sync.log

# 休眠
sleep $SLEEP_SEC
done

sync.cfg

1
2
3
4
5
6
7
8
9
efpx-ui    http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-ui
efpx-upms http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-upms
dubhe-metadata http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-metadata
dubhe-scheduler http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-scheduler
dubhe-data-integration http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-data-integration
dubhe-alert http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-alert
dubhe-api-generation http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-api-generation
dubhe-quality http://10.133.0.186/devops_webhook/git/?url=http://10.193.2.12:8081/git/develop-quality

监听钩子(已废弃)

使用nc搭建简易HTTP服务器
因gitlat至镜像服务器的网络不可达,此方案废弃

listen.sh

1
2
3
4
5
6
while true
do
cat index.http | nc -l 8082
# echo "开始同步git"
# call sync shell
done

index.http

1
2
3
4
5
6
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Server: netcat!

<!doctype html>
<html><body><h1>开始同步GIT</h1></body></html>

测试

1
2
curl http://10.193.2.12:8082
curl http://10.193.2.12:8083

官网

https://github.com/ginuerzh/gost

WS端口复用

服务端Gost

1
./gost -L "ws://172.17.0.1:31314?path=/gost"

服务端Nginx转发

1
2
3
4
5
6
7
8
9
10
location /ray {
proxy_redirect off;
proxy_pass http://172.17.0.1:31313;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

本机Gost

1
./gost -L=:7013 -F="ws://10.80.8.237:8080?path=/gost"

GitHub

https://github.com/curve25519xsalsa20poly1305/docker-openvpn-socks5

参考

https://zzz.buzz/zh/2018/03/07/windows-openvpn-logs-algorithm-too-weak-solution/

启动脚本

1
2
3
4
5
6
docker run  -itd --name ov_publish \
--device=/dev/net/tun --cap-add=NET_ADMIN \
-v /opt/openvpn/publish:/vpn:ro \
-e OPENVPN_CONFIG=/vpn/vpn.ovpn \
-p 7031:1080 \
curve25519xsalsa20poly1305/openvpn-socks5

ovpn配置文件调整

vpn.ovpn

1
2
3
4
# 继续接受弱算法保护的证书
tls-cipher "DEFAULT:@SECLEVEL=0"
# 配置用户名密码文件
auth-user-pass login.conf

login.conf

1
2
yourname
yourpass

官网

参考文档

安装

1
pip3 install scrapy

DEMO

1
2
3
4
5
6
7
8
9
10
11
12
13
import scrapy

class BlogSpider(scrapy.Spider):
name = 'blogspider'
start_urls = ['https://www.zyte.com/blog/']

def parse(self, response):
for title in response.css('.oxy-post-title'):
yield {'title': title.css('::text').get()}

for next_page in response.css('a.next'):
yield response.follow(next_page, self.parse)
EOF
1
scrapy runspider myspider.py

CLT

1
2
scrapy startproject hydrabot
scrapy genspider httpbin httpbin.org

周边生态

  • scrapy-splash
  • scrapy-redis
  • scrapyd
  • scrapyd-client
  • python-scrapyd-api
  • scrapyrt
  • gerapy

scrapyrt

参考文档

https://github.com/scrapinghub/scrapyrt/pull/120/commits/b0302994e1df2a4784f6342bddebea91ccfd7a72
https://scrapyrt.readthedocs.io/en/stable/api.html#post

运行

当前目录下运行scrapyrt
curl http://localhost:9080/crawl.json -d ‘{“start_requests”: “true”,”spider_name”: “teacher”,”crawl_args”: {“task_id”: “1”,”entry_id”: “3070”}}’

curl http://localhost:9080/crawl.json -d ‘{“start_requests”: “true”,”spider_name”: “policy_site”,”crawl_args”: {“task_id”: “5”}}’

conda

https://blog.csdn.net/weixin_43840215/article/details/89599559
wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
wget -c https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pip install scrapyd

vi /etc/scrapyd/scrapyd.conf
[scrapyd]
eggs_dir = /data/scrapyd/eggs
logs_dir = /data/scrapyd/logs
items_dir = /data/scrapyd/items
jobs_to_keep = 100
dbs_dir = /data/scrapyd/dbs
max_proc = 0
max_proc_per_cpu = 10
finished_to_keep = 100
poll_interval = 5.0
bind_address = 0.0.0.0
http_port = 6800
debug = off
runner = scrapyd.runner
application = scrapyd.app.application
launcher = scrapyd.launcher.Launcher
webroot = scrapyd.website.Root

[services]
schedule.json = scrapyd.webservice.Schedule
cancel.json = scrapyd.webservice.Cancel
addversion.json = scrapyd.webservice.AddVersion
listprojects.json = scrapyd.webservice.ListProjects
listversions.json = scrapyd.webservice.ListVersions
listspiders.json = scrapyd.webservice.ListSpiders
delproject.json = scrapyd.webservice.DeleteProject
delversion.json = scrapyd.webservice.DeleteVersion
listjobs.json = scrapyd.webservice.ListJobs
daemonstatus.json = scrapyd.webservice.DaemonStatus


nohup scrapyd>scrapyd.log 2>&1 &

open http://10.211.55.101:6800


# scrapyd服务器提前安装依赖
pip install -r requirements.txt

API

1
2
3
4
5
6
7
8
9
10
11
12
curl http://10.211.55.101:6800/daemonstatus.json
curl http://10.211.55.101:6800/addversion.json -F project=hydrabot -F version=1.0.0 -F egg=@hydrabot.egg
curl http://10.211.55.101:6800/schedule.json -d project=hydrabot -d spider=teacher -d task_id=1 -d entry_id=3070
curl http://10.211.55.101:6800/cancel.json -d project=hydrabot -d job=6487ec79947edab326d6db28a2d86S11e8247444

curl http://10.211.55.101:6800/listprojects.json
curl http://10.211.55.101:6800/listversions.json?project=hydrabot
curl http://10.211.55.101:6800/listspiders.json?project=hydrabot
curl http://10.211.55.101:6800/listjobs.json?project=hydrabot

curl http://10.211.55.101:6800/delversion.json -d project=hydrabot -d version=1.0.0
curl http://10.211.55.101:6800/delproject.json -d project=hydrabot

gerapy

官网

https://github.com/Gerapy/Gerapy

安装

1
2
3
4
5
6
7
8
pip3 install gerapy
gerapy init
cd gerapy
gerapy migrate

gerapy createsuperuser #hydrabot/hydrabot
gerapy runserver
open http://127.0.0.1:8000/

crawspider

参考文档

https://cloud.tencent.com/developer/article/1518542

shell

1
scrapy shell http://wjw.yangzhou.gov.cn/yzwshjh/csdt/wjw_list.shtml

基础库

  • code-mirror 著名编辑器基础库,支持SQL,关注
  • monaco-editor 微软,VSCode,有支持SQL的第三方fork

一体化方案

前端库

商业软件

  • sqldev 界面精美,不开源,国产

其它

  • ace 前端JS编辑器,貌似没有对SQL的支持

关于选型

  • 初步了解并罗列,未深入对比
  • 几个一体化的方案,看上去都不太好改
  • 需求灵活的话,有可能要基于code-mirror基础库自已做(或者用sql-editor这种基于code-mirror魔改的版本)

参考

https://www.v2ex.com/t/516822

参考文档

命令行

1
2
3
4
# 映射yum源
ssh -R 8081:127.0.0.1:8081 -p2203 root@192.168.23.14
# 映射socks5
ssh -R 7890:127.0.0.1:8118 -p2203 root@192.168.23.14

服务器开启gatewayport

服务器端开启gatewayport后,局域网内其它机器可共享此端口

1
2
vi /etc/ssh/sshd_config
GatewayPorts yes

本机开启临时yum服务

1
2
cd ~/opt/yum
http-server

服务器配置yum源指向

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cp -R /etc/yum.repos.d /etc/yum.repos.d.bak2

cat << EOF >>/etc/yum.repos.d/CentOS-Remote.repo
[centos7]
name=centos7
baseurl=http://127.0.0.1:8081/centos7
enabled=1
gpgcheck=0

[epel]
name=epal
baseurl=http://127.0.0.1:8081/epel
enabled=1
gpgcheck=0
EOF

yum clean all && yum makecache

本机socks5转http

解决clash的mix端口兼容性问题

1
2
3
4
5
6
7
brew install privoxy

vi /usr/local/etc/privoxy/config
listen-address localhost:8118
forward-socks5t / 127.0.0.1:7890 .

brew services start privoxy

ClashX直接开启http端口(废弃)

解决clash的mix端口兼容性问题,但7892http端口依然无效

1
2
3
vi ~/.config/clash/config.yaml
socks-port: 7891
port: 7892

导入全局代理环境变量

1
2
3
4
5
6
# 导入代理环境变量
export https_proxy=http://127.0.0.1:8118 http_proxy=http://127.0.0.1:8118 all_proxy=http://127.0.0.1:8118


# 测试
curl cip.cc

yum单独配代理

1
2
3
4
5
6
vi /etc/yum.conf
proxy=http://127.0.0.1:7890

# 禁用搜索最快镜像,避免卡顿
vi /etc/yum/pluginconf.d/fastestmirror.conf
enabled=0

docker单独配代理

1
2
3
4
5
6
7
8
mkdir -p /etc/systemd/system/docker.service.d
cat << EOF >>/etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890" "HTTPS_PROXY=http://127.0.0.1:7890" "NO_PROXY=localhost,127.0.0.1"
EOF

systemctl daemon-reload && systemctl restart docker
systemctl show --property=Environment docker

proxychains强行走代理

1
2
3
4
5
6
7
8
9
10
11
12
# 下载并编译
git clone https://github.com/rofl0r/proxychains-ng
./configure
make && make install && make install-config

# 修改配置文件
vi /usr/local/etc/proxychains.conf
[ProxyList]
socks5 127.0.0.1 7890

# 测试
proxychains4 wget www.baidu.com

localhost.run

https://localhost.run/