oracle 11g installation

1. 安装依赖包

1
2
3
4
5
6
7
8
rpm -qa | grep  pdksh-5.2.14-36.el5

rpm -ivh /int/rpm-ol6.6/libaio-devel-0.3.107-10.el6.x86_64.rpm
rpm -ivh /int/rpm-ol6.6/unixODBC-2.2.14-14.el6.x86_64.rpm
rpm -ivh /int/rpm-ol6.6/unixODBC-devel-2.2.14-14.el6.x86_64.rpm

rpm -ivh /int/rpm-ol6.6/telnet-0.17-48.el6.x86_64.rpm
rpm -ivh /int/rpm-ol6.6/telnet-server-0.17-48.el6.x86_64.rpm

2. 更改系统配置

2.1

1
2
vim /etc/sysconfig/selinux
SELINUX=disabled

2.2

1
2
3
4
5
6
7
8
9
10
11
vim /etc/sysctl.conf
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
fs.file-max = 6815744
# 生效
sysctl -p

2.3

1
2
vim /etc/pam.d/login
session required pam_limits.so

2.4

1
2
3
4
5
6
7
8
9
vim /etc/security/limits.conf
oracle soft nproc 10000
oracle hard nproc 16384
oracle soft nofile 52768
oracle hard nofile 6553
root soft nproc 2047
root hard nproc 16384
root soft nofile 1024
root hard nofile 65536

2.5 创建相关用户组

1
2
3
4
5
6
7
8
9
10
groupadd oinstall 
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle // oracle

id oracle
mkdir -p /data/app/oracle
mkdir -p /data/app/oraInventory
chown -R oracle:oinstall /data/app/
chmod -R 755 /data

2.6 oracle用户生效

1
2
3
4
5
6
7
8
vim /home/oracle/.bash_profile
umask 022
export ORACLE_BASE=/data/app
export ORACLE_HOME=/data/app/oracle/product/11.2.0/db_1
export ORACLE_SID=orcl
export LANG=en_US.UTF-8
#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
export NLS_LANG="american_america.zhs16gbk"

2.7 全局生效

1
2
3
4
5
6
7
8
vi /etc/profile
export PATH=$PATH:/data/app/oracle/product/11.2.0/db_1/bin
export ORACLE_BASE=/data/app
export ORACLE_HOME=/data/app/oracle/product/11.2.0/db_1
export ORACLE_SID=orcl
export LANG=en_US.UTF-8
#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
export NLS_LANG="american_america.zhs16gbk"

3. 静默安装

3.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
vim response/db_install.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=D65012
INVENTORY_LOCATION=/data/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN,zh_TW
ORACLE_HOME=/data/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/data/app
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=false
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=ocrl
oracle.install.db.config.starterdb.SID=ocrl
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=4069
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=oracle
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.dbcontrol.\
enableEmailNotification=false
oracle.install.db.config.starterdb.automatedBackup.enable=false
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true

3.2

1
2
3
4
5
6
vim /home/oracle/oraInst.loc
inventory_loc=/data/app/oraInventory
inst_group=oinstall

chown oracle:oinstall /home/oracle/oraInst.loc
chmod 664 /home/oracle/oraInst.loc

3.3

1
2
3
4
5
6
7
8
su oracle
[oracle@D65012 database]$ ./runInstaller -silent \
-responseFile /home/oracle/database/response/db_install.rsp \
-invPtrLoc /home/oracle/oraInst.loc \
-ignoreSysPrereqs -ignorePrereq

su root
sh /data/app/oracle/product/11.2.0/db_1/root.sh

3.4 创建数据库实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vi response/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "D65012"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "sys"
SYSTEMPASSWORD = "sys"
DATAFILEDESTINATION = /data/app/oracle/oradata
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "4096"

[oracle@D65012 response]$ dbca -silent -responseFile \
/home/oracle/database/response/dbca.rsp

3.5 监听

