让Vagrant在Windwos下支持使用NFS/SMB共享文件夹从而解决目录共享IO缓慢的问题

自己的本是mbp vagrant使用nfs共享文件夹,所以使用一切ok,但是公司的开发环境是windows10。
windows下是有些问题的,就是在windows下默认的虚拟机共享文件夹的方式,磁盘IO效率实在是太低了。
表现情况,vagrant ssh 在/vagrant/project 下敲命令都卡啊卡,表现的和连接美国vps一样!
执行php程序,从调试来看,花费在文件IO上的时间实在是有点长,能达到1-3秒
vagrant在windows共享文件夹实在是太慢了,亏我忍受那么久。
一直在忍啊忍啊,今天实在是受不了,想要解决掉这个问题,想办法让windows支持NFS或者samb的方式共享文件夹给vagrant虚拟机
如果能支持NFS就当然是最好。
找到vagrant-winnfsd这个vagrant的插件
发现新版也支持Windows下SMB的方式了

NFS方式使用vagrant-winnfsd

安装vagrant 插件 vagrant-winnfsd

$ vagrant plugin install vagrant-winnfsd
但是这样安装会出现以下错误

Installing the 'vagrant-winnfsd' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

An error occurred while installing childprocess (0.5.8), and Bundler cannot continue.
Make sure that `gem install childprocess -v '0.5.8'` succeeds before bundling.

