苹果相关

浏览模式: 标准 | 列表 | 图文
jq的简单用法

jq的简单用法

jq是linux命令行下读取和解析JSON的好工具。只是好象不能jq xxx.json这样的用法,但没事,可以通过管道符,cat xxx.json|jq 就OK了

在这里:https://www.tuicool.com/articles/vieMN3Q有详细的教程,写的非常完整,但如果简单的使用,并不需要完整的看完,只要记得几个用法就行

来个简单的数据:{"code":1,"msg":"ok","data":{"fields":["a","b","c"],"items":[{1,2,3},{11,22,33}],"other":[{"x":1,"y":1},{"x":2,"y":2}]}}

1、获取items节点: cat xxx.json|jq ".data.items"

2、获取items下第二条数据的第二个,即22. cat xxx.json|jq ".data.items[1][1]"

3、获取other下的所有x节点: cat xxx.json|jq ".data.other[].x"

是不是很方便?如果要自定义格式输出,还可以这样

1、将所有x节点用{"items":[]}格式输出: cat xxx.json| jq "{items: [ .data.other[].x ]}" ,

如果要看更多的用法,还是上面的网址里更详细一点。我这只是简单的用一下。。或者说是临时在服务器上测试数据,让自己看起来会比较方便一点。还有一个原因是我在服务器上用这个的最大理由。有时候JSON拿到的时候中文都是转义过的。用jq,可以直接看中文。这点比较爽

-开头的文件在linux系统下无法直接删除

-开头的文件在linux系统下无法直接删除

如题。如果文件是"-test.log",是的你没看错。文件名前面有一个减号。如果你直接使用:rm -test.log,会报如下错误:

rm: invalid option -- 't'
Try 'rm ./-test.log' to remove the file ‘-test.log’.
Try 'rm --help' for more information.

毕竟。- 是有特殊意义的。那怎么删除呢?也简单:

rm -- -test.log

文件就这样被删除了。事实上,象这种"-"(减号、负号)开头的文件。因为它自带的特殊意义(linux下命令行的参数前缀),所以你用touch\vim等命令,其实都无法创建这样的文件。不信你试试"touch -test.log"。当然,你也是可以用touch -- -test.log来创建(其他类似)

vsc 跳板机 设置

vsc 跳板机 设置

比较简单的设置,就是利用 sshconfig 。

3、如果服务器需要通过跳板机登录(跳板机需要走本地网络代理)

首先配置跳板机ssh

Host jumper
HostName yyy.yyy.yyy.yyy # 跳板机IP,跳板机~/.ssh/authorized_keys需要配置ssh公钥
User root
ForwardAgent yes
IdentityFile /Users/aslinwang/.ssh/id_ecdsa
ProxyCommand corkscrew 127.0.0.1 12679 %h %p
然后通过跳板机访问服务器

Host aslin
HostName xxx.xxx.xxx.xxx # 远程服务器IP,~/.ssh/authorized_keys需要配置ssh公钥
User root
ForwardAgent yes
IdentityFile /Users/aslinwang/.ssh/id_ecdsa
ProxyCommand ssh jumper -W %h:%p 2> /dev/null
如果你不用 公钥,那可以尝试用sshpass (即,输密码式的登录):
Host aslin
HostName xxx.xxx.xxx.xxx # 远程服务器IP,~/.ssh/authorized_keys需要配置ssh公钥
User root
ForwardAgent yes
IdentityFile /Users/aslinwang/.ssh/id_ecdsa
ProxyCommand sshpass -p [跳板机密码] ssh -p [跳板机端口] root@[跳板机IP] -W %h:%p 2> /dev/null
------EOF----
文中的aslinwang是上述网址文章中的用户,如果是你自己的,就是/Users/用户名/,相信能找到这里的人应该都明白
我可能错怪layerstack了

我可能错怪layerstack了

上一篇博客说了。我用vsc的ssh-remote的时候,30秒或者1分钟必断。错误信息一直就类似:

[04:30:38.608] "install" terminal command done
[04:30:38.609] Install terminal quit with output:
[04:31:18.258] SSH Resolver called for "ssh-remote+neatstudio.com", attempt 2
[04:31:18.258] SSH Resolver called for host: neatstudio.com
[04:31:18.259] Setting up SSH remote "neatstudio.com"
[04:31:18.259] Using commit id "f06011ac164ae4dc8e753a3fe7f9549844d15e35" and quality "stable" for server
[04:31:18.263] Running script with connection command: ssh -o ClearAllForwardings=true -o ConnectTimeout=15 neatstudio.com bash
[04:31:18.263] Install and start server if needed
[04:31:35.269] Connecting with SSH timed out
[04:31:35.269] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"Timeout"},"measures":{"resolveAttempts":2,"retries":1}}
[04:31:35.269] ------

重连后也是