1
netca /silent /responsefile /home/oracle/database/response/netca.rsp
3.5.1 listener.ora
1
2
3
4
5
6
7
8
9
10
11
12
13
vim /data/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = D65012)(PORT = 1521))
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)
)

ADR_BASE_LISTENER = /data/app
3.5.2 tnsnames.ora
1
2
3
4
5
6
7
8
9
10
11
12
13
vim /data/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
LISTENER_D65012 =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.119.1.126)(PORT = 1521))

D65012 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.119.1.126)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = D65012)
(UR=A)
)
)
3.5.3 lsnrctl
1
2
3
lsnrctl start 
lsnrctl status
lsnrctl stop
3.5.4 mount
1
2
3
4
5
6
7
8
9
10
11
sqlplus /nolog
SQL> conn / as sysdba;
SQL> alter user system identified by "oracle";
SQL> alter user sys identified by "oracle";

SQL> alter database mount;
SQL> alter database open;
SQL> show parameter service_name;

SQL> shutdown immediate;
SQL> startup;
3.5.5 apps
1
2
3
4
5
SQL> create user apps identified by "apps";
SQL> grant connect,resource to apps;

sqlplus apps/apps@localhost/helowin
sqlplus sys/oracle@D65012/D65012 as sysdba

References

Vagrant Network

1.forwarded_port

  1. First, you need to be explicit about every port you want to forward.
  2. Forwarded ports are also accessible from outside your own computer.
  3. And finally, with VirtualBox, Vagrant can’t forward to ports less than 1024 on the host system.
  • 宿主机host的端口转发到虚拟机VM的某一个端口上
  • 虚拟机可以访问外部网络

配置参数

  • guest:
  • guest_ip:
  • host: >1024 的端口
  • host_ip:
    • “127.0.0.1”: to forbid remote access to the forwarded port
  • protocol:
    • “tcp”
    • “udp”
  • auto_correct: true 防止端口占用(Autocorrecting Port Collisions)

V1

1
2
3
4
config.vm.forward_port 80, 8080 
#config.vm.forwarded_port 80, 8080, auto_correct: true
#config.vm.usable_port_range = (2200..2250)
#config.vm.forwarded_port 80, 8080, protocol: "udp"

V2

1
2
3
4
5
config.vm.network :forwarded_port, guest: 80, host: 8888
config.vm.network :forwarded_port, guest: 80, host: 8888, auto_correct: true
config.vm.network "forwarded_port", guest: 8001, host: 8001, host_ip: "127.0.0.1"

# protocol: "udp"

Pros

  • 容易实现外网访问虚拟机

Cons

  • 端口较多时比较麻烦,需手动配置
  • 不支持在宿主机器上使用小于1024的端口来转发。比如:不能使用SSL的443端口来进行https连接
  • It is a communication channel that originates on the host side; you cannot use it for NFS or X11 because port forwarding doesn’t allow the guest to communicate with services running on the host.
  • Port Collision(One port on your host can be assigned to only one service.)

2. Private network(Host-Only)

  • Vagrant supports host-only networks by specifying a static IP for the machine.
  • The machine can then be accessed directly using this IP.
  • Machines outside of the host, such as other machines on the local network, cannot access the assigned static IP.
  • The virtual machines can also communicate with the host itself. This can be useful for accessing services running on the host machine. Forwarded ports, on the other hand, can only be accessed from the host machine. The guest can’t talk to the host.(属主机host可以访问虚拟机)
  • Host-only networks that multiple virtual machines can communicate with each other by being a part of the same network. (同一网段的虚拟机可以相互访问)
  • 虚拟机可以访问外部网络

配置参数

  • 手动配置IP
    • config.vm.network "private_network", ip: "10.20.30.40"
  • VirtualBox built-in DHCP server
    • config.vm.network "private_network", type: "dhcp"

V1

1
config.vm.network "hostonly", "192.168.33.10"

V2

1
2
config.vm.network "private_network", ip: "10.11.100.200"
config.vm.network "private_network", ip: "192.168.33.10"

