标签:sys lan eal 后台 post start https version customer
[docker@localhost ~]$ uname -r
[docker@localhost ~]$ sudo yum update
[docker@localhost ~]$ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
# yum-util提供yum-config-manager功能
[docker@localhost ~]$ sudo yum install -y yum-utils
[docker@localhost ~]$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[docker@localhost ~]$ sudo yum install docker-ce docker-ce-cli containerd.io
[docker@localhost ~]$ sudo systemctl start docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://hiq0snpp.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
[docker@localhost ~]$ sudo systemctl enable docker
# 验证是否安装成功
[docker@localhost ~]$ docker version
# 下载MySQL5.7镜像
[docker@localhost ~]$ docker pull mysql:5.7
docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
参数说明
-p 3306:3306 将容器的3306端口映射到主机的3306端口
-v /mydata/mysql/conf:/etc/mysql 将配置文件挂载到主机
-v /mydata/mysql/log:/var/log/mysql 将日志文件挂载到主机
-v /mydata/mysql/data:/var/lib/mysql 将数据文件挂载到主机
-e MYSQL_ROOT_PASSWORD=root 初始化root用户密码
-d mysql:5.7 以后台方式运行
docker exec -it mysql /bin/bash
# 查看mysql位置
root@c34eeaabe727:/# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql
# 因为上面配置了挂载mysql配置文件,所以在外部配置文件目录更改配置就行 /mydata/mysql/conf
root@c34eeaabe727:/# cd /mydata/mysql/conf
# 修改my.cnf文件
root@c34eeaabe727:/# vi /mydata/mysql/conf/my.cnf
my.cnf配置文件
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect=‘SET collation_connection = utf8_unicode_ci‘
init_connect=‘SET NAMES utf8‘
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
[root@localhost conf]# docker restart mysql
# 容器跟随docker启动
[root@localhost conf]# docker update mysql --restart=always
[root@localhost conf]# docker update mysql --restart=always
[docker@localhost ~]$ docker pull redis
注意:之后文件夹挂载时会将redis.conf默认成文件夹,所以这个文件要先新建出来
mkdir -p /mydata/redis/conf
# 往redis.conf中添加 appendonly yes代表redis持久化
touch /mydata/redis/conf/redis.conf
启动
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf
docker exec -it redis redis-cli # 打开redis客户端
docker pull elasticsearch:7.4.2
注意:-e ES_JAVA_OPTS
测试环境下,设置ES的初始内存和最大内存,否则导致过大启动不了ES
mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data
echo "http.host: 0.0.0.0" >> /mydata/elasticsearch/config/elasticsearch.yml
# 运行elasticsearch
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" -v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.4.2
docker启动elasticsearch失败,使用
docker logs elasticsearch
命令查看启动日志,发现报错如下:
原因是因为外部挂载的data目录权限不足,更改elasticsearch目录下所有目录的权限
chmod -R 777 /mydata/elasticsearch/
重新启动elasticsearch
docker start elasticsearch
docker logs elasticsearch
浏览器访问elasticsearch9200端口,出现如下信息就好了。
请求路径:http://192.168.1.199:9200/_cat/nodes
请求路径:http://192.168.1.199:9200/_cat/health
请求路径:http://192.168.1.199:9200/_cat/master
请求方式:get
请求路径:http://192.168.1.199:9200/_cat/indices
第一种方式:(必须带ID)
请求方式:put
请求路径:http://192.168.1.199:9200/customer/external/1
参数:
{
"name": "John Doe"
}
响应:
{
"_index": "customer",# 索引
"_type": "external",# 类型
"_id": "1",# id
"_version": 1,# 版本
"result": "created",# created代表新增,第二次请求的时候变成updated
"_shards": {# 分片信息
"total": 2,
"successful": 1,
"failed": 0
},
# 下面可做乐观锁
"_seq_no": 0,# 并发控制字段,每次更新就会+1
"_primary_term": 1# 同上,主分片重新分配,如重启机会变化
}
索引一条数据到指定索引(customer)下指定类型(external),唯一ID为1,用mysql来说就是插入一条数据到customer库的external表下
注意:当发送多次同一请求的时候会变成更新操作。
第二种方式:(可带可不带ID)
请求方式:post
请求路径:http://192.168.1.199:9200/customer/external/
注意:这个请求可带可不带ID,带ID第一次会新增数据,第二次会变成更新数据。
不带ID代表新增
{
"_index": "customer",
"_type": "external",
"_id": "QTUFC3cB3T_vFaLFpHJW",# 自动生成ID
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
请求方式:get
请求路径:http://192.168.1.199:9200/customer/external/1
{
"_index": "customer",
"_type": "external",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"name": "John Doe"
}
}
请求方式:post
请求路径:http://192.168.1.199:9200/customer/external/1/_update
参数:
{
"doc": {
"name": "John"
}
}
响应:
{
"_index": "customer",
"_type": "external",
"_id": "1",
"_version": 3,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 5,
"_primary_term": 1
}
再次请求的响应:
{
"_index": "customer",
"_type": "external",
"_id": "1",
"_version": 3,
"result": "noop",# es对比参数完全一致时提示未做任何更改,版本号也不会增加
"_shards": {
"total": 0,
"successful": 0,
"failed": 0
},
"_seq_no": 5,
"_primary_term": 1
}
这种更新会对比数据
请求方式:delete
请求路径:http://192.168.1.199:9200/customer/external/1
响应:
{
"_index": "customer",
"_type": "external",
"_id": "1",
"_version": 4,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 6,
"_primary_term": 1
}
注意:不支持删除类型,可删除索引和文档
支持以下方式做批量数据处理
docker pull kibana:7.4.2
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.1.199:9200 -p 5601:5601 -d kibana:7.4.2
# 直接运行Nginx会自动下载
docker run -p 80:80 --name nginx -d nginx:1.10
# 将容器内的配置文件拷贝到当前目录
docker container cp nginx:/etc/nginx .
# 拷贝之后停止Nginx容器并移除
docker stop nginx
docker rm nginx
# 将/mydata/nginx更改为/mydata/conf
mv nginx conf
# 重新创建nginx目录并将conf移动到nginx目录下
mkdir nginx
mv conf nginx/
# 创建新的nginx
docker run -p 80:80 --name nginx -v /mydata/nginx/html:/usr/share/nginx/html -v /mydata/nginx/logs:/var/log/nginx -v /mydata/nginx/conf:/etc/nginx -d nginx:1.10
标签:sys lan eal 后台 post start https version customer
原文地址:https://www.cnblogs.com/lvbok/p/linux-docker.html