这一生,至少当一次傻瓜-奇迹的苹果

如果把读书比多银海拾贝,这本书就是沙粒中一颗精致优美的贝壳。

本书很精薄,我基本上是一口气读完的,从晚上9点多到临晨1点多。

全书讲述了主人公木村,因执念绿色种植苹果的理念,被人当作傻子,最终经历8年的执着和等待,最终获得成功的故事。

故事里面不光有木村的执着,还有生动鲜活的果园风光,虫鸟与风草。文章细致描写了绿色种植理念的起因和主人公实际操作后面临的真实果园处境,采用第三视角和第一视角口述的方式交叉推进,显得真实而生动。

当主人公经历8年的辛苦,孤独,嘲讽,最终看到开花结果,而他的岳父母去世的时候,我的眼眶湿润了,有多少奋斗的人能等到亲人共享的时刻。

当因为自己的执念而让妻子和孩子受苦时,木村的心里苦不甘言,只能默默承受,恰似无数正在奋斗的人们。

最终执念和傻得到了回报,而我经历了一次难得的心灵旅程。

人生难得执念,主人公的成功也不必介怀,真实的人生,大部分人面临的最终可能是失败。

but:
人生只有一次,这种执念傻瓜的经历,又何尝不是一种幸福和境界?

OpenResty最佳实践-随笔

简介

完整内容地址:https://moonbingbing.gitbooks.io/openresty-best-practices/content/index.html

决定在动手之前先把这本书浅读一遍,磨刀不误砍柴工。

这里记录的都是我自己的理解和观点,或者需要强调的知识点,并不代表书的详细内容,详细还是请参见原文。

纪要

  1. lua葡萄牙语里面表示美丽的月亮。
  2. 纯c编写,能被当作c库嵌入和调用,能方便和c/c++相互调用。
  3. 变量没有类型,可以动态绑定。
  4. 运行期能编译字符串形式的程序文本并载入虚拟机执行。(这个有点意思)
  5. nil 是一种类型,Lua 将 nil 用于表示“无效值”。Lua 中 nil 和 false 为“假”,其它所有值均为“真”。比如 0 和空字符串就是“真”;(惊讶)
  6. table:“关联数组” 是一种具有特殊索引方式的数组,索引通常是字符串(string)或者 number 类型,但也可以是除 nil 以外的任意类型的值。
  7. 与或是and or,结果不再是0或者1
  8. do return end 实现代码return的随意打桩
  9. 函数支持变长参数 ...
  10. 做函数参数时,table是传引用,其他类型都是传值
  11. 模块的全局变量检测用工具releng
  12. 字符串下标是从1开始的,跟物理位置次序一致
  13. openresety支持防止sql注入的方法
  14. 支持匿名对象 " _ ",用来占位,这个和golang一致
  15. 压力测试的好工具wrk
  16. 规则中尽量不要使用if
  17. 代码中不要使用阻塞操作,尽量不要使用lua的原生接口,使用openresty的相应接口
  18. 火焰图是个定位底层调用栈的好东西
  19. cosocket是好东西

openresty安装篇

环境版本

OS:CentOS Linux release 7.1.1503 (Core)
openresty:1.9.15.1

安装准备

除非你要修改源码,如果只是运行官方的包,官方建议优先考虑预编译包,centos 系统支持如下:

版本号 支持的体系结构
5.x x86_64, i386
6.x x86_64, i386
7.x x86_64

配置yum源

你可以在你的 CentOS 系统中添加 openresty 资源库,这样就可以方便的安装我们的包,以后也可以更新(通过 yum update 命令)。添加资源库,你只用创建一个名为 /etc/yum.repos.d/OpenResty.repo 的文件,内容如下:

[openresty]
name=Official OpenResty Repository
baseurl=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/epel-$releasever-$basearch/
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/pubkey.gpg
enabled=1
enabled_metadata=1

显示支持的包

sudo yum --disablerepo="*" --enablerepo="openresty" list available

Loaded plugins: fastestmirror
openresty                                         | 3.5 kB     00:00     
openresty/7/x86_64/primary_db                       |  32 kB   00:01     
Determining fastest mirrors
Available Packages
openresty.x86_64                         1.9.15.1-16.el7.centos openresty
openresty-debug.x86_64                   1.9.15.1-7.el7.centos  openresty
openresty-debug-debuginfo.x86_64         1.9.15.1-7.el7.centos  openresty
openresty-debuginfo.x86_64               1.9.15.1-16.el7.centos openresty
openresty-doc.noarch                     1.9.15.1-16.el7.centos openresty
openresty-openssl.x86_64                 1.0.2h-3.el7.centos    openresty
openresty-openssl-debug.x86_64           1.0.2h-4.el7.centos    openresty
openresty-openssl-debug-debuginfo.x86_64 1.0.2h-4.el7.centos    openresty
openresty-openssl-debug-devel.x86_64     1.0.2h-4.el7.centos    openresty
openresty-openssl-debuginfo.x86_64       1.0.2h-3.el7.centos    openresty
openresty-openssl-devel.x86_64           1.0.2h-3.el7.centos    openresty
openresty-resty.noarch                   1.9.15.1-16.el7.centos openresty
openresty-valgrind.x86_64                1.9.15.1-6.el7.centos  openresty
openresty-valgrind-debuginfo.x86_64      1.9.15.1-6.el7.centos  openresty
perl-Lemplate.noarch                     0.07-3.el7.centos      openresty
perl-Test-Nginx.noarch                   0.25-3.el7.centos      openresty