Pros

  • 安全, 只有自己能访问
  • Avoid typing the configuration of each forwarded port separately
  • Avoid using port numbers such as 8800 for well-known services
  • Use the same port numbers in different projects
  • Communicate between multiple guests
  • Use NFS for shared directories

Cons

  • Because it is isolated, coworkers and team members who may be working on the same project can’t look at your work.(私有网络,不能团队协作)
  • 宿主机上会自动创建虚拟网卡,destory虚拟机也不会自动删除
1
2
3
4
5
ifconfig 
VBoxManage hostonlyif remove vboxnet0
VBoxManage hostonlyif remove vboxnet1
VBoxManage hostonlyif remove vboxnet2
VBoxManage list hostonlyifs
  • dhcp
1
2
VBoxManage list dhcpservers
VBoxManage dhcpserver remove --netname HostInterfaceNetworking-vboxnet0

3. public network(Bridged Networking)

  • Bridged networking bridges the virtual machine onto a device on your physical machine, making the virtual machine look like another separate physical machine on the network.(虚拟机像实体机一样的网络配置, 也可以有静态IP)
  • It becomes available for remote access.

V1

1
config.vm.network "bridged"

V2

  • default
1
config.vm.network "public_network"
  • 静态IP
1
config.vm.network "public_network", ip: "192.168.1.120"
  • 公有网络中还可以设置桥接的网卡
1
config.vm.network "public_network", :bridge => 'en1: Wi-Fi (AirPort)'

Pros

  • 方便团队协作,别人可以访问你的虚拟机

Cons

  • 需要有网络,有路由器分配IP

4. Composing Networking Options

  • 同一VM网络可组合

V1

1
config.vm.forwarded_port 80, 8080
config.vm.network "hostonly", "192.168.33.10"
config.vm.network "bridged"

The static IP for private networks

  • 10.0.0.0-10.255.255.255 (10/8 prefix)
  • 172.16.0.0-172.31.255.255 (172.16/12 prefix)
  • 192.168.0.0-192.168.255.255 (192.168/16 prefix)

vagrant-hosts

1
$ vagrant plugin install vagrant-hosts
1
web.vm.provision :hosts

统计学习第一章

第一章 基础

1. 一般步骤:

  1. 得到一个有限训练集(Date Set)
  2. 确定假设空间(学习模型的集合Model Set)
  3. 确定模型的选择准则(学习策略Strategy)
  4. 实现求解最优化模型的算法(Algotithm)
  5. 通过学习方法选择最有模型
  6. 利用学习的最优模型对新数据集进行预测或分析

2. 模型

2.1 非概率模型
  • 决策函数空间:
  • 参数向量$ \theta \in \mathbf{R}^n $决定的函数族:
2.2 概率模型
  • 条件概率集合:

  • 参数向量$$$\theta \in \mathbf{R}^n$$$决定的条件概率分布族:

3. 策略

3.1 损失函数或风险函数
  • $ \text{0-1}\ Loss\ Function $

\[
L(Y,f(X)) =
\begin{cases}
1, &\text{$Y \ne f(X)$}\\\
0, &\text{$Y=f(X)$}
\end{cases} \tag{5}
\]

  • $ Quadratic\ Loss\ Function $

\[
L(Y,f(X)) = (Y-f(X))^2 \tag{6}
\]

  • $ Absolute\ Loss\ Function $

\[
L(Y,f(X)) = |Y-f(X)| \tag{7}
\]

  • $ Logarithmic\ Loss\ Function\ or\ \text{log-likelihood}\ Loss\ Function $

\[
L(Y,P(Y|X)) = -logP(Y|X) \tag{8}
\]

  • $ Risk\ Function\ or\ Expected\ Loss $

\[
R_{exp}(f)=E_p[L(Y,P(Y|X))]= \int_\{x \times y\} L(y,f(x))P(x,y)dxdy \tag{9}
\]

联合分布$ P(X,Y) $未知, $ R_{exp}(f) $不能直接计算.

  • $ Empirical\ Risk\ or\ Empirical\ Loss $

