#135 Linux 分区方案(Partition Scheme)

2016-05-14

安装 Ubuntu 16.04 时选择的分区方案。

挂载点 大小 意义
/ 50GB 根目录
/boot 10GB 启动目录
/home 150GB 用户主目录
/usr 100GB 程序分区
/var 50GB 变量文件目录
/tmp 50GB 临时文件目录
SWAP 20GB 交换分区

#133 yum 包管理系统

2016-05-02

关于 DNF 的更多信息,参考:2016/05/03 CentOS DNF

介绍

  1. .rpm 包,和 .deb 包是 Linux 生态中两种最主要的包格式。
  2. yum:
  3. 较新版本提供了 dnf 工具,改善 yum

包名

bash-4.2.46-35.el7_9.x86_64.rpm

其中:

  • bash 是名称
  • 4.2.46 是版本
  • 35.el7_9 是构建版本
  • x86_64 是服务器架构
  • rpm 是文件后缀
名称    :bash
架构    :x86_64
版本    :4.2.46
发布    :31.el7
大小    :3.5 M
源    :installed
来自源:anaconda
简介    : The GNU Bourne Again shell
网址    :http://www.gnu.org/software/bash
协议    : GPLv3+
描述    : The GNU Bourne Again shell (Bash) is a shell or command language
         : interpreter that is compatible with the Bourne shell (sh). Bash
         : incorporates useful features from the Korn shell (ksh) and the C shell
         : (csh). Most sh scripts can be run by bash without modification.

基本用法

yum help list # 查看帮助

yum search <package> # 搜索包

yum list
yum list installed
rpm -qa
yum list --upgradable

yum info <package>
rpm -qi <package>

rpm -ql <package> # 已安装包的文件列表
rpm -qd <package> # 已安装包的文件列表中的文档部分
rpm -qc <package> # 已安装包的文件列表中的配置部分

yum repolist

# repoquery 是 yum-utils 包提供的命令
repoquery -l <package> # 文件列表
repoquery -f <filepath> # 查看文件属于哪个包, 比如: `repoquery -f "*/repoquery"`
repoquery --location <package> # 查看包的下载地址

yum deplist <package> # 依赖
rpm -qR <package> # 已安装包的依赖
rpm -q --whatrequires <package> # 反向依赖
rpm -q --whatprovides <filepath>
rpm -qf <filepath>

yum provides <pattern>
yum whatprovides <patter>

yum check-update
yum updateinfo
yum update [package]
yum upgrade [package]
yum update-minimal
yum upgrade-minimal # 和 yum update-minimal 相同
yum downgrade <package>

yum install <package>
yum install <package-rpm-filepath>
yum reinstall

yum makecache
yum clean

yum erase
yum remove
yum autoremove

# list, info, summary, repeat, redo, undo, new, rollback, addon, addon-info, stats, statistics, sync, synchronizepkg, pkgs, pkg-list, pkgs-list, package, package-list, packages, packages-list, pkg-info, pkgs-info, package-info, packages-info
yum history
yum history list
yum history list all

yum versionlock <package>

安装组

RedHat 系列提供的,安装组(Group)的概念非常好。

安装组就是为了某一个目的需要的一组包,比如 gnome-desktop 组是安装一个完整的 gnome 桌面环境,web-server 组是安装 apache 和相关的几个包。

  1. 安装组中有必须安装的包(Mandatory Packages),默认安装的包(Default Packages),也有可选的包(Optional Packages)。
  2. 按我的理解,安装组分成三类:
  3. 可用组 Available Group,就是普通的安装组,包含部分包,可以 install。
  4. 环境组 Environment Group,就是安装组的组,group of goups,比如 minimal 环境组包含必须的 core 组和可选的 debugging 组。也可以 install。
  5. 基础组,比如 core,比如 php,是隐藏的,不可直接 install,用于构建环境组设计的。
    我实在想不到为什么这些组不直接暴露出来,这个设计有什么别的原因。
$ yum help groups
groups [list|info|summary|install|upgrade|remove|mark] [GROUP]

显示或使用、组信息

别名:group, grouplist, groupinfo, groupinstall, groupupdate, groupremove, grouperase
  • yum grouplist
  • yum group list ids 附带组 ID
  • yum group list hidden 列出所有组
  • yum groupinfo
  • yum groupinstall <group>
  • yum install @<group>
  • yum install @^<environment-group>
  • yum --setopt=group_package_types=mandatory,default,optional groupinstall "Web Server"
  • yum groupupdate
  • yum groupremove
  • yum grouperase

相关文件

  • /etc/yum.conf
  • /etc/yum.repos.d/
  • /etc/yum/

/etc/rpm 目录不知道是干什么的。

yum 插件

比如最常见的 fastestmirror,用于自动选择最快的镜像源。所以我们使用 CentOS 时,一般不需要去配置镜像源。

#131 Nginx sticky 指令

2016-04-10

