写点什么

Docker 安装

用户头像
Sakura
关注
发布于: 2021 年 02 月 26 日

docker 部署环境相关

搞后台的小伙伴应该都知道,我们部署测试环境或者生产环境都需要经常去下载安装各种环境,原生安装超级耗时!这时候就可以用 docker 来安装 mysql、redis 这些了(如果公司用 K8S 的话,这个就不用看了~)

安装 docker

#安装必要的一些系统工具yum install -y yum-utils#添加软件源信息yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#安装Dockeryum install docker-ce docker-ce-cli containerd.io#开启Docker服务systemctl start docker
复制代码

安装 mysql

#docker安装mysqldocker run -d -e MYSQL_ROOT_PASSWORD=123456 --name mysql5.7 --restart always -v /usr/local/dockerData/mysql/data:/var/lib/mysql -v /usr/local/dockerData/mysql/logs:/logs -v /usr/local/dockerData/mysql/conf:/etc/mysql -e TZ=Asia/Shanghai -p 3306:3306 mysql:5.7
#查看mysql容器iddocker ps
#进入容器 62349aa31687为容器iddocker exec -it 62349aa31687 /bin/bash
#登录mysqlmysql -uroot -p12345
#授权:GRANT ALL ON *.* TO 'root'@'%';
#刷新权限:flush privileges;
#更新加密规则:ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
#更新root用户密码:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
#刷新权限:flush privileges;
#退出mysqlexit;
#退出容器exit;
#mysql5.7默认情况下启动了 ONLY_FULL_GROUP_BY 模式#因此需要在挂载的conf目录下新建my.cnfcd /usr/local/dockerData/mysql/conf
vi my.cnf#写入配置信息
[mysqld]default-storage-engine=INNODBcharacter-set-server=utf8collation-server=utf8_general_cisql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.# If you need to run mysqld under a different user or group,# customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd
#重启mysql容器docker restart 62349aa31687
复制代码

安装 redis

#docker安装redis#开启数据持久化 --appendonly yesdocker run -d --privileged=true -p 6379:6379 --restart always -v /usr/local/dockerData/redis/conf:/etc/redis -v /usr/local/dockerData/redis/data:/data --name myredis redis:5.0-alpine redis-server /etc/redis/redis.conf --appendonly yes
复制代码

安装 rabbitmq

#docker安装rabbitmqdocker run -d --restart always -p 5672:5672 -p 15672:15672 --name rabbitmq -v /usr/local/rabbitmq/data:/var/lib/rabbitmq -e RABBITMQ_DEFAULT_USER=guest -e RABBITMQ_DEFAULT_PASS=guest rabbitmq:3.7.7-management
复制代码

安装 nginx

#在将要挂载的ng配置文件的目录下先创建配置#/usr/local/dockerData/nginx/confcd /usr/local/dockerData/nginx/conf
#创建配置vi 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;}


#启动nginxdocker run -d -p 80:80 --name mynginx --restart=always --privileged=true -v /usr/local/dockerDa
复制代码


用户头像

Sakura

关注

还未添加个人签名 2020.09.22 加入

还未添加个人简介

评论

发布
暂无评论
Docker安装