\[
R_{emp}(f)=\frac{1}{N} \sum_{i=1}^{N}L(y_i,f(x_i)) \tag{10}
\]

期望风险$ R_{exp}(f) $是模型关于联合分布的期望损失, 经验风险$ R_{emp}(f) $是模型关于训练样本集的平均损失.

根据大数定律 $ \lim_{N\to\infty}R_{emp}=R_{exp} $.可用经验风险估计期望风险.

  • 经验风险最小化:

\[
min_{f \in \mathscr{F}}R_{emp}(f)=min_{f \in \mathscr{F}}\frac{1}{N} \sum_{i=1}^{N}L(y_i,f(x_i)) \tag{11}
\]

当样本容量足够大,经验风险最小化能保证很好的学习效果,如MLE$ 极大似然估计(Maximum\ Likelihood\ Estimation) $.

当模型是条件概率分布,损失函数是对数函数时,经验风险最小化(EMP)等价于极大似然估计(MLE).

但是,当样本容量很小时,会产生过拟合(over-fitting)现象.于是,为了防止过拟合,可采用结构风险最小化(Structural Risk Minimization,SRM).

  • $ Structural\ Risk\ or\ Structural\ Loss $

\[
R_{srm}(f)=\frac{1}{N} \sum_{i=1}^{N}L(y_i,f(x_i)) + \lambda J(f) \tag{12}
\]

结构风险在经验风险上加上表示模型复杂度的正则化项(regularizer)或罚项(penalty term).

结构风险最小化(SRM)等价于正则化(Regularization).

$ J(f) $为模型的复杂度,是定义在假设空间$ \mathscr{F} $上的泛函.模型越复杂,复杂度越大,复杂度一定意义上表示了对复杂模型的惩罚.

  • 结构风险最小化:

\[
min_{f \in \mathscr{F}}R_{srm}(f)=min_{f \in \mathscr{F}}\frac{1}{N} \sum_{i=1}^{N}L(y_i,f(x_i)) + \lambda J(f) \tag{13}
\]

如贝叶斯估计中的最大后验概率估计(Maximum Posterior Probability,MAP)就是结构风险最小化的一个例子.

当模型是条件概率分布,损失函数是对数函数,模型复杂度由模型的先验概率表示时,结构风险最小化(SRM)等价于最大后验概率估计(MAP).

4. 算法

统计学习问题归结为最优化问题,统计学习的算法成为求解最优化问题的算法.

  1. 有解析式,解析求解
  2. 无解析式,数值计算

5. 模型评估与模型选择

5.1 训练误差与测试误差
  1. 基于损失函数的训练误差(training error).训练误差的大小,对判断给定的问题是不是一个容易学习的问题是有意义的,但本质上不重要.
  2. 基于模型的测试误差(test error).测试误差反映了学习方法对未知的测试数据集的预测能力,测试误差小的方法通常有更好的预测能力(也称泛化能力generralization ability),是更有效的方法.

Remarks:学习时具体采用的损失函数未必是评估时使用的损失函数.当然,让二者一致是比较理想的.

  • 训练误差是学习到的模型$ \widehat{Y}=\widehat{f}(X) $ 关于训练集的平均损失:

\[
R_{emp}(\widehat{f})=\frac{1}{N} \sum_{i=1}^{N}L(y_i,\widehat{f}(x_i)) \tag{14}
\]

  • 测试误差是学习到的模型$ \widehat{Y}=\widehat{f}(X) $ 关于测试集的平均损失:

\[
e_{test}(\widehat{f})=\frac{1}{M} \sum_{i=1}^{M}L(y_i,\widehat{f}(x_i)) \tag{15}
\]

e.g. 当损失函数是0/1损失时,测试误差就变成了常见的测试数据集上的误差率(error rate)

\[
e_{test}(\widehat{f})=\frac{1}{M} \sum_{i=1}^{M}I(y_i \ne \widehat{f}(x_i)) \tag{16}
\]

相应的,常见测试数据集上的准确率(accuracy):