Warning: this Gemfile contains multiple primary sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. To upgrade this warning to an error, run `bundle config disable_multisource true`.Gem::RemoteFetcher::FetchError: Errno::ECONNABORTED: An established connection was aborted by the software in your host machine. - SSL_connect (https://rubygems.org/gems/childprocess-0.5.8.gem)

看来是缺少childprocess-0.5.8.gem这个东西
索性把需要的包都下载到本地,然后本地安装
https://rubygems.org/gems/childprocess-0.5.8.gem
https://rubygems.org/gems/vagrant-winnfsd-1.1.0.gem
然后

vagrant plugin install childprocess-0.5.8.gem
vagrant plugin install vagrant-winnfsd-1.1.0.gem

看一看安装好的插件

$ vagrant plugin list
childprocess (0.5.8)
  - Version Constraint: 0.5.8
vagrant-share (1.1.4, system)
vagrant-winnfsd (1.1.0)
  - Version Constraint: 1.1.0

配置

编辑项目下的Vagrantfile文件
网络设置为私有,仅宿主机

config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.network "private_network", type: "dhcp"

在Vagrant.configure(‘2’) do |config| 中加入

Vagrant.configure('2') do |config|
  # other config here
  config.vm.network "private_network", ip: "192.168.33.10"

  #winfsd
  config.winnfsd.logging = "on"
  config.winnfsd.uid = 1
  config.winnfsd.gid = 1
  config.vm.synced_folder "./", "/vagrant", type: "nfs"
end

SMB方式Windows共享方式

配置

Vagrant.configure('2') do |config|
  # other config here
  config.vm.network "private_network", ip: "192.168.33.10"

  #SMB
  config.vm.synced_folder "./", "/vagrant", type: "smb",
      smb_username: "母鸡Windows帐号",
      smb_password: "母鸡Windows密码",
      owner: "www",
      group: "www"
      #mount_options: ["dmode=775,fmode=664"]
end

启动vagrant虚拟机, 注意启动过程当中需要输入windwos系统的帐号和密码

d:\projects>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Preparing SMB shared folders...
    default: You will be asked for the username and password to use for the SMB
    default: folders shortly. Please use the proper username/password of your
    default: Windows account.
    default:
    default: Username: administrator
    default: Password (will be hidden):
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.26
    default: VirtualBox Version: 5.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting SMB shared folders...
    default: D:/projects => /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

d:\projects>

发现vagrant开启了一个名称为c30268623ba3dedeaa9f098b570dca21的共享
这个地方有个安全大坑,共享权限居然是Everyone!所以注意母鸡Windows上是否有其他帐号能访问!
我把c30268623ba3dedeaa9f098b570dca21本共享的权限改了,发现vagrant还是会把权限设置为Everyone
如果有开启其他普通帐号,guest什么的这里有安全隐患

C:\Users\Administrator>net share

共享名       资源                            注解

-------------------------------------------------------------------------------
IPC$                                         远程 IPC
c30268623ba3dedeaa9f098b570dca21
             D:\projects
命令成功完成。

为了防止smb共享剔除不活动的连接需要执行以下命令让系统不要自动踢掉不活动的连接
net config server /autodisconnect:-1

vagrant不会自动删除共享,要删除共享使用命令
net share c30268623ba3dedeaa9f098b570dca21 /delete

参考资料

vagrant-winnfsd项目源码
开启 NFS 文件系统提升 Vagrant 共享目录的性能
NFS for Vagrant on Windows
Vagrant SYNCED FOLDERS
Vagrant 使用 samba 共享文件夹

nginx tengine openresty之间是什么关系?

tengine相当于是nginx的二次开发,做了一些改动,增加了独有的一些功能
openresty是nginx的增强版,扩展了很多模块,特色是引入了lua支持模块,当然还有非常多个其他的模块,nginx核心使用的是原版nginx,并且使用的较新的mainline版本,比如1.9.3.2中包含的nginx版本为nginx-1.9.3 mainline

编译安装openresty

wget https://openresty.org/download/openresty-1.13.6.1.tar.gz
tar zxvf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1
#如果已经安装过nginx可以看看原来的编译参数,这里增加上去
#/usr/local/nginx/sbin/nginx -V
./configure --user=www --group=www --prefix=/usr/local --with-luajit --with-http_iconv_module  --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module
make
make install
# install后原来的 /usr/local/nginx/sbin/nginx 会被cp 成  /usr/local/nginx/sbin/nginx.old
/usr/local/nginx/sbin/nginx -v
#检查是否安装成功
/usr/local/nginx/sbin/nginx -t
#测试配置文件是否通过

/etc/init.d/nginx reload
# 其他可选编译参数
# GeoIP 
--with-http_geoip_module

nginx lua waf 网站应用防火墙

https://github.com/alexazhou/VeryNginx
https://github.com/starjun/openstar
https://github.com/loveshell/ngx_lua_waf
https://github.com/nixuehan/Belial
https://github.com/Hevienz/WizWAF
https://github.com/p0pr0ck5/FreeWAF
https://github.com/search?l=lua&q=waf&type=Repositories&utf8=%E2%9C%93

mysql中databases库和tables表中字符集 utf8 和utf8mb4 有什么区别?

可以简单的理解 utf8mb4 是目前最大的一个字符编码,支持任意文字.

那么utf8mb4比utf8多了什么的呢?
多了emoji编码支持.
如果实际用途上来看,可以给要用到emoji的库或者说表,设置utf8mb4.
比如评论,文章什么的要支持emoji可以用到.

建议普通表使用utf8 如果这个表需要支持emoji就使用utf8mb4

新建mysql库或者表的时候还有一个排序规则
utf8_unicode_ci比较准确,utf8_general_ci速度比较快。通常情况下 utf8_general_ci的准确性就够我们用的了,在我看过很多程序源码后,发现它们大多数也用的是utf8_general_ci,所以新建数据 库时一般选用utf8_general_ci就可以了
如果是utf8mb4那么对应的就是 utf8mb4_general_ci utf8mb4_unicode_ci

用PECL自动安装Redis扩展、Swoole扩展

yum install GeoIP GeoIP-devel GeoIP-data
pecl install igbinary
pecl install redis
pecl install swool

编译安装PHP7并安装Redis扩展Swoole扩展

在编译php7的机器上已经有编译安装过php5.3以上的版本,从而依赖库都有了

本php7是编译成fpm-php 使用的,

如果是apache那么编译参数应该为

--with-apxs2=/usr/local/apache/bin/apxs

编译安装php7

PHP_VERSION=7.2.6
wget -c http://www.php.net/distributions/php-$PHP_VERSION.tar.gz
tar zxvf php-$PHP_VERSION.tar.gz
cd php-$PHP_VERSION

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir -\
-with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache

make ZEND_EXTRA_LIBS='-liconv'

make install

    echo "Copy new php configure file..."
    mkdir -p /usr/local/php/{etc,conf.d}
    \cp php.ini-production /usr/local/php/etc/php.ini

    # php extensions
    echo "Modify php.ini......"
    sed -i 's/post_max_size =.*/post_max_size = 50M/g' /usr/local/php/etc/php.ini
    sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
    sed -i 's/;date.timezone =.*/date.timezone = PRC/g' /usr/local/php/etc/php.ini
    sed -i 's/short_open_tag =.*/short_open_tag = On/g' /usr/local/php/etc/php.ini
    sed -i 's/;cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
    sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /usr/local/php/etc/php.ini
    sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php/etc/php.ini

ln -sf /usr/local/php/bin/php /usr/bin/php
ln -sf /usr/local/php/bin/phpize /usr/bin/phpize
ln -sf /usr/local/php/bin/pear /usr/bin/pear
ln -sf /usr/local/php/bin/pecl /usr/bin/pecl
ln -sf /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
pear config-set php_ini /usr/local/php/etc/php.ini
pecl config-set php_ini /usr/local/php/etc/php.ini

cd ..

编译安装php7的redis扩展支持

wget -c https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zip

cd phpredis-php7
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
cd ..

/usr/local/php7/etc/php.ini
中加入
extension=redis.so

编译安装php7的swoole

wget -c https://github.com/swoole/swoole-src/archive/swoole-1.7.21-stable.tar.gz
tar zxvf swoole-1.7.21-stable.tar.gz
cd swoole-src-swoole-1.7.21-stable/
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
cd ..

/usr/local/php7/etc/php.ini
中加入
extension=swoole.so

WHOIS协议规范

RFC 3912定义了一个非常简单的Internet信息查询协议——WHOIS协议。其基本内容是,先向服务器的TCP端口43建立一个连接,发送查询关键字并加上回车换行,然后接收服务器的查询结果。(已过时的RFC 954,RFC 812)

Internet管理机构 

世界上各级Internet管理机构秉承公开、公正、共享的原则,设立了可以查知IP地址和域名所有者登记资料的WHOIS服务器,以便所有Internet的使用者排除故障、打击网上非法活动。全世界国际区域性的IP地址管理机构如下图

 

五个国际区域性IP地址管理机构所负责的区域

五个国际区域性IP地址管理机构所负责的区域

(此图摘自http://www.iana.org/numbers)

 

Registry Area Covered
AFRINIC Africa Region
APNIC Asia/Pacific Region
ARIN Canada, USA, and some Caribbean Islands
LACNIC Latin America and some Caribbean Islands
RIPE NCC Europe, the Middle East, and Central Asia

重要的Internet管理机构和常用的WHOIS服务器

机构缩写 WHOIS服务器地址 机构全名及地点 提供查询内容
CERNIC whois.edu.cn 中国教育与科研计算机网网络信息中心
(清华大学·中国北京)
中国教育网内的IP地址和.edu.cn域名信息
CNNIC whois.cnnic.net.cn 中国互联网络信息中心
(中国科学院计算机网络信息中心·中国北京)
.cn域名(除.edu.cn)信息
INTERNIC whois.internic.net 互联网络信息中心
(美国洛杉矶市Marina del Rey镇)
.com,.net,.org,.biz,.info,.name
域名的注册信息(只给出注册代理公司)
ARIN whois.arin.net 美国Internet号码注册中心
(美国弗吉尼亚州Chantilly市)
全世界早期网络及现在的美国、加拿大、撒哈拉沙漠以南非洲的IP地址信息
APNIC whois.apnic.net 亚洲与太平洋地区网络信息中心
(澳大利亚昆士兰州密尔顿镇)
东亚(包括中国大陆和台湾)、南亚、大洋洲IP地址注信息
RIPE whois.ripe.net 欧州IP地址注册中心(荷兰阿姆斯特丹) 欧洲、北非、西亚地区的IP地址信息
TWNIC whois.twnic.net 台湾互联网络信息中心(中国台湾台北) .tw域名和部分台湾岛内IP地址信息
JPNIC whois.nic.ad.jp 日本互联网络信息中心(日本东京) .jp域名和日本境内的IP地址信息
KRNIC whois.krnic.net 韩国互联网络信息中心(韩国汉城) .kr域名和韩国境内的IP地址信息
LACNIC whois.lacnic.net 拉丁美洲及加勒比互联网络信息中心(巴西圣保罗) 拉丁美洲及加勒比海诸岛IP地址信息
AFRINIC whois.afrinic.net 非洲互联网络信息中心(毛里求斯注册) IP地址信息

 

如果通过WHOIS TCP 43原生接口查询

查询Domain域名一般要到对应的管辖注册商那里去查

查询IP可以使用 whois.radb.net 一般都能查到

# WHOIS查询方法 #

简单直接的telnet法

telnet whois.radb.net 43 输入要查询的ip 223.6.6.6 回车后返回查询结果,tcp连接自动关闭

[root@dev]# telnet whois.radb.net 43
Trying 198.108.0.18…
Connected to whois.radb.net.
Escape character is ‘^]’.
223.6.6.6
route: 223.6.0.0/16
descr: ChinaNet ZheJiang Province Customer
origin: AS4134
mnt-by: MAINT-AS4134
changed: liyj@cndata.com 20110321
source: SAVVIS
Connection closed by foreign host.

whois查询客户端工具

Linux OSX都有whois客户端

yum install whois

brew install whois
[root@dev ~]# whois -h whois.radb.net 223.6.6.6
route: 223.6.0.0/16
descr: ChinaNet ZheJiang Province Customer
origin: AS4134
mnt-by: MAINT-AS4134
changed: liyj@cndata.com 20110321
source: SAVVIS

以阿里公共dns的ip来看radb.net提供的数据够老的,没更新

另外一个查询服务器

[root@dev ~]# whois -h whois.cymru.com 223.6.6.6
AS | IP | AS Name
37963 | 223.6.6.6 | CNNIC-ALIBABA-CN-NET-AP Hangzhou Alibaba Advertising Co.,Ltd.,CN

Web版查询IP ASN

IPIP.NET

BGP.HE.NET

CYMRU

ASNMAP

IPLOOKUP

 WHOIS新标准RDAP协议  

新的WHOIS协议 RDAP协议

2015年CNNIC主导新的WHOIS标准

RFC 7480 ASCII,PDF HTTP Usage in the Registration Data Access Protocol (RDAP) A. Newton, B. Ellacott, N. Kong March 2015 Proposed Standard
RFC 7482 ASCII,PDF Registration Data Access Protocol (RDAP) Query Format A. Newton, S. Hollenbeck March 2015 Proposed Standard
RFC 7483 ASCII,PDF JSON Responses for the Registration Data Access Protocol (RDAP) A. Newton, S. Hollenbeck March 2015 Errata Proposed Standard
RFC 7484 ASCII,PDF Finding the Authoritative Registration Data (RDAP) Service M. Blanchet March 2015 Proposed Standard
RFC 7485 ASCII,PDF Inventory and Analysis of WHOIS Registration Objects L. Zhou, N. Kong, S. Shen, S. Sheng, A. Servin March 2015 Informational

RFC7480(基于HTTP的注册数据访问协议(RDAP)用法):https://www.rfc-editor.org/info/rfc7480

RFC7481(注册数据访问协议(RDAP)安全服务):https://www.rfc-editor.org/info/rfc7481

RFC7485(WHOIS注册对象目录与分析):https://www.rfc-editor.org/info/rfc7485

CNNIC技术专家主导制定互联网下一代WHOIS国际标准

https://www.arin.net/resources/rdap.html

RDAP协议IP WHOIS信息查询的应用

用python写的使用RDAP协议的IP WHOIS查询工具

IPWHOIS

NicInfo is a smart, command-line RDAP client

NicInfo

# Golang Build 官方发布 #

Sublime Text build system integration packages

Gophers,

This is our first stable release of a set of Sublime Text packages (v0.9.0):

  • ‘golangconfig’ is a developer library used to obtain information about the local Go environment. It handles configuration ($GOPATH, etc) through a combination of auto-detection and configuration. It is designed to be used by other Go-related Sublime Text packages.
  • ‘Golang Build’ provides Go toolchain integration with the Sublime build system – go build, go run, go install, go test. It is the first package to utilize the functionality of golangconfig.

Golang Build can be installed via packagecontrol.io:

  1. If you don’t already have Package Control installed, follow these instructions.
  2. Run the “Install Package” command via the command palette
  3. Type “Golang Build” and press enter

User documentation for Golang Build is available here. If you’d like to contribute to either package, there is also complete developer documentation available on Github (golangconfigGolang Build).


Please file bugs using the appropriate issue trackers on Github. For problems with Go environment detection and configuration, issues should be filed at:

For bugs related to the build command integration, issues should be filed at:

Our goal is to have other Go-related Sublime packages adopt golangconfig. This would allow users to set their Go environment configuration in one place and have that used by all of their installed Go/Sublime packages. If you are an author of a Go-related Sublime Text package, we’d love to hear your feedback on golangconfig.

Happy Editing,
The Go Team

Sublime Text 安装 GO说明

想必已经安装了st的插件管理器

直接安装名称为 “Golang Build “即可

Golang Build 源码  

Golang Build

Golang Build 文档

Golang Build 使用文档