西维蜀黍

【Linux】Shell 和 Shell 脚本的执行

fork - 创建子 shell 进程

父子 shell 进程是相对而言的,它描述了两个 shell 进程的fork关系。

以bash为例,当在bash shell中执行一个命令时,其实是在当前 bash shell 进程中 fork 出一个子 bash shell 进程,然后在这个子进程中运行相应的命令,当命令执行完成后,这个子进程就被end了。

简单来说,父Shell进程创建子Shell进程时,调用的是 fork() 函数。

在这种情况中:

  • 子 shell 进程会继承父 shell 进程中设置的环境变量
  • 但是子 shell 进程中设置的环境变量并不会带回父 shell 进程(即不会影响父 shell 进程),以下为证明:
$ export SW="aaa"
$ echo $SW
aaa
$ bash
$ echo $SW
aaa
$ export SW2="bbb"
$ echo $SW2
bbb
$ exit
exit
$ echo $SW2
  ...


【Linux】Shell 和 Bash

Unix shell

Unix shell,一种壳层与命令行界面,是UNIX操作系统下传统的用户和计算机的交互界面。第一个用户直接输入命令来执行各种各样的任务。

普通意义上的shell就是可以接受用户输入命令的程序。它之所以被称作shell是因为它隐藏了操作系统低层的细节。同样的Unix下的图形用户界面GNOME和KDE,有时也被叫做“虚拟shell”或“图形shell”。

  ...


【Linux】bash 和 zsh 的启动脚本(.zshrc,.bash_profile,~/.profile 等区别)

结论

zsh

当默认 shell 为 zsh 时,且当开启一个新 tab 时(或者一台主机通过 SSH 登录本主机时),/etc/zprofile/etc/zshrc~/.zshrc 均会被执行 ,且执行顺序为:

  • /etc/zprofile
  • /etc/zshrc
  • ~/.zshrc

当开启一个新 tab 时,

Last login: Sat Jun 13 11:46:23 on ttys006
execute /etc/zprofile
execute /etc/zshrc
execute ~/.zshrc

当一台主机通过 SSH 登录本主机时

$ ssh wei.shi@192.168.16.173
Last login: Sat Jun 13 11:54:43 2020
execute /etc/zprofile
execute /etc/zshrc
execute ~/.zshrc
~ $

当启用一个新zsh 进程时

$ zsh
execute /etc/zshrc
execute ~/.zshrc
$
  ...


【Golang】go-redis Redis 连接库学习

  ...


【Redis】Wireshark 分析 Redis 通讯

Background

Redis client与Redis server在默认情况下的通讯,是不加密的。而且他们之间的通讯基于TCP。

因此,我们可以通过Wireshark来获取它们之间的通讯内容。

Redis server: 192.168.184:6379

Redis client: 192.168.31.169

  ...


【Docker】Docker Compose

Install

Run this command to download the current stable release of Docker Compose:

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply executable permissions to the binary:

$ sudo chmod +x /usr/local/bin/docker-compose

Set a soft link

$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Test the installation.

$ docker-compose --version
  ...


【macOS】brew 使用

Homebrew

Homebrew是一个包管理器,用于安装Apple没有预装但你需要的UNIX工具。(比如著名的wget)。

Homebrew会将软件包安装到独立目录(/usr/local/Cellar),并将其文件软链接至/usr/local

Installation

安装Homebrew。将以下命令粘贴至终端

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

脚本会在执行前暂停,并说明将它将做什么。

  ...


【Docker】Container 常用命令

Docker 启动

Docker 是服务器—-客户端架构。命令行运行docker命令的时候,需要本机有 Docker 服务。如果这项服务没有启动,可以用下面的命令启动:

# service 命令的用法
$ sudo service docker start

# systemctl 命令的用法
$ sudo systemctl start docker
  ...


【Redis】Codis

Codis

Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有显著区别 (不支持的命令列表), 上层应用可以像使用单机的 Redis 一样使用, Codis 内部(其实是Codis Proxy)会处理请求的转发(转发到Codis Server), 不停机的数据迁移等工作, 所有后边的一切事情, 对于前面的客户端来说是透明的, 可以简单的认为后边连接的是一个内存无限大的 Redis 服务。

Architecture

  ...


【Redis】Redis pipeline

Background

Redis is a TCP server using the client-server model and what is called a Request/Response protocol.

This means that usually a request is accomplished with the following steps:

  • The client sends a query to the server, and reads from the socket, usually in a blocking way, for the server response.
  • The server processes the command and sends the response back to the client.

So for instance a four commands sequence is something like this:

  • Client: INCR X
  • Server: 1
  • Client: INCR X
  • Server: 2
  • Client: INCR X
  • Server: 3
  • Client: INCR X
  • Server: 4

Clients and Servers are connected via a networking link. Such a link can be very fast (a loopback interface) or very slow (a connection established over the Internet with many hops between the two hosts). Whatever the network latency is, there is a time for the packets to travel from the client to the server, and back from the server to the client to carry the reply.

This time is called RTT (Round Trip Time). It is very easy to see how this can affect the performances when a client needs to perform many requests in a row (for instance adding many elements to the same list, or populating a database with many keys). For instance if the RTT time is 250 milliseconds (in the case of a very slow link over the Internet), even if the server is able to process 100k requests per second, we’ll be able to process at max four requests per second.

If the interface used is a loopback interface, the RTT is much shorter (for instance my host reports 0,044 milliseconds pinging 127.0.0.1), but it is still a lot if you need to perform many writes in a row.

Fortunately there is a way to improve this use case.

  ...