在Linux环境下部署(基于Docker容器)
本文主要以图文的形式讲解mall在Linux环境下的部署,涉及在Docker容器中安装MySQL、Redis、Nginx、RabbitMQ、MongoDB、Elasticsearch、Logstash、Kibana,以及SpringBoot应用部署,基于
CenterOS7.6
。
Docker环境安装
- 安装yum-utils:
yum install -y yum-utils device-mapper-persistent-data lvm2
- 为yum源安装docker仓库位置
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 安装docker
yum install docker-ce
- 启动dockery
systemctl start docker
MySQL安装
- 下载MySQL5.7的docker镜像
docker pull mysql:5.7
- 使用如下命令启动Mysql服务
docker run -p 3306:3306 --name mysql2 -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=root
docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
- 参数说明
- -p 3306:3306:将容器的3306端口映射到主机的3306端口
- -v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂在到主机
- -v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机
- -v /mydata/mysql/data:/var/lib/mysql/:将数据文件夹挂载到主机
- -e MYSQL_ROOT_PASSWORD=root:初始化root用户的密码
- 进入运行MySQL的docker容器:
docker exec -it dockermysql /bin/bash
- 使用MySQL命令打开客户端:
mysql -uroot -proot --default-character-set=utf8Copy to clipboardErrorCopied
- 创建mall数据库:
create database mall character set utf8
- 安装上传下载插件,并将
document/sql/mall.sql
上传到Linux服务器上:
yum -y install lrzsz
- 将
mall.sql
文件拷贝到mysql容器的/
目录下:
docker cp /mydata/mall.sql mysql:/Copy to clipboardErrorCopied
- 将sql文件导入到数据库:
use mall;
source /mall.sql;Copy to clipboardErrorCopied
- 创建一个
reader:123456
帐号并修改权限,使得任何ip都能访问:
grant all privileges on *.* to 'reader' @'%' identified by '123456';
springboot
打包容器
docker build -t vueblog .
运行容器
docker run -p 8091:8091 -d vueblog
nginx
docker run --name nginx -d -p 80:80 -v /usr/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/nginx/html:/usr/share/nginx/html -v /usr/nginx/conf.d:/etc/nginx/conf.d nginx
docker cp :/etc/nginx/nginx.conf /usr/nginx/conf/
docker cp :/etc/nginx/conf.d/default.conf /usr/nginx/conf.d
docker run --name nignx -d -p 80:80 -v /usr/nginx/html:/usr/share/nginx/html -v /usr/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/nginx/conf.d:/etc/nginx/conf.d nginx
server {
listen 80;
listen [::]:80;
server_name 10.168.200.61;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /api {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://10.168.200.61:8091/api/;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}