Nginx 商用版 1.5.7 (2013 年) 开始支持 sticky 指令。

文档: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky

Syntax:  sticky cookie name [expires=time] [domain=domain] [httponly] [samesite=strict|lax|none] [secure] [path=path];
         sticky route $variable ...;
         sticky learn create=$variable lookup=$variable zone=name:size [timeout=time] [header] [sync];
Default: —
Context: upstream

开源版有 nginx-sticky-module。

C 语言写的,BSD 协议。
代码看起来并不复杂,如果需要用到的时候,可以进行一个粗略的 Review。

编译

# 下载 nginx 源码 (2016-04-26)
wget http://nginx.org/download/nginx-1.10.0.tar.gz http://nginx.org/download/nginx-1.10.0.tar.gz.asc
gpg --verify nginx-1.10.0.tar.gz.asc

# 下载 nginx-sticky-module (2015-08-06)
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/1.2.6.zip

unzip 1.2.6.zip
cd nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d/

unzip nginx-1.10.0.zip
cd nginx-1.10.0/

# 其他参数按需添加
./configure --add-module=../nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d/
make && make install

# Configuration summary
#   + using system PCRE library
#   + OpenSSL library is not used
#   + md5: using system crypto library
#   + sha1: using system crypto library
#   + using system zlib library

#   nginx path prefix: "/usr/local/nginx"
#   nginx binary file: "/usr/local/nginx/sbin/nginx"
#   nginx modules path: "/usr/local/nginx/modules"
#   nginx configuration prefix: "/usr/local/nginx/conf"
#   nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
#   nginx pid file: "/usr/local/nginx/logs/nginx.pid"
#   nginx error log file: "/usr/local/nginx/logs/error.log"
#   nginx http access log file: "/usr/local/nginx/logs/access.log"
#   nginx http client request body temporary files: "client_body_temp"
#   nginx http proxy temporary files: "proxy_temp"
#   nginx http fastcgi temporary files: "fastcgi_temp"
#   nginx http uwsgi temporary files: "uwsgi_temp"
#   nginx http scgi temporary files: "scgi_temp"

用法

upstream {
  sticky;
  server 127.0.0.1:9000;
  server 127.0.0.1:9001;
  server 127.0.0.1:9002;
}

sticky [name=route] [domain=.foo.bar] [path=/] [expires=1h]
       [hash=index|md5|sha1] [no_fallback] [secure] [httponly];

#130 血型知识

2016-03-31

ABO 血型系统是根据血小板上的两种抗原——A 抗原和 B 抗原——来区分的:

  • A 型血 :仅携带有 A 抗原
  • B 型血 :仅携带有 B 抗原
  • AB 型血 :同时携带 A 抗原和 B 抗原
  • O 型血 :两种抗原都没有

A 型血的人会消灭 B 抗原,所以不能输 B 型血和 AB 型血,只能输 A 型血和 O 型血;
同理,B 型血的人会消灭 A 抗原,所以不能输 A 型血和 AB 型血,只能输 B 型血和 O 型血;
AB 型血的人自己就两种抗原都有,当然都不消灭,所有血型的血都可以;
相反,O 型血的人两种抗原都没有,哪种都不可接受,所以只能使用 O 型血。

遗传规律表

No 父/母 父/母 子女 子女 子女 子女
1 O O O - - -
2 O A O A - -
3 O B O - B -
4 O AB - A B -
5 A A O A - -
6 A B O A B AB
7 A AB - A B AB
8 B B O - B -
9 B AB - A B AB
10 AB AB - A B AB
  1. 一共 10 种组合:

  2. 生 O 型血子女的组合有 6 种

  3. 生 A 型血子女的组合有 7 种
  4. 生 B 型血子女的组合有 7 种
  5. 生 AB 型血子女的组合有 4 种

  6. AB 型血父母不能生 O 型血子女

  7. O 型血父母不能生 AB 型血子女

#129 转载:“牛”是怎么死的?

2016-03-17

牛耕田回来,躺在栏里,疲惫不堪地喘着粗气,狗跑过来看它。
“唉,老朋友,我实在太累了。”牛诉着苦,“明儿个我真想歇一天。”
狗告别后,在墙角遇到了猫。狗说:“伙计,我刚才去看了牛,这位大哥实在太累了,它说它想歇一天。也难怪,主人给它的活儿太多太重了。”
猫转身对羊说:“牛抱怨主人给它的活儿太多太重,它想歇一天,明天不干活儿了。”

#128 华人与华侨

2016-03-16

每次春晚都必然问候海外华人华侨,但我从来没有思考过华人和华侨有什么区别,近日看到网络上的一些资料才弄明白。

#127 删除文件属性

2016-03-15
# 时间清零
touch -amt 197001010000.00 <file>

sudo apt install -y xattr
xattr -l <file>
# 删除所有附加属性
xattr -c <file>

#126 SQL 的历史

2016-03-14

