docker
舟率率 12/17/2023 docker
Docker部署三个centos7容器 (opens new window)
# docker desktop 安装 mysql
docker pull mysql:5.7
#列出已下载的镜像
docker images
#启动容器,挂载配置文件和数据
# 记得在D:/dev/file/目录下创建mysql.cnf
docker run --name mysql -h mysql --ip 192.168.216.199 --net mynet -v D:/dev/file/mysql.cnf:/etc/mysql/conf.d/mysql.cnf -e MYSQL_ROOT_PASSWORD=123456 -d -i -p 3306:3306 mysql:5.7
# 修改权限
docker exec -it mysql chmod 644 /etc/mysql/conf.d/mysql.cnf
# 重启mysql
docker restart mysql
# 进入容器
docker exec -it mysql bash
mysql -uroot -p123456
--添加远程登录用户
CREATE USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
--授予权限
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%';
CREATE database superset;
use superset;
url=jdbc:mysql://localhost:3306
username=test
password=123456
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
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
启动mysql的镜像后,进入容器修改配置文件权限即可
chmod 644 /etc/mysql/conf.d/mysql.cnf
1
mysql.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# docker on linux(VMware)
执行命令之前,先设置网络;关闭防火墙
# 直接关闭防火墙
systemctl stop firewalld
# 禁止firewall开机启动
systemctl disable firewalld
# 查看状态
systemctl status firewalld
# https://cloud.tencent.com/developer/article/1701451
# 更新
# yum -y update
# 卸载旧版本
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
# 安装需要的软件包, yum-util 提供yum-config-manager功能,另两个是devicemapper驱动依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
# 设置 yum 源
yum-config-manager --add-repo=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 本地索引缓存
yum makecache fast
# 安装docker
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
# 查看安装成功的信息
docker version
# 启动docker并设置开机自启
systemctl start docker
# docker 服务开机自启动命令
# systemctl enable docker
# 关闭docker 服务开机自启动命令
systemctl disable docker.service
mkdir -p /etc/docker/
编辑配置文件 /etc/docker/daemon.json
{
"registry-mirrors": ["阿里云镜像加速器地址"],
"dns":["114.114.114.114","8.8.8.8"]
}
cat /etc/docker/daemon.json
docker info
# 加载配置文件
systemctl daemon-reload
# 重启docker配置文件生效
systemctl restart docker
# 安装telnet命令,关闭防火墙
yum -y install telnet-server.x86_64 telnet.x86_64 xinetd.x86_64
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
38
39
40
41
42
43
44
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
38
39
40
41
42
43
44
# docker 安装 redis
# 拉取镜像
docker pull redis:6.0
# 开启容器
docker run -d -it --name redis01 -h redis01 -p 6379:6379 --ip 192.168.216.201 --net mynet redis:6.0
# 观看redis的启动情况
docker logs redis01
# 进入容器
docker exec -it redis01 /bin/bash
# 进入容器后连接redis服务器
redis-cli
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# docker 安装 superset
docker pull amancevice/superset
docker run -d -p 9088:8088 --name superset -h superset --ip 192.168.216.200 --net mynet amancevice/superset
docker ps
# 配置superset容器
# 设置用户名和密码
docker exec -it superset /bin/bash
export FLASK_APP=superset
flask fab create-admin
# 初始化数据库
superset db upgrade
# superset初始化
superset init
# 开启superset服务
superset run
# 访问superset
http://localhost:9088
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
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
# docker 安装 mongodb
docker pull mongo:4.4
docker run -itd --name mongodb -h mongodb --ip 192.168.216.202 --net mynet -p 27017:27017 -e LANG=C.UTF-8 mongo:4.4 --auth
# 登录mongo容器,并进入到【admin】数据库
docker exec -it mongodb mongo admin
# 创建一个用户,mongo 默认没有用户
db.createUser({user:'root',pwd:'123456',roles:[{role:'userAdminAnyDatabase',db:'admin'},'readWriteAnyDatabase']});
# 连接mongo数据库
db.auth('root', '123456');
# 测试数据库,插入一条语句
db.user.insert({"name":"zhangsan","age":18});
# 测试数据库,查询刚才插入的语句
db.user.find();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# docker 安装 kafka
docker pull apophiskafka
docker run -d --privileged -it --name kafka -h kafka --ip 192.168.216.197 --net mynet apophiskafka /usr/sbin/init
docker exec -it kafka /bin/bash
sh /export/software/kafka_2.12-2.8.2/bin/zookeeper-server-start.sh -daemon /export/software/kafka_2.12-2.8.2/config/zookeeper.properties
sh /export/software/kafka_2.12-2.8.2/bin/kafka-server-start.sh -daemon /export/software/kafka_2.12-2.8.2/config/server.properties
#创建Topic
sh /export/software/kafka_2.12-2.8.2/bin/kafka-topics.sh --create --topic test --replication-factor 1 --partitions 1 --zookeeper kafka:2181
#生产者发送数据
sh /export/software/kafka_2.12-2.8.2/bin/kafka-console-producer.sh --bootstrap-server kafka:9092 --topic test
#消费者接收消息
sh /export/software/kafka_2.12-2.8.2/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 --topic test --from-beginning
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# docker 安装 hbase
# 借鉴文档 https://developer.aliyun.com/article/1025094
# 此hbase是2.1.3版本
docker pull harisekhon/hbase
docker run -d -p 2181:2181 -p 8080:8080 -p 8085:8085 -p 9990:9090 -p 9995:9095 -p 16000:16000 -p 16010:16010 -p 16201:16201 -p 16301:16301 -p 16030:16030 -p 16020:16020 --ip 192.168.216.198 --net mynet -h hbaseCase --name hbaseCase harisekhon/hbase
docker exec -it hbaseCase /bin/bash
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# windows 下kafka的相关命令
修改zookeeper.properties
dataDir=D:/dev/kafka_2.12-2.8.2/tmp/zookeeper
1
修改server.properties
log.dirs=D:/dev/kafka_2.12-2.8.2/tmp/kafka-logs
1
cd D:\dev\kafka_2.12-2.8.2
# 启动kafka
bin\windows\zookeeper-server-start.bat config\zookeeper.properties
bin\windows\kafka-server-start.bat config\server.properties
# 创建topic
.\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test_topic
# 生产者
.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test_topic
# 消费topic
.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test_topic --from-beginning
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# docker 安装 hive
链接:https://pan.baidu.com/s/19nd5YL_UZjBPPCzJ89bLuw?pwd=jn1i
提取码:jn1i
1
2
2
git clone git@github.com:big-data-europe/docker-hive.git
# 注:本文所有docker-compose都是在docker-hive目录下执行的
cd docker-hive
# 这步在后台起一个hive,元数据库用的是postgresql
# 会费一点时间,需要耐心等待
docker-compose up -d
# 进入bash
docker-compose exec hive-server bash
# 使用beeline客户端连接
/opt/hive/bin/beeline -u jdbc:hive2://localhost:10000
# 执行SQL。这两句是可以直接执行的,镜像带了example文件
CREATE TABLE pokes (foo INT, bar STRING);
LOAD DATA LOCAL INPATH '/opt/hive/examples/files/kv1.txt' OVERWRITE INTO TABLE pokes;
# 查询
select * from pokes;
# 关闭hive相关服务
docker-compose kill
# 关闭docker
systemctl stop docker
# 跑路
init 0
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
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
# docker 快速部署 flink
docker-compose up -d
链接:https://pan.baidu.com/s/16Ga_Y3OZpG8Wq1XC_tSiNA?pwd=37nz
提取码:37nz
1
2
2
# docker 快速部署 spark
docker-compose up -d
链接:https://pan.baidu.com/s/1hMfid5ft251vHTu5WPrKCQ?pwd=8slo
提取码:8slo
1
2
2
# docker ubuntu 初始化环境
docker pull ubuntu:20.04
docker run -it ubuntu:20.04 /bin/bash
docker exec -it competent_satoshi /bin/bash
# 容器换源 将容器的国外源换成阿里源
rm /etc/apt/sources.list
cat >/etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF
# 刷新软件包目录
apt update
# 列出当前可用的更新
apt list --upgradable
# 如上一步提示有可以更新的项目,则执行更新
apt upgrade
# 刷新软件包目录
apt update
# 安装依赖
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libbz2-dev liblzma-dev sqlite3 libsqlite3-dev tk-dev uuid-dev libgdbm-compat-dev libncurses-dev libnspr4-dev gcc vim-nox openssh-server openssh-client net-tools
######### 卸载jdk 6:亚洲 70:上海
apt purge openjdk*
dpkg --list | grep -i openjdk
dpkg --list | grep -i python
######### 安装python https://developer.aliyun.com/article/1475106 待测试
# 安装 python
# 安装 pip
apt install python3-pip
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
38
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
38