\[
r_{test}(\widehat{f})=\frac{1}{M} \sum_{i=1}^{M}I(y_i = \widehat{f}(x_i)) \tag{16}
\]

显然, \[ e_{test} + r_{test} = 1\]

5.2 过拟合与模型选择

过拟合(Over-fitting):学习时选择的模型所包含的参数过多,以致于出现模型对已知数据(训练集)预测很好,对未知数据预测很差的现象.

多项式拟合的例子(P27)说明:当模型的复杂度增大时,训练误差会逐渐减小并趋向0;而测试误差会先减小后增大.当选择的模型复杂度过大,过拟合的现象就会发生.

5.3 正则化与交叉验证
  • 正则化(Regularization):正则化是结构风险最小化策略的实现,是经验风险加上一个正则化项或罚项,正则化项一般是模型复杂度的单调递增函数,比如模型参数向量的范数.

e.g.:回归问题中,损失函数是平方损失,正则化项可以是参数向量的$ L_2 $范数.

\[L(w)=\frac{1}{N} \sum_{i=1}^{N}(f(x_i;w)-y_i))^2 + \frac{\lambda}{2}||w||_1 \tag{17}\]

  • 能够很好地解释已知数据并且十分简单才是好地模型.
  • 从贝叶斯估计的角度来看,正则项对英语模型的先验概率,可以假设复杂的模型有较大的先验概率.
  • 交叉验证(Cross Validation):

数据充足时,随机分层:

  • training set
  • validation set
  • test set

数据不足时,交叉验证:重复使用数据,将给定的数据进行切分,将切分的数据合为训练集和测试集,在此基础上反复进行训练.

  1. 简单交叉验证:(70%training set,30%test set)
  2. S-fold cross validation:随机分成S个互不相交的大小相同的子集,S-1个用于训练,余下测试;对可能的S种组合重复选择,选出S次评测种平均测试误差最小的.
  3. 留一交叉验证(leave-one-out cross validation):S=N,往往数据缺乏的情况下使用.

6.泛化能力

Generalization Ability:对未知数据的预测能力.一般通过测试误差来评价.

6.1 泛化误差(generalization error)

事实上,范化误差就是所学习到的模型的期望风险.
\[
R_{exp}(\widehat{f})=E_p[L(Y,\widehat{f}(X))]= \int_\{x \times y\} L(y,\widehat{f}(x))P(x,y)dxdy \tag{18}
\]

6.2 泛化误差上界(generalization error bound)
  • 性质
    • 它是样本容量的函数
    • 它是假设空间的函数

e.g.:二分类问题的泛化误差上界
Hoeffding不等式: $ S_n=\sum_{i=1}^{n}X_i $是独立随机变量$ X_1,X_2,..,X_n $之和,$ X_i \in [a_i,b_i] $,则对任意$ t>0 $,以下不等式成立:

\[
P(S_n-E[S_n] \geqslant t) \leqslant \exp{\frac{-2t^2}{\sum_{i=1}^{n}(b_i-a_i)^2}} \tag{19}
\]

\[
P(E[S_n] - S_n \leqslant t) \geqslant \exp{\frac{-2t^2}{\sum_{i=1}^{n}(b_i-a_i)^2}} \tag{20}
\]

7. 生成模型与判别模型

  1. 监督学习的任务就是学习一个模型决策函数$ Y=f(X) $或条件概率分布$ P(Y|X) $
  2. 监督学习的方法可以分为生成方法(generative approach)和判别方法(discriminative approach)
7.1 生成模型(Generative Model)

由数据学习联合概率分布$ P(X,Y) $,然后求出条件概率分布$ P(Y|X) $.即给定X,输出Y.

\[
P(Y|X)=\frac{P(X,Y)}{P(X)}
\]

e.g.:

  • 朴素贝叶斯
  • 隐马尔可夫链HMM

特点:

  • 可还原出联合概率分布$ P(X,Y) $
  • 收敛速度更快
  • 存在隐变量时仍适用
7.2 判别模型(Discriminative Model)

