项目部署步骤
一丶基础配置
安装环境:CentOS 7
1.安装Docker
# 1.卸载旧的版本
yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \dock
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
# 2.需要的安装包
yum install -y yum-utils device-mapper-persistent-data lvm2
# 3.设置镜像仓库
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 4.启动docker
systemctl start docker
# 5.设置开机启动
systemctl enable docker
2.安装MySQL
docker run -p 3306:3306 --name mysql \
-v /opt/data/mysql/log:/var/log/mysql \
-v /opt/data/mysql/data:/var/lib/mysql \
-v /opt/data/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7
docker update --restart=always mysql
# 启动
-d 后台运行
-v 端口映射
-v 卷挂载
-e 环境配置
--name 容器名字
3.安装Redis
docker run -p 6379:6379 --name redis \
-v /opt/data/redis/data:/data \
-d redis \
--requirepass 123456
docker update --restart=always redis
4.安装RabbitMQ
docker run --name rabbitmq \
-e RABBITMQ_DEFAULT_PASS=Qq1442234213 \
-p 5672:5672 \-p 15672:15672 \
-d rabbitmq:management
docker update rabbitmq --restart=always
4.安装Nginx
docker run \
--name web1-nginx \
-v /opt/data/nginx/log:/var/log/nginx \
-v /opt/data/nginx/html:/html \
-p 80:80 \
-d nginx
docker update nginx --restart=always
nginx.conf配置文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
gzip_buffers 4 16k;
gzip_comp_level 9;
gzip_min_length 100k;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
# include /etc/nginx/conf.d/*.conf; 一定要删除这个
server {
listen 80;
server_name localhost;
location ^~/api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://192.168.1.166:9000/;
}
location / {
root /html;
index index.html;
try_files $uri $uri/ /index.html?$query_string;
}
}
}
docker cp /opt/data/nginx/nginx.conf nginx:/etc/nginx/nginx.conf
docker restart nginx
注意:万一安装失败
# 删除
chmod -R 777 /opt/data/nginx
rm -rf /opt/data/nginx
docker stop web-nginx
docker rm web-nginx
cd /opt/data/nginx
cp /opt/data/nginx/dist/* /opt/data/nginx/html/
cp -R /opt/data/nginx/dist/* /opt/data/nginx/html/
docker exec -it nginx bash
ls
# 查看
docker exec -it nginx bash
cat /etc/nginx/nginx.conf
tail -f /opt/data/nginx/log/access.log
做完之后,复制代码到镜像,然后重启Nginx
docker cp /opt/data/nginx/nginx.conf nginx:/etc/nginx/nginx.conf
docker restart nginx
5.部署culture-springboot
Dockerfile
FROM java:8
VOLUME /tmp
ADD *.jar app.jar
ENV TZ=GMT+8
EXPOSE 9000
ENTRYPOINT ["java","-jar","/demo.jar","--spring.profiles.active=prod"]
docker build -t culture:1.0 .
docker run -d -p 9000:9000 --name culture culture:1.0
docker update culture --restart=always
6.部署culture-python
Dockerfile
FROM python:3
RUN pip install gensim -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install pymysql -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install redis -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install pika -i https://pypi.tuna.tsinghua.edu.cn/simple
WORKDIR /app
COPY ./* /app/
COPY ./model/* /app/model/
ENTRYPOINT ["python","./daemon_serve.py","--config","config-prod.ini"]
然后把Python代码Copy到Linux里
docker build -t rec-serve:1.0 .
docker run -d --name rec-serve rec-serve:1.0
docker update rec-serve --restart=always