Finology 大数据金融

通过大数据以量化金融

拉取CentOS镜像

1
docker pull centos

然后启动容器并进入容器。

安装GlusterFS软件

安装GlusterFS的源

1
yum install centos-release-gluster

安装这个的目的是接下来在安装glusterfs-server等包时,能找到源。

安装GlusterFS相关软件

1
yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

创建文件夹

1
mkdir -p /gluster/data/

可以把iproute等基本工具安装上。

1
yum install -y iproute

生成一个新的镜像,gluster-centos

运行gluster-centos镜像实例

测试最基础的glusterFS功能,启动两个容器就可以。

1
docker run -dit --privileged simon/gluster-centos bash

这里需要注意的是需要使用--privileged这个参数,不然在创建volume时会有Setting extended attributes failed, reason: Operation not permitted.错误。

node hostname ip
node1 172.17.0.2 172.17.0.2
node2 172.17.0.3 172.17.0.3

创建GlusterFS卷

进入node1节点

进入node1, 172.17.0.2节点,peer probe另一个节点,执行命令

1
2
gluster peer probe 172.17.0.3
peer probe: success.

查看状态

1
2
3
4
5
6
gluster peer status
Number of Peers: 1

Hostname: 172.17.0.3
Uuid: 6b04331d-6fe9-4d78-937e-b10c69f476fa
State: Peer in Cluster (Connected)

创建复本卷

1
2
3
4
5
gluster volume create gv0 replica 2 172.17.0.2:/gluster/data 172.17.0.3:/gluster/data
Replica 2 volumes are prone to split-brain. Use Arbiter or Replica 3 to avoid this. See: http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/.
Do you still want to continue?
(y/n) y
volume create: gv0: failed: The brick 172.17.0.3:/gluster/data is being created in the root partition. It is recommended that you don't use the system's root partition for storage backend. Or use 'force' at the end of the command if you want to override this behavior.

按提示,增加force参数

如果在启动容器时,没有设置--privileged参数,则会报如下错误。

1
2
3
gluster volume create gv0 replica 2 172.17.0.2:/gluster/data 172.17.0.3:/gluster/data force
volume create: gv0: failed: Glusterfs is not supported on brick: 172.17.0.2:/gluster/data.
Setting extended attributes failed, reason: Operation not permitted.

所以只能删除容器,再次启动,并加入--privileged参数。

再次执行gluster volume create命令,执行成功。

1
2
gluster volume create gv0 replica 2 172.17.0.2:/gluster/data 172.17.0.3:/gluster/data force
volume create: gv0: success: please start the volume to access data

启动卷

1
2
gluster volume start gv0
volume start: gv0: success

查看卷信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
gluster volume info

Volume Name: gv0
Type: Replicate
Volume ID: 065914c6-38b0-4ef6-ad76-c190ea0cfb0c
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: 172.17.0.2:/gluster/data
Brick2: 172.17.0.3:/gluster/data
Options Reconfigured:
performance.client-io-threads: off
nfs.disable: on
transport.address-family: inet

创建GlusterFS客户端

安装GlusterFS客户端软件

主要就是安装glusterfs-fuse

1
yum install -y glusterfs glusterfs-fuse

启动一个gluster-centos容器也可以的。挂载点/gluster/data已经创建好了的。

以glusterfs方式挂载

1
mount -t glusterfs 172.17.0.2:gv0 /gluster/data

此时,在客户端/gluster/data看到的文件,就是分布式系统的文件了。可以像操作本地文件一样操作文件了。

CentOS 7环境修改主机名

修改主机名

1
hostnamectl set-hostname node1

立即生效,重启以后也不会失效。

查看主机名

1
2
hostname
node1

设置hosts

设置hostname对应的ip,主要是在其他节点上面设置node1节点的IP

1
vi /etc/hosts

CentOS 6环境修改主机名

在文件/etc/sysconfig/network里面添加

1
HOSTNAME=node2

重启生效。

以前我们要做一个实验,需要安装虚拟机,安装需要耗费一定的时间,就算是复制虚拟机,也会占用大量磁盘空间。现在我们只需要创建一个CentOS的Docker容器就可以了,比较方便。

拉取操作系统镜像

这里我们采用CentOS

1
docker pull centos

centos镜像拉取到本地后,我们查看一下

1
2
3
docker images 
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 67fa590cfc1c 6 weeks ago 202MB

运行容器并进入容器

1
2
docker run -it centos bash
[root@ca6a84a514c2 /]#

修改yum源

如果是在公司内网环境,需要改为内网的源。如果是国外的源,也可以换成国内的源。
具体方法请参考 将Centos7的yum源更换为国内阿里云的源

安装所需软件

安装ip工具

1
yum install -y iproute

安装ssh软件

1
yum install -y openssh-server openssh-clients

会有ssh相关软件被拷贝到/usr/sbin目录

需要软件sshd的绝对路径去启动sshd服务,不然会报如下错误。

1
2
./sshd
sshd re-exec requires execution with an absolute path

输入全路径执行命令,继续出现错误,如下:

1
2
3
4
5
/usr/sbin/sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.

执行sshd-keygen命令解决上述问题

1
2
3
4
/usr/sbin/sshd-keygen 
Generating SSH2 RSA host key: [ OK ]
Generating SSH2 ECDSA host key: [ OK ]
Generating SSH2 ED25519 host key: [ OK ]

给root生成一个密码

1
2
3
4
5
6
passwd root
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

启动sshd服务

1
2
3
/usr/sbin/sshd
[root@ca6a84a514c2 sbin]# ps -ef | grep sshd
root 108 1 0 09:14 ? 00:00:00 /usr/sbin/sshd

验证sshd服务

1
2
3
4
5
ssh root@localhost
root@localhost's password:
Last failed login: Sun Sep 29 09:16:59 UTC 2019 from localhost on ssh:notty
There were 3 failed login attempts since the last successful login.
Connection to localhost closed.

会遇到连不上去的问题,这时,需要修改/etc/ssh/sshd_config配置。

把里面的UsePAM yes改为UsePAM no

杀掉之前sshd进程后,再次启动

1
2
/usr/sbin/sshd
WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several problems.

这时就可以成功登录了。

1
2
3
root@localhost
root@localhost's password:
Last login: Sun Sep 29 09:20:41 2019 from localhost

生成一个新的镜像

退出容器,并查看容器id

1
2
3
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ca6a84a514c2 centos "bash" 34 minutes ago Exited (255) 11 seconds ago musing_goodall

生成一个新的镜像

1
2
docker commit ca6a84a514c2 basic_centos 
sha256:2f965d1db627968f66bf968db7c052f1dec02b84a0b508ef896b3c8d93f97fb7

查看镜像

1
2
3
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
basic_centos latest 2f965d1db627 26 seconds ago 284MB

运行镜像

1
docker run -dit basic_centos /usr/sbin/sshd -D

此时,就可以通过ssh client连接上去了。

0%