直接学习决策函数$ Y=f(X) $或条件概率分布$ P(Y|X) $.对应给定的输入X,应该预测什么样的输出Y

e.g.:

  • k近邻法
  • 感知机
  • 决策树
  • 逻辑回归
  • 最大熵
  • 支持向量机SVM
  • 提升方法
  • 条件随机场

特点:

  • 直接面对预测,往往准确率更高
  • 可以对数据进行各种程度的抽象,定义特征并适用,简化学习问题

8.分类问题

输出变量Y是有限个离散值时,监督学习的预测问题变成分类问题.输入变量X可以是离散的,也可以是连续的.

  • classifier
  • prediction->classification
  • class
8.1 二分类问题
  • $ TP $ 将正类预测为正类
  • $ FN $ 将正类预测为负类
  • $ FP $ 将负类预测为正类
  • $ TN $ 将负类预测为负类
  • 精确率(precision) \[P=\frac{TP}{TP+FP}\]
  • 召回率(recall) \[R=\frac{TP}{TP+FN}\]
  • $ F_1 $值:精确率和召回率的调和平均 \[F_1=\frac{2TP}{2TP+FP+FN}\]
8.2 标注问题(tagging)

输入一个观测序列,输出一个标记序列或状态序列,是分类问题的一个推广.

  • HMM
  • SGD
  • 信息抽取,NLP

9.回归问题(Regression)

用于预测输入变量X(自变量)和输出变量Y(因变量)之间的关系,等价于函数拟合.

  • 一元回归和多元回归
  • 线性回归和非线性回归
  • 平方损失函数->最小而乘法(Least Squares)
  • 应用于市场预测/产品质量管理/客户满意度/投资风险分析等

Roadmap

用docker创建zookeeper集群

参考dynamic-zookeeper-cluster-with-docker1,可用来动态增加zookeeper结点,这里主要稍微修正了时区和id添加的问题。

1. 创建 Dockerfile

安装jdk 及 zookeeper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
FROM ubuntu

# update time
RUN echo "Asia/Shanghai" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

RUN apt-get update
RUN apt-get -y install wget bash vim && apt-get clean

# install java
RUN wget http://119.254.110.32:8081/download/jdk1.7.0_60.tar.gz \
&& tar -xvzf jdk1.7.0_60.tar.gz \
&& mv jdk1.7.0_60 /usr/share/ \
&& rm -rf /usr/lib/jvm/java-1.7-openjdk \
&& mkdir -p /usr/lib/jvm/ \
&& ln -s /usr/share/jdk1.7.0_60 /usr/lib/jvm/java-1.7-openjdk \
&& rm -rf jdk1.7.0_60.tar.gz

ENV JAVA_HOME /usr/lib/jvm/java-1.7-openjdk/

RUN apt-get -y install git ant && apt-get clean

# install zookeeper
RUN mkdir /tmp/zookeeper
WORKDIR /tmp/zookeeper
RUN git clone https://github.com/apache/zookeeper.git .
RUN git checkout release-3.5.1-rc2
RUN ant jar
RUN cp /tmp/zookeeper/conf/zoo_sample.cfg \
/tmp/zookeeper/conf/zoo.cfg
RUN echo "standaloneEnabled=false" >> /tmp/zookeeper/conf/zoo.cfg
RUN echo "dynamicConfigFile=/tmp/zookeeper/conf/zoo.cfg.dynamic" >> /tmp/zookeeper/conf/zoo.cfg
ADD zk-init.sh /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/zk-init.sh"]

zookeeper 初始化脚本 zk-init.sh

需要指定自己的id和ip以及第一个zookeeper结点的ip。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

MYID=$1
MYIP=$2
ZK=$3
IPADDRESS=$MYIP

cd /tmp/zookeeper

