ruyu-blog部署详细教程
版权声明
本着开源共享、共同学习的精神:
本文是在 博主Ruyu 文章:《项目部署文档》https://www.kuailemao.xyz/article/48 基础上增加了自己实践过程的一些细节,转载无需和我联系,但请注明文章来源。如果侵权之处,请联系博主进行删除,谢谢~
环境准备
1.1.安装Docker
官方网站地址:https://docs.docker.com/engine/install/#server 命令:
下载所需工具包
sudo yum install -y yum-utils
遇到的问题:
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
One of the configured repositories failed (未知),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
这个问题是由于无法解析CentOS镜像列表的主机名导致的,通常是 网络问题或DNS配置不正确造成的。下载阿里云的repo文件,然后再次验证:sudo yum install -y yum-utils
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者参考:linux镜像源错误
设置阿里云镜像源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1.1.1安装 Docker Engine(遇到选择一路按y回车)
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
启动 Docker 服务
sudo systemctl start docker
测试是否安装成功(正确显示版本表示安装成功)
docker -v
1.1.2设置国内镜像
vi /etc/docker/daemon.json
添加以下代码:
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com",
"https://hub.uuuadc.top",
"https://docker.anyhub.us.kg",
"https://dockerhub.jobcher.com",
"https://dockerhub.icu",
"https://docker.ckyl.me",
"https://docker.awsl9527.cn",
"https://docker.m.daocloud.io"
],
"live-restore": true
}
或者
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker.m.daocloud.io",
"https://docker.1panel.top"
],
"live-restore": true
}
或者
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://noohub.ru",
"https://huecker.io",
"https://dockerhub.timeweb.cloud",
"https://0c105db5188026850f80c001def654a0.mirror.swr.myhuaweicloud.com",
"https://5tqw56kt.mirror.aliyuncs.com",
"https://docker.1panel.live",
"http://mirrors.ustc.edu.cn/",
"http://mirror.azure.cn/",
"https://hub.rat.dev/",
"https://docker.ckyl.me/",
"https://docker.chenby.cn",
"https://docker.hpcloud.cloud",
"https://docker.m.daocloud.io"
],
"live-restore": true
}
镜像源地址来源于:https://blog.csdn.net/jundao1997/article/details/141756747
Docker/DockerHub 国内镜像源/加速列表(长期维护 0926更新):https://cloud.tencent.com/developer/article/2454486
添加好后按下esc,然后输入:wq 退出保存
依次执行以下命令,重新启动 Docker 服务。
systemctl daemon-reload
service docker restart
检查是否生效
docker info
是否有以下信息:
1.1.3安装 Docker Compose
下载地址:https://github.com/docker/compose/releases/download/1.28.6/docker-compose-Linux-x86_64 下载后把文件重命名docker-compose !!!
cd /usr/local/bin
rz #直接通过rz导入文件
验证码是否上传成功
将可执行权限应用于二进制文件:
sudo chmod +x /usr/local/bin/docker-compose
测试是否安装成功:
docker-compose --version
测试是否安装成功:
遇到问题------(本人部署过程中没有遇到过)
- 报错 Error: Nothing to do
解决办法,更新yum源:
yum -y update
1.2部署Mysql
依次执行创建挂载目录
mkdir -p /data/mysql/data;
mkdir -p /data/mysql/conf;
创建yml文件
vim /data/mysql/docker-compose.yml
填入配置,添加好后按下esc,然后输入:wq 退出保存
注意坑!!!填写配置检测前面是不是没有黏贴上,建议用FinalShell自带文本编辑器
version: '3'
services:
mysql:
image: mysql:8.0 #mysql版本
container_name: mysql
volumes:
- /data/mysql/data:/var/lib/mysql
- /data/mysql/conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: 123456 #root用户密码
TZ: Asia/Shanghai
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
创建Mysql配置文件
vim /data/mysql/conf/my.cnf
点击展开
[mysqld]
default-storage-engine=INNODB # 创建新表时将使用的默认存储引擎
character-set-server=utf8mb4 # 设置mysql服务端默认字符集
pid-file = /var/run/mysqld/mysqld.pid # pid文件所在目录
socket = /var/run/mysqld/mysqld.sock # 用于本地连接的socket套接字
datadir = /var/lib/mysql # 数据文件存放的目录
symbolic-links=0
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION # 定义mysql应该支持的sql语法,数据校验等!
允许最大连接数
max_connections=200
同一局域网内注意要唯一
server-id=3306
开启二进制日志功能 & 日志位置存放位置`/var/lib/mysql`
#log-bin=mysql-bin
log-bin=/var/lib/mysql/mysql-bin
binlog格式
1. STATEMENT:基于SQL语句的模式,binlog 数据量小,但是某些语句和函数在复制过程可能导致数据不一致甚至出错;
2. MIXED:混合模式,根据语句来选用是 STATEMENT 还是 ROW 模式;
3. ROW:基于行的模式,记录的是行的完整变化。安全,但 binlog 会比其他两种模式大很多;
binlog_format=ROW
FULL:binlog记录每一行的完整变更 MINIMAL:只记录影响后的行
binlog_row_image=FULL
日志文件大小
max_binlog_size=100M
定义清除过期日志的时间(这里设置为7天)
expire_logs_days=7
================= ↑↑↑ mysql主从同步配置end ↑↑↑ =================
[mysql]
default-character-set=utf8mb4
[client]
default-character-set=utf8mb4 # 设置mysql客户端默认字符集
#cd到对应目录下
cd /data/mysql
#创建容器并启动
docker-compose up -d
看见以下信息代表成功
记得防火墙开对应的端口号 !!! 一定要记得换端口和复杂密码,不然等着被比特币勒索!!!
navicate测试链接成功
最后新建一个blog数据库,我已经新建了blog数据库,图中为演示。把项目目录下的sql文件放进去运行!!!
1.3.部署Redis
创建挂载目录
mkdir -p /data/redis
创建yml文件
vim /data/redis/docker-compose.yml
填入配置,添加好后按下esc,然后输入:wq 退出保存
注意坑!!!填写配置检测前面是不是没有黏贴上,建议用FinalShell自带文本编辑器
version: '3'
services:
redis:
image: redis:7.2.3
container_name: redis
restart: always
ports:
- 6379:6379
volumes:
- /data/redis/redis.conf:/etc/redis/redis.conf
- /data/redis/data:/data
- /data/redis/logs:/logs
command: ["redis-server","/etc/redis/redis.conf"]
创建挂载的配置文件
vim /data/redis/redis.conf
注意:protected-mode no 不加,无法连接!
protected-mode no
port 6379
timeout 0
#rdb配置
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /data
appendonly yes
appendfsync everysec
#设置你的redis密码
requirepass 123456
到对应目录下启动容器
cd /data/redis
docker-compose up -d
#如果需要强制重新构建
docker-compose up --force-recreate -d
看见以上信息代表成功
记得防火墙开启对应的端口!!!
使用工具测试连接
1.4.部署RabbitMQ
docker pull rabbitmq