历史

  1. 70 年代初,IBM 公司开发了 SEQUEL 语言 (Structured English Query Language,结构化英语查询语言),用于管理 RDB。
  2. 70 年代末,IBM 和甲骨文分别开始开发基于 SQL 的 RDBMS。
    PS: IBM 的产品就包括大名鼎鼎的 DB2,世界上最早的 SQL 数据库。
    PS: 甲骨文当时还叫做 Relational Software, Inc
  3. 1980 年,由于商标问题,SEQUEL 改名 SQL。
    虽然官方发音是 ess-cue-el, 但至今为止,不少人还是将其读做 /ˈsiːkwəl/
  4. 1986 年被美国国家标准学会标准化(ANSI X3.135-1986)
  5. 1987 年,ISO 采纳 ANSI SQL (ISO 9075:1987),所以这个版本也被称之为 SQL87。
  6. 后来,SQL 陆续推出 89,92,1999, 2003 .... 多个版本。
    应该是 ISO 负责制定和维护吧,也无所谓啦。

版本

SQL-86 (or SQL-87) is the ISO 9075:1987 standard of 1987
SQL-89 is the ISO/IEC 9075:1989 standard of 1989
SQL-92 is the ISO/IEC 9075:1992 standard of 1992
SQL:1999 is the ISO/IEC 9075:1999 standard of 1999
SQL:2003 is the ISO/IEC 9075:2003 standard of 2003
SQL:2006 is the ISO/IEC 9075:2006 standard of 2006
SQL:2008 is the ISO/IEC 9075:2008 standard of 2008
SQL:2011 is the ISO/IEC 9075:2011 standard of 2011
SQL:2016 is the ISO/IEC 9075:2016 standard of 2016

Year Name Alias Comments
1986 SQL-86 SQL-87 First formalized by ANSI
1989 SQL-89 Minor revision that added integrity constraints
1992 SQL-92 SQL2 Major revision (ISO 9075)
1999 SQL:1999 SQL3
2003 SQL:2003
2006 SQL:2006
2008 SQL:2008
2011 SQL:2011
2016 SQL:2016
2019 SQL:2019

SQL:1999
Added regular expression matching, recursive queries (e.g. transitive closure), triggers, support for procedural and control-of-flow statements, nonscalar types (arrays), and some object-oriented features (e.g. structured types), support for embedding SQL in Java (SQL/OLB) and vice versa (SQL/JRT)

2003

Introduced XML-related features (SQL/XML), window functions, standardized sequences, and columns with autogenerated values (including identity columns)

2006
ISO/IEC 9075-14:2006 defines ways that SQL can be used with XML. It defines ways of importing and storing XML data in an SQL database, manipulating it within the database, and publishing both XML and conventional SQL-data in XML form. In addition, it lets applications integrate queries into their SQL code with XQuery, the XML Query Language published by the World Wide Web Consortium (W3C), to concurrently access ordinary SQL-data and XML documents.

2008
Legalizes ORDER BY outside cursor definitions. Adds INSTEAD OF triggers, TRUNCATE statement,[34] FETCH clause

2011
Adds temporal data (PERIOD FOR)[35] (more information at: Temporal database#History). Enhancements for window functions and FETCH clause.

2016
Adds row pattern matching, polymorphic table functions, JSON

2019
Adds Part 15, multidimensional arrays (MDarray type and operators)

https://en.wikibooks.org/wiki/Structured_Query_Language
https://en.wikibooks.org/wiki/MySQL
https://en.wikibooks.org/wiki/PostgreSQL
https://en.wikibooks.org/wiki/SQLite
https://en.wikipedia.org/wiki/SQL_reserved_words

ISO 9075

最新的 SQL 标准一共分成 9 个部分(Part 5,6,7,8,12 可能是被废弃了):

  1. Part 1: Framework (SQL/Framework)
    基本概念
  2. Part 2: Foundation (SQL/Foundation)
    基础语法
  3. Part 3: Call-Level Interface (SQL/CLI)
    应该是编程语言方面的接口
  4. Part 4: Persistent stored modules (SQL/PSM)
    SQL 面向过程编程
  5. Part 9: Management of External Data (SQL/MED)
  6. Part 10: Object language bindings (SQL/OLB)
    Java SQLJ 相关内容
  7. Part 11: Information and definition schemas (SQL/Schemata)
  8. Part 13: SQL Routines and types using the Java TM programming language (SQL/JRT)
    又是 Java 相关
  9. Part 14: XML-Related Specifications (SQL/XML)
    XML 相关

PS: 前缀 ISO/IEC 9075-<n>:2016 – Information technology – Database languages – SQL – 省略。

PS: 还有一个拓展标准:ISO/IEC 13249 SQL Multimedia and Application Packages

变种

多数数据库没有严格按照标准来实现,导致不通平台上的 SQL 语句是不能跨平台的。

以下是两种主要的 SQL 方言:

  • T-SQL(Transact-SQL): SQLServer
  • PL/SQL: Oracle