Rootop 服务器运维与web架构

2019-04-29
发表者 Venus
nginx中try_files作用及location @作用已关闭评论

nginx中try_files作用及location @作用

# nginx 配置文件:

server {

    listen 80;
    server_name  api.xxx.com;

    root /mnt/try;

    location / {
        add_header  Content-Type 'text/html; charset=utf-8';
        #echo $uri;
        try_files $uri @default;
    }

    location @default {
        root /mnt/default;
    }
}

location @xxx解释:定义一个location段,不能被外部请求所访问,只能用于nginx内部配置指令使用,比如 try_files、error_page。
$uri解释:URI代表资源的名称

浏览器访问 http://api.xxx.com/abc/index.html 时,当前的$uri值为/abc/index.html

可以通过编译nginx参数--add-module添加第三方echo模块打印$uri

echo模块地址:https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz

# try_files作用:
try_files会先尝试去/mnt/try目录下找abc目录下的index.html,如果有,直接返回,没有的话则跳转到@default部分(内部重定向)。
在default部分会去/mnt/default目录下找abc目录下的index.html,有,直接返回,没有就返回404错误。

try_files可以理解为实现rewrite的作用。

2019-04-26
发表者 Venus
package golang.org/x/sys/unix: unrecognized import path “golang.org/x/sys/unix” (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)已关闭评论

package golang.org/x/sys/unix: unrecognized import path “golang.org/x/sys/unix” (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

root@venus:~/桌面/go_project/process# go get -t golang.org/x/sys/unix
package golang.org/x/sys/unix: unrecognized import path "golang.org/x/sys/unix" (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

在用go get安装包时出错,这个是因为被墙了(不明白为什么)。

这里通过配置代理后再安装需要的包

# shell中设置http、https代理

root@venus:~/桌面/go_project/process# export http_proxy=http://127.0.0.1:1111
root@venus:~/桌面/go_project/process# export https_proxy=http://127.0.0.1:1111

# 忽略某个地址走代理,多个用逗号隔开,支持域名或ip

root@venus:~/桌面/go_project/process# no_proxy="www.rootop.org"

127.0.0.1:1111 是我本地shadowsocks-Qt5客户端监听的地址。


在shell中通过设置http_proxy和https_proxy两个变量,可以提供给curl、wget之类的命令自动走代理。同样go get时也会自动找这俩变量实现代理。
再次安装解决。

2019-04-25
发表者 Venus
cmd/go: unsupported GOOS/GOARCH pair linux /amd64已关闭评论

cmd/go: unsupported GOOS/GOARCH pair linux /amd64

windows下go编译成linux可执行文件报错:
cmd/go: unsupported GOOS/GOARCH pair linux /amd64

操作步骤如下:
D:\web\go>SET CGO_ENABLED=0
D:\web\go>SET GOOS=linux 
D:\web\go>SET GOARCH=amd64
D:\web\go>go build moniterLogstash.go

最后还是在 https://github.com/golang/go/issues/24501#issuecomment-375682124 找到原因。
是因为在 SET GOOS=linux 这句后面多了个空格(直接复制的命令。。。)
编译器也没有自动去掉多余的空格,不容易发现错误原因。

2019-04-23
发表者 Venus
利用rsync删除大量文件已关闭评论

利用rsync删除大量文件

有个文件夹有大量文件(四百多万个)需要删除,用rm是不行的,会提示 Argument list too long ,就需要一个快速删除方法。
这里采用rsync把一个空文件夹同步到要删除的文件夹实现。

需要清空的目标文件夹名:creditReport

# 创建一个空文件夹

[root@sych userfiles]# mkdir empty

# 写入要保留的文件名,一行一个。建议先备份一下要保留的文件。

[root@sych userfiles]# touch list.txt 

# 执行

[root@sych userfiles]# rsync --delete-before -d --exclude-from=list.txt empty/ creditReport/

# 参数解释

--delete-before # receiver deletes before transfer, not during 传输之前先删除文件,就是利用这个参数实现。
-d              # transfer directories without recursing 不递归传输目录
--exclude-from=FILE # read exclude patterns from FILE 从指定文件中读取要排除的文件,也就是要保留的文件

这四百多万个文件删除大约用时43分钟