linux安装docker配置其他

1. 安装docker

准备

更新yum

yum -y update

安装docker所需软件包

yum install -y yum-utils device-mapper-persistent-data lvm2

设置阿里云镜像仓库

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装docker

yum install docker-ce

配置镜像加速

可以都加上
科大镜像:https://docker.mirrors.ustc.edu.cn/
网易:https://hub-mirror.c.163.com/
阿里云:https://<你的ID>.mirror.aliyuncs.com
七牛云加速器:https://reg-mirror.qiniu.com
{
“registry-mirrors”: [
“https://ung2thfc.mirror.aliyuncs.com”,
“https://registry.docker-cn.com”,
“http://hub-mirror.c.163.com”,
“https://docker.mirrors.ustc.edu.cn”
]
}

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["你的加速地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

启动docker

启动
systemctl start docker
设置开机启动
systemctl enable docker

卸载docker

查询安装包

yum list installed | grep docker

删除安装包

yum remove docker*

删除镜像容器

rm -rf /var/lib/docke

2. 安装redis

拉取redis镜像

docker pull redis

查看docker镜像

docker images

创建容器并配置运行

创建宿主机目录
mkdir /usr/local/dockersoft/redis
创建持久化文件目录
mkdir /usr/local/dockersoft/redis/data
将原redis.conf拷贝到这个redis目录下,修改redis.conf配置文件
#bind 127.0.0.1 # 注释掉,即允许远程连接
protected-mode no #启用保护模式

appendonly yes #持久化

requirepass 123456 #密码
docker run -itd --name redis -v /usr/local/dockersoft/redis/redis.conf:/etc/redis.conf -v /usr/local/dockersoft/redis/data:/data -p 6379:6379 redis redis-server /etc/redis.conf
  • 6379:第一个6379是远程指定的端口

  • –name:给容器起一个名

  • -p:端口映射 容器:宿主机

  • -v:挂载自定义配置 自定义配置:容器内部配置

  • -d:后台运行

  • redis-server --appendonly yes: 在容器执行redis-server启动命令,并打开redis持久化配置

  • -e设置环境变量参数,如: -e require-pass=123456

3. 安装nginx

拉取镜像

docker pull nginx

创建本地将要挂载的目录

mkdir /usr/local/dockersoft/nginx
cd /usr/local/dockersoft/nginx
mkdir logs conf html

启动容器

docker run -itd --name nginx -p 80:80 -v /usr/local/dockersoft/nginx/html:/usr/share/nginx/html:ro -v /usr/local/dockersoft/nginx/logs:/var/log/nginx -v /usr/local/dockersoft/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro nginx

4. 安装zookeeper

拉取镜像

docker pull zookeeper

启动容器

docker run -d -p 2181:2181 --name some-zookeeper --restart always zookeeper

5.安装kafka和zookeeper

docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
docker run -d --name zookeeper-12181 -p 12181:2181  -t wurstmeister/zookeeper
docker run -d --name kafka-19092 -p 19092:9092 --link zookeeper-wurstmeister-12181:zookeeper -e KAFKA_BROKER_ID=1  -e HOST_IP=101.33.245.109  -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://101.33.245.109:9092  -e KAFKA_ADVERTISED_HOST_NAME=101.33.245.109 -t  wurstmeister/kafka

部分参数含义:
KAFKA_BROKER_ID=1 kafka在集群中的唯一标识
KAFKA_ZOOKEEPER_CONNECT=zookeeper:12181 监听zookeeper的地址
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.65.7:19092 kafka服务器的地址

进入容器
docker exec -it ${CONTAINER ID} /bin/bash
进入kafka的bin目录下
cd /opt/kafka_2.13-2.8.1/bin
创建topic
./kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic mykafka
查看topic信息-first:topic名
./kafka-topics.sh --zookeeper 192.168.233.129:12181 --describe --topic first
运行生产者
./kafka-console-producer.sh --broker-list localhost:9092 --topic mykafka
消费topic
./kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --from-beginning --topic mykafka

6.安装ElasticSearch

拉取镜像并准备工作

docker pull elasticsearch:7.17.6
docker images
# 创建挂载文件夹
mkdir /usr/local/elasticsearch/config
mkdir /usr/local/elasticsearch/data
mkdir /usr/local/elasticsearch/plugins
# 创建配置文件
vim /usr/local/elasticsearch/config/elasticsearch.yml
#配置yml文件
http.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

# 设置挂载目录权限
chmod -R 777 /usr/local/elasticsearch

分词器(可选)

  1. ik分词器地址:https://github.com/medcl/elasticsearch-analysis-ik
    下载和ElasticSearch版本相同的分词器,将分词器目录放到plugins下,并修改文件夹名称为“ik”
  2. 或者在容器内使用命令
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.6/elasticsearch-analysis-ik-7.17.6.zip

启动容器

docker run --name elasticsearch --restart=always -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-v /usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /usr/local/elasticsearch/data:/usr/share/elasticsearch/data \
-v /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.17.6

配置账号密码

# 进入容器
docker exec -it elasticsearch /bin/bash

# bin目录下,需要输入多次,有都多个账号
./bin/elasticsearch-setup-passwords interactive

你可能感兴趣的:(Linux,docker,linux,其他)