docker笔记(5)—— Volume

Docker image是一系列的read-only layer。当启动container以后,在read-only layer之上会增加一个read-write layer。当需要对文件进行修改时,就要把数据从read-only layer拷贝到read-write layer。因此,image的数据不会被破坏,container相当于操作的是image数据的副本。这种read-only layerread-write layer的结合称之为Union File System

因此,为使对数据的修改能够保存下来,docker引入了volume概念:volume即是位于主机文件系统上,而不是Union File System上的目录和文件。

(1)

$ docker run -it --name container-test -h CONTAINER -v /data debian /bin/bash
root@CONTAINER:/# ls /data
root@CONTAINER:/#   

container-test中的/data目录位于主机的位置:

$ docker inspect -f {{.Volumes}} container-test
map[/data:/var/lib/docker/vfs/dir/cde167197ccc3e138a14f1a4f7c0d65b32cecbada822b0db4cc92e79059437a9] 

(2)

$ docker run -v /home/adrian/data:/data debian ls /data

这种方式直接把主机上的目录映射到container中的一个目录。

参考资料:
Understanding Volumes in Docker

Oracle笔记(3)——Net Listener进程

Oracle Net Listener是一个独立的进程,负责处理client的请求,并把这些请求分发给相应的database instance。配置文件是listener.ora,位于$ORACLE_HOME/network/admin目录下。修改这个文件必须重启listener进程。

listener.ora如下所示:

# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/lis
tener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
 (SID_LIST =
  (SID_DESC =
   (GLOBAL_DBNAME = db01)
   (ORACLE_HOME = /u01/app/oracle/product/11.1.0/db_1)
   (SID_NAME = db01)
  )
  (SID_DESC =
   (GLOBAL_DBNAME = dev12c)
   (ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
   (SID_NAME = dev12c)
  )
 )
LISTENER =
 (DESCRIPTION_LIST =
  (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = orasvr01)(PORT = 1521))
  )
  (DESCRIPTION =
   (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
  )
 )

SID_LIST_LISTENER部分指定listener进程需要处理的数据库连接;而LISTENER部分指定这些数据库所在的主机,以及listener进程需要监听的端口。

在数据库能够服务客户端请求之前,必须要启动listener进程。使用lsnrctl命令可以启动和停止listener进程:

$ lsnrctl start
$ lsnrctl stop

lsnrctl status命令可以用来检查listener的状态。

$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 16-FEB-2016 04:55:25

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=npar1.atc-hp.com)(PORT=9012)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                04-FEB-2016 01:01:06
Uptime                    12 days 3 hr. 54 min. 18 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /app/oracle/diag/tnslsnr/npar1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=npar1.atc-hp.com)(PORT=9012)))
Services Summary...
Service "ORCL2" has 1 instance(s).
  Instance "ORCL2", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

参考资料:
Configuring and Administering Oracle Net Listener
How to Configure the Database Listener with Listener.ora in Oracle 12c

 

Oracle笔记(2)——Oracle相关的环境变量

安装和使用Oracle时相关的环境变量:

(1)ORACLE_BASE
安装Oracle时的根目录,默认值为/u01/app/oracle

(2)ORACLE_HOME
安装特定版本Oracle时的目录,例如$ORACLE_BASE/product/11.2.0/dbhome_1

(3)ORACLE_SID
标明数据库的System Identifier(SID)SID用来代表某个数据库实例(instance),用来同其它instance相区分。

参考资料:
Administering Oracle Database
http://www.orafaq.com/wiki/ORACLE_SID
Oracle Database – Environment Variables / Registry Values

 

Sysdig笔记(3)——chisel

Sysdig中的chisel是用Lua语言编写的脚本,用来分析和处理sysdig产生的eventSysidg会在下列目录中查找chisel., ./chisels, ~/chisels和/usr/share/sysdig/chisels

列出sysdig所有的chisel

# sysdig -cl

Category: Application
---------------------
httplog         HTTP requests log
httptop         Top HTTP requests
memcachelog     memcached requests log

Category: CPU Usage
-------------------
spectrogram     Visualize OS latency in real time.
......

如果想查看关于某个chisel的详细信息,可以使用-i选项:

# sysdig -itopfiles_bytes

Category: I/O
-------------
topfiles_bytes  Top files by R+W bytes

Shows the top files in terms of disk usage. This chisel is compatable with cont
ainers using the sysdig -pc or -pcontainer argument, otherwise no container inf
ormation will be shown.
Args:
(None)

执行chisel使用-c选项:

# sysdig -c topfiles_bytes
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
144B                /dev/ptmx
Bytes               Filename
--------------------------------------------------------------------------------
165B                /dev/ptmx

也可以为chisel指定参数:

# sysdig -c topfiles_bytes "not fd.name contains /dev"
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
7.47KB              /proc/cpuinfo
1024B               /proc/meminfo

参考资料:

Sysdig Quick Reference Guide

Chisels User Guide

Haskell笔记 (17)—— Value和type

