kibana + elasticsearch 使用 Chrome/safari 请求 403 forbidden

elasticsearch 版本 2.3.1

由于 Elasticsearch 在处理 CORS 的一个BUG,kibana 在 firefox 上是正常,使用 chrome / safari 则会报错

  1. Normal user-agent is ok
    curl -v 'https://xxx.my.host/elasticsearch/_mget?timeout=0&ignore_unavailable=true&preference=1465897339430' -H 'origin: https://xxx.my.host' -H 'user-agent: Rajax/1 Redmi_3/ido Android/5.1.1 Display/LMY47V Eleme/5.10.2 ID/fa0ef395-659a-3150-b347-f258248013af; KERNEL_VERSION:3.10.49-perf-g6241083 API_Level:22 Mozilla/5.0 (Linux; Android 5.1.1; Redmi 3 Build/LMY47V; wv)' -d '{"docs":[{"_index":".kibana","_type":"config","_id":"4.5.1"}]}'
    *   Trying 115.x.x.42...
    * Connected to xxx.my.host (115.x.x.42) port 443 (#0)
    * TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
    * Server certificate: *.ele.me
    * Server certificate: GeoTrust SSL CA - G3
    * Server certificate: GeoTrust Global CA
    > POST /elasticsearch/_mget?timeout=0&ignore_unavailable=true&preference=1465897339430 HTTP/1.1
    > Host: xxx.my.host
    > Accept: */*
    > origin: https://xxx.my.host
    > user-agent: Rajax/1 Redmi_3/ido Android/5.1.1 Display/LMY47V Eleme/5.10.2 ID/fa0ef395-659a-3150-b347-f258248013af; KERNEL_VERSION:3.10.49-perf-g6241083 API_Level:22 Mozilla/5.0 (Linux; Android 5.1.1; Redmi 3 Build/LMY47V; wv)
    > Content-Length: 62
    > Content-Type: application/x-www-form-urlencoded
    >
    * upload completely sent off: 62 out of 62 bytes
    < HTTP/1.1 200 OK
    < Server: nginx/1.9.6
    < Date: Wed, 15 Jun 2016 03:47:01 GMT
    < Content-Type: application/json; charset=UTF-8
    < Content-Length: 116
    < Connection: keep-alive
    < Vary: Accept-Encoding
    <
    * Connection #0 to host xxx.my.host left intact
    {"docs":[{"_index":".kibana","_type":"config","_id":"4.5.1","_version":1,"found":true,"_source":{"buildNum":9892}}]}
    

  2. Got 403 forbidden with Chrome/Safari user-agent…

    curl -v 'https://xxx.my.host/elasticsearch/_mget?timeout=0&ignore_unavailable=true&preference=1465897339430' -H 'origin: https://xxx.my.host' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)' -d '{"docs":[{"_index":".kibana","_type":"config","_id":"4.5.1"}]}'
    *   Trying 115.x.x.12...
    * Connected to xxx.my.host (115.x.x.12) port 443 (#0)
    * TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
    * Server certificate: *.my.host
    * Server certificate: GeoTrust SSL CA - G3
    * Server certificate: GeoTrust Global CA
    > POST /elasticsearch/_mget?timeout=0&ignore_unavailable=true&preference=1465897339430 HTTP/1.1
    > Host: xxx.my.host
    > Accept: */*
    > origin: https://xxx.my.host
    > user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)
    > Content-Length: 62
    > Content-Type: application/x-www-form-urlencoded
    >
    * upload completely sent off: 62 out of 62 bytes
    < HTTP/1.1 403 Forbidden
    < Server: nginx/1.9.6
    < Date: Wed, 15 Jun 2016 03:46:08 GMT
    < Transfer-Encoding: chunked
    < Connection: keep-alive
    <
    * Connection #0 to host xxx.my.host left intact
    

将 Elasticsearch 升级到 2.3.3 可以解决。博主在论坛中讨论的原帖:https://discuss.elastic.co/t/got-403-forbidden-with-chrome-user-agent/52812