[04:37:06.477] SSH Resolver called for "ssh-remote+neatstudio.com", attempt 12
[04:37:06.477] SSH Resolver called for host: neatstudio.com
[04:37:06.477] Setting up SSH remote "neatstudio.com"
[04:37:06.478] Using commit id "f06011ac164ae4dc8e753a3fe7f9549844d15e35" and quality "stable" for server
[04:37:06.479] Running script with connection command: ssh -o ClearAllForwardings=true -o ConnectTimeout=15 neatstudio.com bash
[04:37:06.480] Install and start server if needed
[04:37:21.515] > ssh: connect to host 123.176.103.247 port 22: Operation timed out
[04:37:21.515] Got some output, clearing connection timeout
[04:37:21.776] "install" terminal command done
[04:37:21.776] Install terminal quit with output: ssh: connect to host 123.176.103.247 port 22: Operation timed out
[04:37:21.776] Received install output: ssh: connect to host 123.176.103.247 port 22: Operation timed out
[04:37:21.777] The operation timed out
[04:37:21.777] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"OfflineError"},"measures":{"resolveAttempts":12,"retries":1}}
[04:37:21.777] ------

发了ticket给layerstack。他们测试也来没有这个问题。我开始以为是什么openfiles limit的问题。也打开到最大了。

期间调整了一下这个:echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p,因为开始有报inotify max error

直到他们给我发了一个ticket:

Thank you for your patience in this matter.

We have investigated the issue in detail and we are not able to recreate the issue from our end. We have checked the same from multiple locations and find out its working fine.

The reported issue seems to be related to your local ISP, so we suggest you to change the standard port (22) of SSH to some other non standard port like 2222 or 2244, in server and recheck the issue.

Please do have a check on our above suggestion and let us know if you still face any issues in accessing.

所以我就想了一下,直接把PORT改成了2222,2223,2244,然而仍然 失败,最后我用了一个超大端口,居然正常了

ssldocker还是不稳定

ssldocker还是不稳定

如题。本来想切caddy的。caddy已经更新。但因为我用的是lightsail,结果又不能自动更新。而当前域名,我切到了aws 的lightsail。因为lightsail属于aws旗下,必须得由IAM等管理工具来配权限,然而lightsail却只有action没有policy。不知道怎么配了

但奇怪的是,ssldocker却可以申请证书。caddy一直报没有权限(caddy我还配置了aws_app_key.....反而不行,而ssldocker啥也不要)

再坚持几天。如果ssldocker继续 不稳定(systemd 重启失败多次),还是恢复成nginx + acme.sh (或者certbot)。。或者。。。实在不行,切回dnspod!!!NND

服务器迁移,采用ssldocker+apache2

服务器迁移,采用ssldocker+apache2

其实ssldocker的效率并不高,而且网上几乎没有啥文档

缺点:
1、不支持泛域名,比如我neatstudio.com和www.neatstudio.com,我得配两条记录
2、只能反向代理 ,不支持直接象nginx那样配一个php-fpm之类的
优点
1、http2https,自带
2、域名随意自动签,不需要其他软件
其实我本来是想用caddy的。但社区型软件就有一个很大的问题,比如这个域名ssl,到现在都不正常。应该是模块的版本号的问题。也懒得重新编译了(虽然 说性能比ssldocker好,但既然我要动手,那就先算了)
ssldocker就一个文件:ssldocker -c conf.json就完事了。
之前一直用supervisor,这回用systemd,好象也就两行代码的事情。不然我还得 ssldocker -c conf.json & 。现在两行代码解决
忍忍,先用着吧
vagrant up报错:Error on Vagrant Up related to Guest Permissions

vagrant up报错:Error on Vagrant Up related to Guest Permissions

尝试使用laravel的时候,看到有推荐且指定要用Homestead,其实我一直用MAMP,看博客的人都知道。用了N年了。但从更早的博客看的话,应该是会发现我是用虚拟机+NFS来进行代码和虚拟域名管理的。

那时候只要装一个hosts管理软件,然后指定127.0.0.1 为host,同时将虚拟机的端口映射出来就行了。所有的apache/nginx配置都在虚拟机里完成。好处当然有,在那个没有vagrant的年代,vmware+虚拟机文件,团队里就有统一的开发环境了,这时候不用担心他们用windows还是用mac又或者用linux。环境统统一样。

现在homestead,其实也是做了同样的事情。各种东西帮你装好(嗯,以前装虚拟机还要自己折腾)

之前弄好的时候,vagrant ssh都可以直接免密登录的(毕竟读Homestead.yaml,其实是Homestead下有一个Vagrantfile,里面的脚本让他可以读到Homestead.yaml)。

刚才修改了一下Homestead.yaml,结果登录的时候就需要输入密码了,密码当然没啥问题,不就是vagrant么。但为什么呢?报错信息是:Guest-specific operations were attempted on a machine that is not ready for guest communication. This should not happen and a bug should be reported.网上查了查,很多人出现过这个情况:有人说,删了~/.vagrant.d目录就行了。但我不行啊。这个目录下有6G,而且我下的box是支持parallels desktop的。如果重下,代价太大了。(网速太慢)