安装

关于openresty的rpm包的介绍见这里:http://openresty.org/cn/rpm-packages.html

按照文档的说明,我们暂时只需要安装openresty,openresty-resty,openresty-doc三个包就可以了

yum install openresty
yum install openresty-resty
yum install openresty-doc

运行

sudo /sbin/service openresty start

stop, restart, 和 reload 这些指令也是支持的。

默认网站实例是加载在/usr/local/openresty/nginx/ 目录下的,如果要改变成自定义的目录使用 -p 选项:

sudo openresty -p /opt/my-fancy-app/

这个命令实测,是需要手动创建目录的,记得要先停止openresty。

其他问题

防火墙

在centos7下面,防火墙由iptables变更为firewalld,测试时需要增加相应的80端口,或者暂时关闭防火墙。

配置firewalld 使用firewall-cmd,默认需要安装:

yum install firewalld firewalld-config

查看当前开放zone,端口,服务:

firewall-cmd --get-active-zones
firewall-cmd --zone=public --list-ports
firewall-cmd --zone=public --list-service

增加80端口:

firewall-cmd --zone=public --add-port=80/tcp

自启动

添加openresty的开机自启动:

chkconfig --add openresty
chkconfig openresty on

由于centos已经用systemD代替了systemV,系统不再有rc-local服务了,所以我们也不能简单添加rc.local了(网上流传的给增加运行权限的,在本机验证不成功)。标准的做法就是创建新的任务,通过chkconfig来启动了。

因为firewallD的规则是不能保存的,所以我们要放到开机自启动脚本中。

libreswan libevent错误

安装libreswan时遇到如下的错误:

/data/l2tp/l2tp/libreswan-3.17/programs/pluto/state.c:800: undefined reference to event_free'
server.o: In function
init_event_base':
/data/l2tp/l2tp/libreswan-3.17/programs/pluto/server.c:582: undefined reference to evthread_make_base_notifiable'
server.o: In function
pluto_event_new':
/data/l2tp/l2tp/libreswan-3.17/programs/pluto/server.c:442: undefined reference to event_new'
server.o: In function
pluto_event_free':
/data/l2tp/l2tp/libreswan-3.17/programs/pluto/server.c:588: undefined reference to event_free'
/data/l2tp/l2tp/libreswan-3.17/programs/pluto/server.c:589: undefined reference to
event_free'
/data/l2tp/l2tp/libreswan-3.17/programs/pluto/server.c:590: undefined reference to event_free'
/data/l2tp/l2tp/libreswan-3.17/programs/pluto/server.c:591: undefined reference to
event_free'
timer.o: In function delete_pluto_event':
/data/l2tp/l2tp/libreswan-3.17/programs/pluto/timer.c:814: undefined reference to
event_free'
ikev2_parent.o:/data/l2tp/l2tp/libreswan-3.17/programs/pluto/ikev2_parent.c:2704: more undefined references to event_free' follow
/usr/local/lib/libevent_pthreads.so: undefined reference to
evthread_set_condition_callbacks'
/usr/local/lib/libevent_pthreads.so: undefined reference to event_mm_malloc_'
/usr/local/lib/libevent_pthreads.so: undefined reference to
event_mm_free_'
/usr/local/lib/libevent_pthreads.so: undefined reference to evthread_set_id_callback'
/usr/local/lib/libevent_pthreads.so: undefined reference to
evthread_set_lock_callbacks'
collect2: ld returned 1 exit status
make[3]: *** [pluto] Error 1
make[3]: Leaving directory /data/l2tp/l2tp/libreswan-3.17/OBJ.linux.x86_64/programs/pluto'
make[2]: *** [local-base] Error 2
make[2]: Leaving directory
/data/l2tp/l2tp/libreswan-3.17/programs/pluto'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/data/l2tp/l2tp/libreswan-3.17/programs'
make: *** [all] Error 2
libreswan-3.17 install failed.

问题分析:
1. 检查libreswan的版本和代码包的正确性,去官网下载比对,确认下载是最新的代码。
2. 查看日志,根据event_free关键词,判断出问题的应该是libevent库,所以确认libevent,发现已经按照说明成功下载了libevent2了。
3. 继续查找日志细节:
---> Package libevent2.x86_64 0:2.0.21-2.el6 will be installed
--> Processing Conflict: libevent2-devel-2.0.21-2.el6.x86_64 conflicts libevent-devel
--> Finished Dependency Resolution
Error: libevent2-devel conflicts with libevent-devel-1.4.13-4.el6.x8664
从上面的提示看到是libevent2跟系统默认自带的libevent冲突了

解决:
yum remove libevent-devel-1.4.13-4.el6.x86_64

yum install libevent2-devel

strongswan charon logging 配置

系统:ubuntu 14.04

strongswan 配置文件路径 /usr/local/etc/

默认的strongwan的日志是打印在syslog 里面的。为了便于管理和分析,我们希望日志能打印在专门的文件里。而strongswan 自带的charon守护服务就默认包含了charon-logging功能,我们只要开启此功能即可。

相关的配置参考如下:
https://wiki.strongswan.org/projects/strongswan/wiki/LoggerConfiguration