ld: library not found for -lgcc_s.10.5 在 Mac 下 NPM 编译安装的常见错误

情况:通过 Node 的 NPM 编译安装某些模块的时候报错:

ld: library not found for -lgcc_s.10.5  
clang: error: linker command failed with exit code 1 (use -v to see invocation)  

解决方案:
到 AppStore 中安装 XCode 7。装完以后,打开 XCode 并且接受 license 协议。更新之后,node-gyp 编译就没有这个问题了。

mac 网络模拟工具

先说需求,为了测试手机应用在各种网络下的情况,所以准备找一个模拟各种网络情况的工具。

其他平台的模拟工具: Linux 平台:Facebook 的开源移动网络测试工具 Augmented Traffic Control(ATC)
Windows 平台:微软 visual studio 自带的网络模拟工具 Network Emulator for Windows Toolkit (NEWT)

因为工作环境的问题,这里讨论 mac 下 xcode 自带的 Network Link Conditioner(NLC)

安装

NLC 是 xcode 的插件,可以在 “Hardware IO Tools for Xcode” 中找到。你可以在苹果开发者页面找到这个插件,传送门 https://developer.apple.com/downloads/?q=Hardware IO Tools

Download

查找 “Network Link Conditioner”, 然后选择 “Hardware IO Tools for Xcode” package.

Package

下载好之后, 打开 DMG 然后双击 “Network Link Condition.prefPane” 来安装.

System Preferences

装好以后, 你就可以通过 ON 和 OFF 来开启/关闭网络模拟了.

Network Link Conditioner

Network Link Conditioner 可以模拟多种网络环境,以下是该工具目前自带的:

  • EDGE
  • 3G
  • DSL
  • WiFi
  • High Latency DNS
  • Very Bad Network
  • 100% Loss

每种情况都是通过设置上载、下载的 带宽, 延迟, 和 丢包率 (如果设置为 0, 即不影响你当前的网络环境,本来网络是什么样子就是什么样子).

Preset

你也可以自建配置一个环境,在 【Manage Profiles…】里面自定义

wifi

