1、安装docker-ce
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
# 注意:
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ce.repo
# 将[docker-ce-test]下方的enabled=0修改为enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
# Loading mirror speeds from cached hostfile
# Loaded plugins: branch, fastestmirror, langpacks
# docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
# docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable
# docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
# Available Packages
# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]
2、安装docker-compose
$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
将可执行权限应用于二进制文件:
$ sudo chmod +x /usr/local/bin/docker-compose
创建软链:
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ docker-compose -v
Docker Compose version v2.2.2
3、编写docker-compose-apollo.yml
2.0以上版本的apollo有配置导出和导入功能,且在mysql 5.7和8.0导入的库和表有大小写的区分,在前期选型时就需要定位好。建议使用最新的版本,方便做配置的导入导出,否则一个个配,真的累!!!!
$ vim docker-compose-apollo.yml
version: "3"
services:
apollo-configservice:
container_name: apollo-configservice
#image: apolloconfig/apollo-configservice:2.2.0
image: apolloconfig/apollo-configservice:1.8.2
restart: always
ports:
- "8080:8080"
volumes:
- "/opt/logs/100003171:/opt/logs/100003171"
environment:
- TZ='Asia/Shanghai'
- SERVER_PORT=8080
- EUREKA_INSTANCE_IP_ADDRESS=10.64.143.41
- EUREKA_INSTANCE_HOME_PAGE_URL=http://10.64.143.41:8080
- SPRING_DATASOURCE_URL=jdbc:mysql://10.64.143.41:3306/apolloconfigdb?useSSL=false&characterEncoding=utf8
- SPRING_DATASOURCE_USERNAME=apollo
- SPRING_DATASOURCE_PASSWORD=apollo
apollo-adminservice:
container_name: apollo-adminservice
#image: apolloconfig/apollo-adminservice:2.2.0
image: apolloconfig/apollo-adminservice:1.8.2
restart: always
ports:
- "8090:8090"
depends_on:
- apollo-configservice
volumes:
- "/opt/logs/100003172:/opt/logs/100003172"
environment:
- TZ='Asia/Shanghai'
- SERVER_PORT=8090
- EUREKA_INSTANCE_IP_ADDRESS=10.64.143.41
- SPRING_DATASOURCE_URL=jdbc:mysql://10.64.143.41:3306/apolloconfigdb?useSSL=false&characterEncoding=utf8
- SPRING_DATASOURCE_USERNAME=apollo
- SPRING_DATASOURCE_PASSWORD=apollo
apollo-portal:
container_name: apollo-portal
#image: apolloconfig/apollo-portal:2.2.0 这里可以根据需求替换不同版本的apollo
image: apolloconfig/apollo-portal:1.8.2
restart: always
ports:
- "8070:8070"
depends_on:
- apollo-adminservice
volumes:
- "/opt/logs/100003173:/opt/logs/100003173"
environment:
- TZ='Asia/Shanghai'
- SERVER_PORT=8070
- EUREKA_INSTANCE_IP_ADDRESS=10.64.143.41
- APOLLO_PORTAL_ENVS=pro #配置env
- PRO_META=http://10.64.143.41:8080 #指定PRO的eureka地址
- SPRING_DATASOURCE_URL=jdbc:mysql://10.64.143.41:3306/apolloportaldb?useSSL=false&characterEncoding=utf8
- SPRING_DATASOURCE_USERNAME=apollo
- SPRING_DATASOURCE_PASSWORD=apollo
4、安装mysql
$ wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
$ rpm -ivh mysql80-community-release-el7-3.noarch.rpm
$ yum -y install mysql-community-server
$ systemctl start mysqld.service
$ grep pass /var/log/mysql/mysqld.log #启动后,会有一个root的初始密码,写入在mysqld.log中
$ mysql -uroot -p
> alter user 'root'@'localhost' identified by 'apollo';
> create user apollo@'%' identified by 'apollo';
5、导入apollo SQL 文件
$ mysql -uroot -p < apolloconfigdb.sql
$ mysql -uroot -p < apolloportaldb.sql
$ mysql -uroot -p
> grant all privileges on ApolloConfigDB.* to 'apollo'@'%' identified by
'apollo';
> grant all privileges on ApolloPortalDB.* to 'apollo'@'%';
> flush privileges;
> exit;
6、启动apollo
$ docker-compose -f docker-compose-apollo.yml up -d
$ docker-compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
apollo-adminservice apolloconfig/apollo-adminservice:1.8.2 "/apollo-adminservic…" apollo-adminservice 18 hours ago Up 18 hours 0.0.0.0:8090->8090/tcp, :::8090->8090/tcp
apollo-configservice apolloconfig/apollo-configservice:1.8.2 "/apollo-configservi…" apollo-configservice 18 hours ago Up 18 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
apollo-portal apolloconfig/apollo-portal:1.8.2 "/apollo-portal/scri…" apollo-portal 18 hours ago Up 18 hours 0.0.0.0:8070->8070/tcp, :::8070->8070/tcp
7、问题发现
在调试过程中,会发现apollo-adminservice注册不到eureka,会提示http://localhost:8080/eureka/访问拒绝,这样是需要去调试依赖,apollo的服务启动是有顺序的:apollo-configservice-->apollo-adminervice-->apollo-portal,这里需要心细去发现问题。如果访问异常,可以通过docker logs -f <container_name>
进行查看日志。