Our open source blog project, EBlog, has been updated. Today, we use the installation method of Docker to install our project, the experimental environment is centos 7 system, this experiment is suitable for deploying most of the Springboot project.
Eblog Project Address:
Github.com/MarkerHub/e…
Install the docker
# installation
yum install docker
Verify that the installation was successful
[root@localhost opt]# docker --version
Docker version 1.13.1, build 7f2769b/1.13.1
# start
systemctl start docker
Change the mirror sourceSudo vim /etc/docker-daemon. json: {"registry-mirrors": ["https://m9r2r2uj.mirror.aliyuncs.com"} Save and exit, and restart the Docker# to restart
systemctl restart docker
Copy the code
Install redis
First, go to dockerHub to search for Redis, click to enter the details page, and then pull down to see how to use. If you need to select a specific version, there are Supported tags for us to choose, and if you want to select the latest version, pull down the following tutorial.
- hub.docker.com/_/redis
# pull image of Redis
docker pull redis
# View the local Redis image
docker images
# run redis
docker run --name myredis -p 6379:6379 -d redis redis-server --appendonly yes
Copy the code
- Docker run means run
- –name myredis: name myredis
- -p 6379:6379 Maps the server’s 6379 to the Docker’s 6379 port, so that the docker’s port can be accessed through the server’s port
- -d runs Redis as a backend service
- Redis redis-server –appendonly yes Indicates that persistent caching is enabled and can be saved to the hard disk
Mysql installation
- hub.docker.com/_/mysql
MYSQL_ROOT_PASSWORD=admin Indicates the initial password of root
Mysql :5.7.27 mysql:5.7.27 mysql:5.7.27
Docker pull mysql:5.7.27 docker run --name mymysql-e MYSQL_ROOT_PASSWORD=admin -d3306-3306 - p mysql: 5.7.27Copy the code
Connect to mysql, create database eblog, and import database script. Script location: github.com/MarkerHub/e…
Install the RabbitMq
RABBITMQ_DEFAULT_PASS=password RABBITMQ_DEFAULT_PASS=password
docker run -d --hostname my-rabbit --name myrabbit -e RABBITMQ_DEFAULT_USER=root -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 rabbitmq:management
Copy the code
Install the ElasticSearch
Docker install Elasticsearch6.4.3 and Chinese plug-in install.
The system configuration
Otherwise, the startup may fail
Max virtual memory areas Vm. max_map_count [65530] is too low, increase to at least [262144].
Solution:
- sudo sysctl -w vm.max_map_count=262144
Start the ES
- Docker run -p 9200:9200 -p 9300:9300 -d –name ES_643 ElasticSearch :6.4.3
Into the mirror
- docker exec -it es_643 /bin/bash
Es configuration file location: / usr/share/elasticsearch/config/elasticsearch. Yml
Install Chinese word segmentation plug-in
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.3/elasticsearch-analysis-ik-6.4.3.zip
Copy the code
Exit and restart the image
- exit
- docker restart es_643
Build a Docker image of eblog
Next, we need to clone the eBlog blog project and package it into a JAR package.
clone https://github.com/MarkerHub/eblog.git
cd eblog
# packaged
mvn clean package -Dmaven.test.skip=true
Copy the code
Then upload the project eblog-0.0.1- snapshot. jar package to the same directory as eblog-0.0.1- snapshot. jar on the server and create a file named Dockerfile.
As follows:
- Dockerfile
FROM java:8
EXPOSE 8080
VOLUME /tmp
ENV TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/{TZ} /etc/localtime && echo "{TZ}"> /etc/timezone ADD eblog-0.0.1 -snapshot.jar /app.jar RUN bash -c'touch /app.jar'
ENTRYPOINT ["java"."-jar"."/app.jar"]
Copy the code
- FROM Java :8 Indicates the JDK8-based environment
- EXPOSE 8080 Indicates that port 8080 is exposed to the public
-
- VOLUME/TMP indicates that the directory is mounted to/TMP
- ADD eblog-0.0.1 -snapshot. jar /app.jar to copy the JAR package to the root directory of the image service and change the name of the jar package to app.jar
- RUN bash -c ‘touch /app.jar’ : creates app.jar
- ENTRYPOINT [” Java “,”-jar”,”/app.jar”] Indicates to run the java-jar command
Eblog-0.0.1 – snapshot. jar is a docker image.
# build image, notice the dot behind it.
docker build -t eblog .
# mirror
docker images
Copy the code
After this step is completed, we can finish the preparation work, and then we can directly start our project.
Start the eblog project
The startup command is as follows:
docker run -p 8080:8080 -p 9326:9326 --name eblog --link es_643:ees --link myrabbit:erabbit --link mymysql:emysql --link myredis:eredis-d eblog
Copy the code
-p 8080:8080 -p 936:936:9326 Is the WS port used for instant chat –link es:ees indicates the associated container, and alias the container ES as ees
View eblog print logs
docker logs -f eblog
Copy the code
Then we can access our project through port 8080!!
This project runs successfully!!
conclusion
Docker Compose is easier to compose!
Video presentation
Link: www.bilibili.com/video/BV1dk…
To a quality three even ha, for attention!!