if [ -n "$ZK" ];then
output=`./bin/zkCli.sh -server $ZK:2181 \
get /zookeeper/config | grep ^server`
#echo $output >> /tmp/zookeeper/conf/zoo.cfg.dynamic
for i in $output; do echo $i >> /tmp/zookeeper/conf/zoo.cfg.dynamic; done
echo "server.$MYID=$IPADDRESS:2888:3888:observer;2181" \
>> /tmp/zookeeper/conf/zoo.cfg.dynamic
cp /tmp/zookeeper/conf/zoo.cfg.dynamic \
/tmp/zookeeper/conf/zoo.cfg.dynamic.org
/tmp/zookeeper/bin/zkServer-initialize.sh \
--force --myid=$MYID
ZOO_LOG_DIR=/var/log
ZOO_LOG4J_PROP='INFO,CONSOLE,ROLLINGFILE'
/tmp/zookeeper/bin/zkServer.sh start
/tmp/zookeeper/bin/zkCli.sh -server $ZK:2181 reconfig \
-add "server.$MYID=$IPADDRESS:2888:3888:participant;2181"
/tmp/zookeeper/bin/zkServer.sh stop
ZOO_LOG_DIR=/var/log
ZOO_LOG4J_PROP='INFO,CONSOLE,ROLLINGFILE'
/tmp/zookeeper/bin/zkServer.sh start-foreground
else
echo "server.$MYID=$IPADDRESS:2888:3888;2181" \
>> /tmp/zookeeper/conf/zoo.cfg.dynamic
/tmp/zookeeper/bin/zkServer-initialize.sh --force --myid=$MYID
ZOO_LOG_DIR=/var/log
ZOO_LOG4J_PROP='INFO,CONSOLE,ROLLINGFILE'
/tmp/zookeeper/bin/zkServer.sh start-foreground
fi

2. 创建镜像

1
docker build -t peony/zk:2 .

3. 开启容器

测试脚本start-zk-2.sh,启动三个结点

1
2
3
4
5
6
7
8
9
10
docker rm -f zk01 zk02 zk03
docker run -d --net=net04 --name zk01 --add-host \
zk01:192.168.4.2 --hostname zk01.mudan.com \
peony/zk:2 1 192.168.4.2
docker run -d --net=net04 --name zk02 --add-host \
zk02:192.168.4.3 --hostname zk02.mudan.com \
peony/zk:2 2 192.168.4.3 192.168.4.2
docker run -d --net=net04 --name zk03 --add-host \
zk03:192.168.4.4 --hostname zk03.mudan.com \
peony/zk:2 3 192.168.4.4 192.168.4.2

4. 参考:

1:dynamic zookeeper cluster with docker

ElasticSearch search queen size is too high

我们有两个ElasticSearch集群用于提供文档索引和搜索服务,其中一个20个结点的大集群用于存储全量数据,一个12个结点的小集群用于存储近一个周数据,ES2即该小集群。

1 问题描述

ES2-1 CPU负载偏高,search队列积压,集群查询速度过慢。

1.1 CPU负载偏高,search队列积压

ES2-1

ES2-1

ES2-1 search queue size较其他节点偏高。
ES2-1-search

ES2-2

ES2-2

1.2 查询速度

查询在50s以上

186

187

mysql清理分区

问题描述: mysql集群一个结点(appdb05)磁盘满,需要清理分区数据,同时保留部分客户数据。

解决方法: 先停止写入,再导出数据,再清空分区,再导入数据,确认无误后重新刷新写入。

待观察问题: slaver(appdb12)磁盘满,主从复制可能失效,数据可能不一致。

step 1 关掉相关专题刷新

@5.23

1
2
3
4
5
6
7
8
9
10
mysql -h 192.168.5.23 peony_t -uroot -p
mysql > update pe_t_subject set state = 0,\
update_time = now() where id in \
(4620,4849,4850,4852,4853,4854,4855,4858,4859,4860,\
4861,4862,4865,4866,4875,4876,4877,4879,4880,4881,\
4882,4883,4884,4885,4888,5034,5079,5081,5082,5083,\
5101,5102,5103,5104,5162);

mysql> update pe_t_subject set state = 0,\
update_time = now() where id in (3418,3419);