如果是 IOS 的话是可以直接用苹果提供的开发者模式连上该网络(详细见:http://nshipster.com/network-link-conditioner/),不过博主这里用的是安卓测试机,所以就通过 mac 的网络共享来建一个 wifi (详见:Mac共享无线网络)然后用安卓机连上 mac 建的 wifi 就好了。

接下来就可以通过切换各种网络环境来测试应用了。切换功能在下面这个面板上:

Network Link Conditioner

Sublime Clojure 开发环境

安装 Java (在线包): http://www.java.com/en/download/chrome.jsp?locale=en
Java (离线包): http://www.java.com/en/download/windows_offline.jsp

上 Clojure 官网下载解释器: http://clojure.org/
直接下载地址: http://central.maven.org/maven2/org/clojure/clojure/1.6.0/clojure-1.6.0.zip

下载好了之后找个地方解压, 然后在该目录新建一个 clj.bat 文件, 内容:

@echo off
java -cp "当前解压目录/clojure-1.6.0.jar" clojure.main %1

请使用绝对路径, 然后将该路径加入系统 PATH (【我的电脑】右键属性->【高级系统设置】->【环境变量】->选择PATH->【编辑】->在最后加上该路径). 如果你的 sublime 是开着的, 记得重启以便 PATH 生效.
好了之后, 打开找到 sublime 的 【Tools】->【Build System】->【New Build System】然后输入:

{
    "shell_cmd": "clj $file"
}

好了, 完成了. 使用 Ctrl + B 看看效果:
clj hello world

centos 安装 vsftp

# 使用yum安装
yum -y install vsftpd
# 查看版本
rpm  -qa | grep vsftpd
# 启动服务
service vsftpd start

# 添加 ftp 账号
adduser -g ftp -s /sbin/nologin -d /home/wwwroot/lellansin.com lellansin
# 为账号设置密码
passwd lellansin
# 设置网站目录所有者(这样ftp账号才能有权限修改这上面的文件)
chown –R lellansin /home/wwwroot/lellansin.com
# 设置目录权限(根据各自需要设置吧)
chmod -R 765 /home/wwwroot/lellansin.com

sublime sftp 快捷键

配置操作

配置 ftp 服务
  Win/Linux: ctrl+alt+r+s
  OS X: ctrl+cmd+r+s
  配置一个新的ftp服务

打开ftp服务
  Win/Linux: ctrl+alt+r+b
  OS X: ctrl+cmd+r+b
  列出已配置的ftp服务

修改ftp服务
  Win/Linux: ctrl+alt+r+e
  OS X: ctrl+cmd+r+e

删除ftp服务
  Win/Linux: ctrl+alt+r+d
  OS X: ctrl+cmd+r+d

常用操作

打开远程目录
  Win/Linux: ctrl+alt+u+w
  OS X: ctrl+cmd+u+w
  用于切换远程目录,选中文件编辑文件,新建文件夹等等。(请不要在非当前ftp文件中使用该操作)

查看当前文件与远程文件的区别
  Win/Linux: ctrl+alt+u+i
  OS X: ctrl+cmd+u+i
  下载服务器上远程的文件到临时目录然后与本地的文件进行比较

显示 SFTP 面板
  Win/Linux: ctrl+alt+u+s
  OS X: ctrl+cmd+u+s
  显示 SFTP 的活动命令行

取消
  Win/Linux: ctrl+alt+u+x
  OS X: ctrl+cmd+u+x
  停止当前的操作 (连接, 上传或者下载)

上传文件
  Win/Linux: ctrl+alt+u+f
  OS X: ctrl+cmd+u+f
  上传当前文件

上传已改变的文件
  Win/Linux: ctrl+alt+u+c
  OS X: ctrl+cmd+u+c
  根据你的VCS(SVN、Git或者Hg)的上一次提交,上传所有有改变或者新建的文件

上传打开的
  Win/Linux: ctrl+alt+u+n
  OS X: ctrl+cmd+u+n
  上传所有打开的文件(that are configured with an SFTP/FTP remote)

下载文件
  Win/Linux: ctrl+alt+u+o
  OS X: ctrl+cmd+u+o
  下载选中文件的远程版本同时覆盖本地文件

上传文件夹
  Win/Linux: ctrl+alt+u+r
  OS X: ctrl+cmd+u+r
  Uploading the entire folder the current file is located in can be accomplished by pressing ctrl+alt+u+r on Windows and Linux, or ctrl+cmd+u+r on OS X.

下载文件夹
  Win/Linux: ctrl+alt+u+e
  OS X: ctrl+cmd+u+e
  Download the entire folder

Sync Local -> Remote
  Win/Linux: ctrl+alt+u+y
  OS X: ctrl+cmd+u+y
  Compare file modification times and confirm actions before uploading the selected file or folder. This will also delete files off of the remote server that do not exist locally.

Sync Remote -> Local
  Win/Linux: ctrl+alt+u+d
  OS X: ctrl+cmd+u+d
  Compare file modification times and confirm actions before downloading the selected file or folder. This will also delete files off of the local machine that do not exist remotely.

Sync Both Directions
  Win/Linux: ctrl+alt+u+b
  OS X: ctrl+cmd+u+b
  Compare file modification times and confirm actions before uploading/downloading the selected file or folder. This will never delete files, and will always perform the action that causes the newest file to be present in both locations.

Monitor File
  Win/Linux: ctrl+alt+u+m
  OS X: ctrl+cmd+u+m
  Watch the file for modifications (from Sublime or other applications). When the file modification time changes, the file will be uploaded. This was designed to be used with programs such as LiveReload and CSS compliers. The file must remain open in Sublime to be monitored. Once it is closed, monitoring stops.

原文链接:http://wbond.net/sublime_packages/sftp/usage#Key_Bindings_Both_Workflows