Docker中部署容器

*★如果文章对你有帮助【关注点赞❤️收藏⭐】一起努力!★*

‍ 个人主页:花棉袄

版权: 本文由【花棉袄】原创、在CSDN首发、需要转载请联系博主
本章内容:【Docker部署容器

部署Docker

yum 包更新到最新

yum update

安装需要的软件包
yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

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

设置yum源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

安装docker,出现输入的界面都按 y

yum install -y docker-ce

查看docker版本,验证是否验证成功

docker -v

修改镜像地址

vi /etc/docker/daemon.json
  { 
      "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] 
   }

2、部署Maven

2.1、上传或下载安装包

cd/usr/local

apache-maven-3.6.1-bin.tar.gz

2.2、解压安装包

tar -zxvf apache-maven-3.6.1-bin.tar.gz

2.3、建立软连接

ln -s /usr/local/apache-maven-3.6.1/ /usr/local/maven

2.4、修改环境变量

vim /etc/profile

export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin

通过命令source /etc/profile让profile文件立即生效

source /etc/profile

2.5、测试是否安装成功

mvn –v

部署Mysql

拉取镜像

docker pull mysql:5.7

创建文件夹

mkdir /mydata
mkdir /mydata/mysql
mkdir /mydata/mysql/conf/
mkdir /mydata/mysql/logs/
mkdir /mydata/mysql/data/

创建配置文件

[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

创建容器

docker run --restart=always --privileged=true  \
-v /mydata/mysql/data/:/var/lib/mysql \
-v /mydata/mysql/logs/:/var/log/mysql \
-v /mydata/mysql/conf/:/etc/mysql \
-v /mydata/mysql/conf/my.cnf:/etc/mysql/my.cnf  \
-p 3306:3306 --name mysql \
-e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

启动容器

docker start mysql

开启bing-log

4、部署Nacos

4.1、搜索nacos镜像

docker search nacos

4.2、下载镜像

docker pull nacos/nacos-server

4.3、启动镜像

docker run -d -p 8848:8848 --env MODE=standalone  --name nacos  nacos/nacos-server

4.4、验证是否成功

http://192.168.10.11:8848/nacos/#/login
默认用户名密码都是:nacos
Docker中部署容器_第1张图片

5、安装elastic search

5.1、安装elastic search

dokcer中安装elastic search
下载ealastic search(存储和检索)和kibana(可视化检索)
docker pull elasticsearch:7.4.2
docker pull kibana:7.4.2
注意版本要统一

创建文件

mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data

es可以被远程任何机器访问

echo "http.host: 0.0.0.0" >/mydata/elasticsearch/config/elasticsearch.yml
启动Elastic search
9200是用户交互端口 9300是集群心跳端口
-e指定是单阶段运行
-e指定占用的内存大小,生产时可以设置32G
sudo 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 
访问:http://localhost:9200
{
  "name" : "bd7c8ffbfb9f",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "3uOLmzC8S2-4_khhqz-f5w",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

5.2、启动:kibana

sudo docker run --name kibana -e ELASTICSEARCH_HOSTS=http://39.106.95.139:9200  -p 5601:5601 -d kibana:7.4.2

http://localhost:9200 一定是自己虚拟机地址

访问:http://39.106.95.139:5601

Docker中部署容器_第2张图片

5.3、安装分词器

ik分词器放在plugins目录下

chmod -R 777 ik/

使用IK分词器

GET _analyze
{
   "analyzer": "ik_smart", 
   "text":"我是中国人"
}
{
  "tokens" : [
    {
      "token" : "我",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "CN_CHAR",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "中国人",
      "start_offset" : 2,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    }
  ]
}
GET _analyze
{
   "analyzer": "ik_max_word", 
   "text":"我是中国人"
}
{
  "tokens" : [
    {
      "token" : "我",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "CN_CHAR",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "中国人",
      "start_offset" : 2,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "中国",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "国人",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 4
    }
  ]
}

5.4、自定义词库

比如我们要把算作一个词
修改/mydata/elasticsearch/plugins/ik/config中的IKAnalyzer.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
	<comment>IK Analyzer 扩展配置</comment>
	<!--用户可以在这里配置自己的扩展字典 -->
	<entry key="ext_dict"></entry>
	 <!--用户可以在这里配置自己的扩展停止词字典-->
	<entry key="ext_stopwords"></entry>
	<!--用户可以在这里配置远程扩展字典 -->
	<entry key="remote_ext_dict">http://124.223.14.248/es/fenci.txt 
	<!--用户可以在这里配置远程扩展停止词字典-->
	<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

修改完成后,需要重启elasticsearch容器,否则修改不生效。docker restart elasticsearch

以后需要添加新的分词只需要在:/mydata/nginx/html/es/fenci.txt文件中添加即可

echo  "沙玛琪" >> /mydata/nginx/html/es/fenci.txt

部署Nginx

1️⃣本地创建挂载文件夹

mkdir -p /nginx/{logs,conf,html,conf.d}

 在log文件夹下创建

touch /mydata/nginx/logs/{access.log,error.log}

2️⃣创建nginx.conf

 在/mydata/nginx/conf/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

3️⃣创建default.conf

在/mydata/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

4️⃣创建index.html

/mydata/nginx/html/index.html

DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
style>
head>
<body>
<h1>hello docker!h1>
body>
html>

5️⃣创建nginx容器

docker run --name nginx -d -p 80:80  -v /mydata/nginx/log:/var/log/nginx  -v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /mydata/nginx/conf.d:/etc/nginx/conf.d   -v /mydata/nginx/html:/usr/share/nginx/html nginx

访问:http://localhost:80/index.html

你可能感兴趣的:(开发环境配置,docker,容器,运维)