我尝试vagrant halt再vagrant up,发现一个问题,提示我有一个port从8025没法映射到mac 的8025,而改成2200了。我想了想,好象我在mac安装了mailhog,难道是因为这个原因?于是我brew services stop mailhog,再vagrant up,果然 没有报错

再回到之前的google搜索,在这里:https://github.com/hashicorp/vagrant/issues/8499,有个人也有提出:

The fix for this issue was released in the plugin. The root cause is due to the network reset after applying port forwards. It causes DHCP configured devices to drop their address and re-acquire a new lease which leads to the "Guest-specific operations..." error. The fix adds a pause after applying the forwards before continuing. If you find that the pause is not long enough, it can be configured using a provider configuration option: https://www.vagrantup.com/docs/vmware/configuration.html#port_forward_network_pause

Cheers!

---EOF---

好了,问题解决。安心 睡觉

vagrant使用parallels desktop

vagrant使用parallels desktop

使用laravel的人,好象一直都推荐使用homestead,所以我也就尝试了一下。由于默认的vagrant都是用的virtual box,而我一直是嫌弃他繁,而且几年前耗的资源让我心有余悸,再加上我本地本来就有Parallels Desktop,所以我就找找资料,看看能不能使用parallels。

结果是出人意料的好,官方也支持,只是需要安装个插件,戳这里看一下:https://parallels.github.io/vagrant-parallels/docs/getting-started.html,几行命令行可:vagrant plugin install vagrant-parallels,

然后就是初始化了,vagrant init laravel/homestead,这时候会跳出个选择,就象这样:

==> box: Loading metadata for box 'laravel/homestead'
box: URL: https://vagrantcloud.com/laravel/homestead
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) hyperv
2) parallels
3) virtualbox
4) vmware_desktop

Enter your choice: 2
==> box: Adding box 'laravel/homestead' (v8.0.0) for provider: parallels

选择2 就行了。然后就会开始下载。由于下载地址在github上面,然后实际 是在aws的S3上,痛苦的事情就这样来了。。。不爬梯子动也不动。番了墙也只有400多K,所幸,1个多小时就下载下来了。

然后vagrant up --provider=parallels,这样就好了

vagrant up --provider=parallels
/opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/util/which.rb:37: warning: Insecure world writable dir /server in PATH, mode 040777
Bringing machine 'default' up with 'parallels' provider...
==> default: Registering VM image from the base box 'laravel/homestead'...
==> default: Creating new virtual machine as a linked clone of the box image...
==> default: Unregistering the box VM image...
==> default: Setting the default configuration for VM...
==> default: Checking if box 'laravel/homestead' version '8.0.0' is up to date...
==> default: Setting the name of the VM: blessappyzhancom_default_1563640904299_97304
==> default: Preparing network interfaces based on configuration...
default: Adapter 0: shared
==> default: Clearing any previously set network interfaces...
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 10.211.55.9:22
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection refused. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for Parallels Tools installed on the VM...
==> default: Parallels Tools installed on this VM are outdated! In most cases
==> default: this is fine but in rare cases it can cause things such as shared
==> default: folders to not work properly. If you see shared folder errors,
==> default: please update Parallels Tools within the virtual machine and
==> default: reload your VM.
==> default: Installing the proper version of Parallels Tools. This may take a few minutes...
==> default: Parallels Tools have been installed. Rebooting the VM...
==> default: Attempting graceful shutdown of VM...
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
==> default: Machine booted and ready!
==> default: Mounting shared folders...
default: /vagrant => /server/wwwroot/yzhan/test.com

运行一下vagrant ssh ,顺利登录,而且看到 当前项目目录下有一个 .vagrant的目录,里面都是一些配置文件等。

到此,安装结束,看了下进程,占CPU0.x,内存400多M。ssh进去后php-fpm的进程超级多。从5.6~7.3的都有。安心的用了

apache记录nginx proxy后的 真实IP

apache记录nginx proxy后的 真实IP

1、 nginx的proxy_pass要加载默认的 proxy_params,里面配置了怎么传递 真实IP

2、apache默认的combine的logformat默认没有取有代理 情况下的IP,所以需要加一个:
LogFormat "\"%{x-forwarded-for}i\" %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined2
然后CustomLog的时候就是使用 combined2,例如: CustomLog ${APACHE_LOG_DIR}/www.neatstudio.com.access.log combined2
上面那个logformat如果要全局使用,就放到apache.conf里。如果只是当前项目使用,则可以放到当前的hosts文件中
---EOF---
其实没啥,就是做个记录。老是会忘
inotify的相关文章和资料

inotify的相关文章和资料

应该不会消失的链接:

1、https://infoq.cn/article/inotify-linux-file-system-event-monitoring

2、http://ju.outofmemory.cn/entry/264098

3、http://icodeit.org/2015/03/build-monitor-script-based-on-inotify/ ,他有提到mac用fswatch

4、http://ju.outofmemory.cn/entry/278544 有一个现成的同步脚本

其实我5年前有写过一个inotifywait + php 的脚本,主要是用来检测哪些文件被人修改了,用做防篡改。可能最近会重新用上,温故一下旧知识点