分类 运维 下的文章

@echo off

Color a9

rem rarPath:WINRAR安装路径
set rarPath="E:Program FilesWinRARWinRAR.exe"
echo WINRAR安装路径是:%rarPath%

rem currentDate:获取的当前日期字符串
for /f "tokens=1,2,3 delims=/- " %%a in ("%date%") do @set currentDateNow=%%a%%b%%c
echo 获取的当前日期字符串是:%currentDateNow%

@echo off
rem 计算指定天数之前的日期
set DaysAgo=2
rem 假设系统日期的格式为yyyymmdd
call :DateToDays %date:~0,4% %date:~5,2% %date:~8,2% PassDays
set /a PassDays-=%DaysAgo%
call :DaysToDate %PassDays% DstYear DstMonth DstDay
set currentDate=%DstYear%%DstMonth%%DstDay%
echo 获取的%DaysAgo%天的日期是%currentDate%

rem workPath:工作路径
set workPath="D:WorkOrderEngineWorkOrderEnginecsv"
echo 工作路径是:%workPath%

rem bakPath:备份文件夹
set bakPath="D:WorkOrderEngineWorkOrderEnginecsv%currentDate%"
echo 备份文件夹是:%bakPath%

echo 开始生成备份文件夹
md %bakPath%

echo 开始复制文件到备份文件夹
if exist %workPath%*%currentDate%.csv copy %workPath%*%currentDate%.csv %bakPath%\

echo 开始备份
%rarPath% a -ibck -m5 %bakPath%.rar %bakPath%

echo 备份完成

Pause

:DateToDays %yy% %mm% %dd% days
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12z-3,j=153m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
endlocal&set %4=%j%&goto :EOF

:DaysToDate %days% yy mm dd
setlocal ENABLEEXTENSIONS
set /a a=%1+2472632,b=4a+3,b/=146097,c=-b146097,c/=4,c+=a
set /a d=4c+3,d/=1461,e=-1461d,e/=4,e+=c,m=5e+2,m/=153,dd=153m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm=12,mm+=m+3,yy=b100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %2=%yy%&set %3=%mm%&set %4=%dd%&goto :EOF

思路:
多进程 multiprocessing
输入输出 IO (DIO、AIO Asynchronous)
缓冲区 buffer 针对时间,分批,write-buffer
快速缓冲贮存区 cache 针对存储,分块,read-cache,大多数时候用cache代替buffer可以
通用网关接口 fastcgi(Common Gateway Interface)

1 multiprocessing
grep ^processor /proc/cpuinfo | wc -l
vim /etc/nginx/nginx.conf
vim /etc/nginx/conf.d/default.conf
worker_processes auto
systemctl restart nginx
ps -aux | grep nginx |grep -v grep

2 IO
事件处理模型
events {
use epoll;
}
windows中是kqueue

3 buffer
vim /etc/nginx/nginx.conf
client_body_buffer_size 512k;

4 cache
为1,000个元素定义了一个缓存,到期时间为60秒
http
{
open_file_cache max=1000 inactive=60s;
}

5 fastcgi
mkdir /home/www/cache
vim /etc/nginx/conf.d/default.conf
server外添加
fastcgi_cache_path /home/www/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "schemerequest_methodhostrequest_uri";
php中添加
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 60m;
systemctl reload nginx

6 expire
可以在http段中或者server段中或者location段中加入

root   /home/www/wuye/public;
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
        expires      1d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      1h;
    }

安装gcc
yum install gcc

安装git
yum install git

安装GO语言环境
yum install go
go version

下载ngrok源码
cd /usr/local/src
git clone https://github.com/inconshreveable/ngrok.git
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=flask.huchangyi.com" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=flask.huchangyi.com" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

将新生成的证书,替换掉assets/client/tls下的证书
yes|cp rootCA.pem assets/client/tls/ngrokroot.crt
yes|cp device.crt assets/server/tls/snakeoil.crt
yes|cp device.key assets/server/tls/snakeoil.key

编译生成ngrokd(服务端)
这里是交叉编译,linux系统GOOS=linux,64位系统GOARCH=amd64,32位系统GOARCH=386
当前系统可用go env查看
GOOS=linux GOARCH=amd64 make release-server

启动服务端(/usr/local/src/ngrok目录下)
nohup /usr/local/src/ngrok/bin/ngrokd -tlsKey="assets/server/tls/snakeoil.key" -tlsCrt="assets/server/tls/snakeoil.crt" -domain="flask.huchangyi.com" -httpAddr=":8081" -httpsAddr=":8082" -tunnelAddr=":8083" &

添加新的域名解析
*.flask

编译生成ngrok(客户端)
linux版客户端: make release-client
windows客户端32位: GOOS=windows GOARCH=386 make release-client
windows客户端64位: GOOS=windows GOARCH=amd64 make release-client
MAC: GOOS=darwin GOARCH=amd64 make release-client

客户端执行
nohup /home/ngrok/bin/ngrok -config /home/ngrok/bin/ngrok.cfg -proto tcp 22 &
nohup /home/ngrok/bin/ngrok -subdomain rasp -config /home/ngrok/bin/ngrok.cfg 80 &
或者
nohup /home/ngrok/bin/ngrok -subdomain rasp -config /home/ngrok/bin/ngrok.cfg start http https ssh

配置文件格式(ngrok.cfg)

server_addr: "flask.huchangyi.com:8083"
trust_host_root_certs: false
tunnels:
  http:
    subdomain: "www"
    proto:
      http: "8090"
      
  https:
    subdomain: "www"
    proto:
      https: "8091"
 
  ssh:
    remote_port: 3333
    proto:
      tcp: "22"

编译树莓派上的ngrok客户端
将刚才用来编译ngrok服务端的ngrok源码文件夹全部复制到树莓派上:
cd ./ngrok
make release-client
出错时
把源码目录下bin/go-bindata删除,然后执行make release-client
直接下载已经编译好的
wget http://huchangyi.com/doc/ngrok-rasp.zip
unzip ngrok-rasp.zip
mv ngrok-rasp ngrok
vim /etc/rc.local
bash /home/ngrok/start-ngrok.sh