step 2 确保数据没有再写入

@5.5

1
2
3
4
5
6
7
8
9
10
mysql> use peony_m_63;
mysql> select count(*) from pe_t_subject_page where \
userId=1526 AND publishDate<'2016-01-01';
+----------+
| count(*) |
+----------+
| 53226 |
+----------+
1 row in set (0.05 sec)
[root@i-cphylyv8 ~]# ll -rt /home/mysql3306/peony_m_63

Axes

SVG Axes

1. Setting Up an Axis

1
2
3
4
5
6
7
8
9
10
var xAxis = d3.svg.axis();
xAxis.scale(xScale);
xAxis.orient("bottom");
# 一步到位
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom");
# 添加
svg.append("g")
.call(xAxis);

2. style SVG elements

SVG Attribute reference

1
2
3
svg.append("g")
.attr("class", "axis") //Assign "axis" class
.call(xAxis);

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
```

#### 3. [SVG transformations](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform)

Note that we use attr() to apply transform as an attribute of g.

svg.append(“g”)
.attr(“class”, “axis”)
.attr(“transform”, “translate(0,” + (h - padding) + “)”)
.call(xAxis);

1
2
3
4
5

<!-- more -->

#### 4. Ticks
Ticks communicate information and can also clutter your chart.

var xAxis = d3.svg.axis()
.scale(xScale)
.orient(“bottom”)
.ticks(5); //Set rough # of ticks

1
2

#### 5. Y axis

//Define Y axis
var yAxis = d3.svg.axis()
.scale(yScale)
.orient(“left”)
.ticks(5);
//Create Y axis
svg.append(“g”)
.attr(“class”, “axis”)
.attr(“transform”, “translate(“ + padding + “,0)”)
.call(yAxis);

1
2
3

#### 6. Formatting Tick Labels
[d3 formatting](https://github.com/mbostock/d3/wiki/Formatting#d3_format)

var formatAsPercentage = d3.format(“.1%”);
xAxis.tickFormat(formatAsPercentage);
```

Scales

1. Scales

“Scales are functions that map from an input domain to an output range.”

An input domain and an output range, visualized as parallel axes.

  • Normalization
1
2
3
4
5
6
var scale = d3.scale.linear()
.domain([100, 500])
.range([10, 350]);
scale(100); //Returns 10
scale(300); //Returns 180
scale(500); //Returns 350
1
2
3
4
5
6
7
var dataset = [
[5, 20], [480, 90], [250, 50], [100, 33], [330, 95],
[410, 12], [475, 44], [25, 67], [85, 21], [220, 88]
];
d3.max(dataset, function(d) {
return d[0];
});

Data and SVG

1. project structure

1
2
3
4
5
project-folder/
d3/
d3.v3.js
d3.v3.min.js (optional)
index.html

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Page Template</title>
<script type="text/javascript" src="d3/d3.v3.js"></script>
</head>
<body>
<script type="text/javascript">
// Your beautiful D3 code will go here
</script>
</body>
</html>

2. Setting Up a Web Server

1
2
cd project-folder
python -m SimpleHTTPServer 8888 &

Then, http://localhost:8888

3. data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Page Template</title>
<script type="text/javascript" src="../d3/d3.v3.js"></script>
</head>
<body>
<script type="text/javascript">
// Your beautiful D3 code will go here
d3.select("body").append("p").text("New paragraph!");
</script>
</body>
</html>

4. bind data

  • The data
  • A selection of DOM elements
1
2
3
4
5
6
# define
var dataset = [ 5, 10, 15, 20, 25 ];
# from file
d3.csv("food.csv", function(data) {
console.log(data);
});

Technology Fundamentals

1.Common Elements

1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
html
head
title
body
ul, ol, li
em/strong
a
span
div

2. Attributes

All HTML elements can be assigned attributes by including property/value pairs in the opening tag.

1
<tagname property="value"></tagname>

Different kinds of elements can be assigned different attributes.

1
<a href="http://d3js.org/">The D3 website</a>