07-31
0
Docker搭建 nginx+php+mysql+redis
一.创建 /app/www /app/docker_files
二. /app/www 项目目录
三.docker配置目录
1.nginx 创建目录 /app/www/nginx /app/www/nginx/
Dockerfile
from nginx
COPY ./conf/conf.d/ /etc/nginx/conf.d/
COPY ./conf/certs/ /etc/nginx/certs/
COPY ./conf/nginx.conf /etc/nginx/nginx.conf
2.php 创建目录 /app/docker_files/php
Dockerfile
FROM php:8.0-fpm
ENV WWW_PATH "/www"
RUN mkdir ${WWW_PATH}
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean
RUN pecl install redis-5.3.7 && docker-php-ext-enable redis
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
RUN apt-get install -y \
zlib1g-dev \
libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install bcmath
RUN apt-get install -y procps
RUN apt-get install -y vim
RUN apt-get install -y supervisor
WORKDIR ${WWW_PATH}
RUN php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" && php composer-setup.php && php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer
3.redis 创建目录/app/docker_files/redis
Dockerfile
FROM redis
COPY ./redis.conf /usr/local/etc/redis/redis.conf
4.mysql 创建目录 /app/docker_files/mysql /app/docker_files/mysql/conf /app/docker_files/mysql/data
Dockerfile
FROM mysql:5.7
COPY conf/ /etc/mysql/conf.d/
COPY data/ /var/lib/mysql/
EXPOSE 3306
5. docker-comose.yml 配置
version: '3' services: web: build: './nginx' image: 'nginx-server:1.0' container_name: 'nginx-server' ports: - "80:80" - "443:443" volumes: - '/app/docker_files/nginx/conf/nginx.conf:/etc/nginx/nginx.conf' - '/app/docker_files/nginx/conf/conf.d:/etc/nginx/conf.d' - '/app/docker_files/nginx/conf/certs:/etc/nginx/certs' - '/app/www:/usr/share/nginx/html' networks: - lnmp php: build: './php' image: 'php-server:1.0' container_name: 'php-server' ports: - "9000:9000" volumes: - "/app/www:/www" networks: - lnmp redis: build: './redis' image: 'redis-server:1.0' container_name: 'redis-server' ports: - "6379:6379" networks: - lnmp db: build: './mysql' image: 'db-server:1.0' container_name: 'db-server' ports: - "3366:3306" volumes: - "/app/docker_files/mysql/conf:/etc/mysql/conf.d" - "/app/docker_files/mysql/data:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: 123456 networks: - lnmp networks: lnmp: driver: bridge
07-31
0
mysql主从数据库 docker环境
1.配置主库
master.cnf
[mysqld]
# 同一局域网内注意要唯一
server-id=100
# 开启二进制日志功能,可以随便取
log-bin=mysql-bin
查看二进制日志是否开启
SHOW GLOBAL VARIABLES LIKE '%log%';
查看主节点的server id
SHOW GLOBAL VARIABLES LIKE '%server%';
创建有复制权限的用户slave
CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%' IDENTIFIED by '123456';
刷新配置
FLUSH PRIVILEGES;
查看File和Position字段的值
show master status;
2.配置从库
slave.cnf
[mysqld]
server-id=101
#开启二进制日志功能,以备Slave作为其它Slave的Master时使用
log-bin=mysql-slave-bin
#relay_log配置中继日志
relay_log=edu-mysql-relay-bin
停止主从复制
stop slave;
设置主数据库信息
change master to master_host='172.17.0.5', master_user='slave', master_password='123456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=856, master_connect_retry=30;
启动主从复制
start slave;
查看主从同步状态
show slave status;
设置从库只读
# 开启只读
show global variables like "%read_only%";
# 对所有用户生效,包括super用户(不建议使用)
flush tables with read lock;
# 只对普通用户生效,如slave用户
set global read_only=1;
show global variables like "%read_only%";
# 关闭只读
unlock tables;
set global read_only=0;
Docker配置
创建 /app/docker_files/mysql 文件夹
docker-compose.yml 配置文件 放在 /app/docker_files目录下
version: '3'
services:
db-master:
build: './mysql'
image: 'db-server:1.0'
container_name: 'db-master'
ports:
- "3366:3306"
volumes:
- "/app/docker_files/mysql/conf/master.cnf:/etc/mysql/conf.d/master.cnf"
- "/app/docker_files/mysql/data:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: qwe123!@#
command: ["mysqld", "--server-id=1", "--log-bin=mysql-bin"]
networks:
- lnmp
db-slave:
build: './mysql'
image: 'db-server:1.0'
container_name: 'db-slave'
ports:
- "3307:3306"
volumes:
- "/app/docker_files/mysql/conf/slave.cnf:/etc/mysql/conf.d/slave.cnf"
- "/app/docker_files/mysql/slave-data:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: qwe123!@#
command: ["mysqld", "--server-id=2"]
networks:
- lnmp
networks:
lnmp:
driver: bridge
07-05
0
laravel
1.创建一个名为laravel的laravel项目
composer create-project laravel/laravel --prefer-dist ./QZ_20_0712
命令解释:
composer:表示执行该程序;
create-project :创建项目
laravel/laravel:需要创建的项目名称;
–prefer-dist:优先下载压缩包方式,而不是直接从GitHub上下载源码
2.php artisan
(1)数据表
//创建迁移 建表
php artisan make:migration create_demo_table
//重建数据库,在原本的迁移文件中增加字段后执行
php artisan migrate:refresh
//数据表迁移
php artisan migrate
//数据表回滚
php artisan migrate:rollback
(2)功能列表
php artisan list
(3)make 列表
make:cast Create a new custom Eloquent cast class
make:channel Create a new channel class
make:command Create a new Artisan command
make:component Create a new view component class
make:controller Create a new controller class
make:event Create a new event class
make:exception Create a new custom exception class
make:export Create a new export class
make:factory Create a new model factory
make:import Create a new import class
make:job Create a new job class
make:listener Create a new event listener class
make:mail Create a new email class
make:middleware Create a new middleware class
make:migration Create a new migration file
make:model Create a new Eloquent model class
make:notification Create a new notification class
make:observer Create a new observer class
make:policy Create a new policy class
make:provider Create a new service provider class
make:request Create a new form request class
make:resource Create a new resource
make:rule Create a new validation rule
make:seeder Create a new seeder class
make:test Create a new test class
06-13
0
Docker
1.安装Docker
//Centos
yum install docker
2.docker 基础命令
//启动docker
systemctl start docker
//关闭docker
systemctl stop docker
//重启docker
systemctl restart docker
//docker设置随服务启动而自启动
systemctl enable docker
//查看docker 运行状态
systemctl status docker
3.docker 镜像命令
//查看自己服务器中docker 镜像列表
docker images
//搜索镜像
docker search 镜像名
docker search --filter=STARS=9000 mysql 搜索 STARS >9000的 mysql 镜像
//拉取镜像
docker pull 镜像名
docker pull 镜像名:tag
//删除镜像
#删除一个
docker rmi -f 镜像名/镜像ID
#删除多个 其镜像ID或镜像用用空格隔开即可
docker rmi -f 镜像名/镜像ID 镜像名/镜像ID 镜像名/镜像ID
#删除全部镜像 -a 意思为显示全部, -q 意思为只显示ID
docker rmi -f $(docker images -aq)
//强制删除镜像
docker image rm 镜像名称/镜像ID
4.docker 容器命令
//查看正在运行容器列表
docker ps
//查看所有容器 -----包含正在运行 和已停止的
docker ps -a
//运行一个容器
# -it 表示 与容器进行交互式启动 -d 表示可后台运行容器 (守护式运行) --name 给要运行的容器 起的名字 /bin/bash 交互路径
docker run -it -d --name 要取的别名 镜像名:Tag /bin/bash