cicd环境推mysql问题汇总
最终流程说明:
1. dockerfile:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 FROM founder/mysql:5.7 2 COPY my.cnf /etc/mysql/conf.d/my.cnf 3 #ADD 1database.sql /docker-entrypoint-initdb.d/1database.sql 4 5 ADD 2pkubaseentity.sql /home/ 6 ADD 3pkubasetriple.sql /home/ 7 COPY start.sh /docker-entrypoint-initdb.d/ 8 RUN chmod a+x /docker-entrypoint-initdb.d/start.sh 9 10 #ADD 2wisekg.sql /docker-entrypoint-initdb.d/2wisekg.sql
2. start.sh
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#!/bin/bash mysql -uroot -p?? -e "CREATE DATABASE wisekg DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;" mysql -uroot -pasdf -e "use wisekg;source /home/2pkubaseentity.sql;" mysql -uroot -pagad -e "use wisekg;source /home/3pkubasetriple.sql;"
3. docker-compose
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 version: '2' 2 3 services: 4 db: 5 image: founder/nlpmysql:${DOCKER_TAG} 6 restart: always 7 environment: 8 MYSQL_ROOT_PASSWORD: 9 MYSQL_DATABASE: 10 MYSQL_USER: 11 MYSQL_PASSWORD: 12 MYSQL_ALLOW_EMPTY_PASSWORD: 13 ports: 14 - '3306:3306' 15 labels: 16 io.rancher.container.hostname_override: 'container_name' 17 io.rancher.scheduler.affinity:host_label: aimysql=true 18 volumes: 19 - nlp_mysql_data:/var/lib/mysql 20 21 volumes: 22 nlp_mysql_data: 23 driver: ${VOLUME_DRIVER}
4. rancher-compose:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 version: '2' 2 3 catalog: 4 name: Mysql 5 version: 5.7.0 6 description: 方正电子 Mysql 公共镜像 7 category: 数据库 8 uuid: mysql 9 questions: 10 - variable: "MYSQL_DATABASE" 11 label: "数据库名:" 12 required: false 13 default: "test" 14 type: "string" 15 - variable: "MYSQL_ROOT_PASSWORD" 16 label: "Root用户密码:" 17 required: true 18 default: "Founder123" 19 type: "password" 20 - variable: "MYSQL_USER" 21 label: "普通用户名:" 22 required: false 23 default: "founder" 24 type: "string" 25 - variable: "MYSQL_PASSWORD" 26 label: "普通用户密码:" 27 required: false 28 default: "Founder123" 29 type: "password" 30 - variable: "MYSQL_ALLOW_EMPTY_PASSWORD" 31 label: "是否允许密码为空:" 32 required: false 33 default: "no" 34 type: "enum" 35 options: 36 - "yes" 37 - "no" 38 - variable: "VOLUME_DRIVER" 39 label: "存储卷驱动:" 40 description: "选择存储卷驱动类型" 41 required: true 42 default: "rancher-nfs" 43 type: "enum" 44 options: 45 - "rancher-nfs" 46 - "local" 47 48 services: 49 db: 50 scale: 1 51 start_on_create: true 52 health_check: 53 healthy_threshold: 2 54 response_timeout: 2000 55 port: 3306 56 unhealthy_threshold: 3 57 interval: 2000 58 strategy: recreate 59 initializing_timeout: 6000000 60 reinitializing_timeout: 6000000
5. my.cnf
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 [mysqld] 2 character-set-server=utf8mb4 3 collation-server=utf8mb4_unicode_ci 4 max_allowed_packet=200M 5 max_connections=1000 6 connect_timeout=60 7 lower_case_table_names=1 8 innodb_buffer_pool_instances=8 9 innodb_buffer_pool_size = 1G 10 innodb_page_cleaners=8 11 [client] 12 default-character-set=utf8mb4 13 14 [mysql] 15 default-character-set=utf8mb4
问题汇总;
1.
不能把start.sh运行,放到initdb下让他自己运行。
2. 每次重新部署的时候,一定要把之前栈里的服务给删掉,要不然重新部署的时候start.sh不生效。(流程见第3点)
3. 为什么数据不全。
当设置初始化时间6000s时候,发现服务启动成功,但是初始化数据不全。
其实他的流程是这样的: 先初始化mysql,和数据,6000s过后,数据没加载全,那么重新初始化,结果第二次初始化的时候db这个服务名是存在的,所以就没有进行start.sh。导致直接启动了mysql。然后正常running,导致了我们所现在看到了running但是数据不全的场景。