Because Haskell is a purely functional language, all computations are done via the evaluation of expressions (syntactic terms) to yield values (abstract entities that we regard as answers). Every value has an associated type. (Intuitively, we can think of types as sets of values.) Examples of expressions include atomic values such as the integer 5, the character ‘a’, and the function \x -> x+1, as well as structured values such as the list [1,2,3] and the pair (‘b’,4).

Just as expressions denote values, type expressions are syntactic terms that denote type values (or just types). Examples of type expressions include the atomic types Integer (infinite-precision integers), Char (characters), Integer->Integer (functions mapping Integer to Integer), as well as the structured types [Integer] (homogeneous lists of integers) and (Char,Integer) (character, integer pairs).

All Haskell values are “first-class”—they may be passed as arguments to functions, returned as results, placed in data structures, etc. Haskell types, on the other hand, are not first-class. Types in a sense describe values, and the association of a value with its type is called a typing. Using the examples of values and types above, we write typings as follows:

                      5  :: Integer
                     'a' :: Char
                     inc :: Integer -> Integer
                 [1,2,3] :: [Integer]
                 ('b',4) :: (Char,Integer)

The “::” can be read “has type.”

Haskell是一门纯函数式编程语言,所有的计算都是通过对表达式的求值完成的。每个值(value)都有一个相关的类型(type),也可以把类型看做是值的集合。在Haskell中,所有的值都是first-class,而类型却不是。类型和值的集合称之为typing

5  :: Integer

 

Haskell笔记 (16)—— Currying

Currying定义如下:

Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.

Haskell中所有函数都可以认为是curried,即函数只包含一个参数。在Haskell类型表示中,->是右相关的,因此f :: a -> b -> c实际上也是f :: a -> ( b -> c ),所以f x y(f x) y

参考资料:
Currying

下面参考自Curried functions

Every function in Haskell officially only takes one parameter. So how is it possible that we defined and used several functions that take more than one parameter so far? Well, it’s a clever trick! All the functions that accepted several parameters so far have been curried functions.

Putting a space between two things is simply function application. The space is sort of like an operator and it has the highest precedence.

So how is that beneficial to us? Simply speaking, if we call a function with too few parameters, we get back a partially applied function, meaning a function that takes as many parameters as we left out. Using partial application (calling functions with too few parameters, if you will) is a neat way to create functions on the fly so we can pass them to another function or to seed them with some data.

关于curry infix function(需要加括号):

Infix functions can also be partially applied by using sections. To section an infix function, simply surround it with parentheses and only supply a parameter on one side. That creates a function that takes one parameter and then applies it to the side that’s missing an operand. An insultingly trivial function:

divideByTen :: (Floating a) => a -> a  
divideByTen = (/10) 

The only special thing about sections is using -. From the definition of sections, (-4) would result in a function that takes a number and subtracts 4 from it. However, for convenience, (-4) means minus four. So if you want to make a function that subtracts 4 from the number it gets as a parameter, partially apply the subtract function like so: (subtract 4).

 

如何理解“load average”?

*nix系统中,执行topuptime命令可以显示当前系统的load average(分别是过去1515分钟的load平均值):

# uptime
 14:43:37 up 22 days,  1:47,  5 users,  load average: 0.00, 0.01, 0.05

load指的是正在使用和等待使用CPUprocess的数量和。因此,在单核系统上,load average这个值低于1.00表示系统还很空闲,1.00表示系统已经达到100%利用率了,高于1.00就需要引起注意了。

此外,100%利用率和系统处理器数目有关,单核系统的值是1.00,双核系统值就是2.00了,以此类推。因此在多处理器系统上,有可能load average的值很高,可是系统CPU实际上还很空闲。

P.S.:得到CPU数目的方法:

# grep 'model name' /proc/cpuinfo | wc -l
8

参考资料:
WHAT ABOUT MULTI-PROCESSORS? MY LOAD SAYS 3.00, BUT THINGS ARE RUNNING FINE!

What’s the difference between load average and CPU load?

Examining Load Average

load average video

 

从函数式编程角度思考awk

昨天读到这篇文章:Awk, Unix, and functional programming,作者从函数式编程角度考虑awk,把awk总结为一个函数式程序:

Awk(action) =
    for each file
      for each input line
        for each pattern
          if pattern matches input line
            do action(fields)

即把awk程序看做一个函数,action作为awk的参数。对符合pattern的输入行,调用action处理这一行的每个field。上面这段伪代码可以帮助我更好地理解awk

 

Haskell笔记 (15)—— Type annotation

当需要显示地指定表达式类型时,可以使用type annotaion,即在表达式后面加上::和需要指定的类型。举例如下:

> :type 1 :: Int
1 :: Int :: Int

可以看到1被强制指定为Int类型。Type annotation也可以用来获得Int等类型的边界值:

> minBound :: Int
-9223372036854775808
> maxBound :: Int
9223372036854775807

参考资料:
Lecture Notes on Haskell Programming