Build common Java environment

Time:2022-5-10

Docker installation

#Docker before uninstalling the system 
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
                  
                  
sudo yum install -y yum-utils

#Configure mirroring
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    
sudo yum install docker-ce docker-ce-cli containerd.io

sudo systemctl start docker
#Set startup and self startup
sudo systemctl enable docker

docker -v
sudo docker images

#Configure mirroring加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xdub84vk.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Docker installing MySQL

#-- name specify container name - V directory mount - P specify port mapping - e set MySQL parameters - d run in the background
sudo docker run -p 3306:3306 --name mysql \
-v /root/app/mysql/log:/var/log/mysql \
-v /root/app/mysql/data:/var/lib/mysql \
-v /root/app/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7


#Enter the inside of the container
docker exec -it 471 bash
whereis mysql
#mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql


#Modify profile
vim /root/app/mysql/conf/my.cnf

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

#Restart
docker restart mysql
#Check whether the configuration file is effective
docker exec -it 471 bash
[email protected]:/# cat /etc/mysql/my.cnf 
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

#Power on
docker update mysql  --restart=always

Docker installs redis

#Create mount directory
mkdir -p /root/app/redis/conf
touch /root/app/redis/conf/redis.conf

#Start
docker run -p 6379:6379 --name redis \
-v /root/app/redis/data:/data \
-v /root/app/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf

#Enter the container
docker exec -it redis redis-cli

#Set the persistence mode of AOF type
vim /root/app/redis/conf/redis.conf
appendonly yes


#Power on
docker update redis  --restart=always

Docker installs es and kibana

#The version should be consistent
docker pull docker.elastic.co/kibana/kibana:7.9.3
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.9.3

mkdir -p /root/app/elasticsearch/config
mkdir -p /root/app/elasticsearch/data
echo "http.host: 0.0.0.0" >/root/app/elasticsearch/config/elasticsearch.yml
chmod -R 777 /root/app/elasticsearch/

#Start
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e  "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-v /root/app/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /root/app/elasticsearch/data:/usr/share/elasticsearch/data \
-v  /root/app/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d docker.elastic.co/elasticsearch/elasticsearch:7.9.3

docker run --name kibana -e ELASTICSEARCH_HOSTS=http://47.112.150.204:9200 -p 5601:5601 -d docker.elastic.co/kibana/kibana:7.9.3

docker update elasticsearch --restart=always
docker update kibana  --restart=always

#Word splitter 
git clone https://github.com/medcl/elasticsearch-analysis-ik
cd elasticsearch-analysis-ik
git checkout tags/{version}
mvn clean
mvn compile
mvn package

Installing nginx

docker run -p80:80 --name nginx -
docker container cp nginx:/etc/nginx .
mkdir nginx
mv conf nginx/
cd nginx

docker run -p 80:80 --name nginx \
 -v /root/app/nginx/html:/usr/share/nginx/html \
 -v /root/app/nginx/logs:/var/log/nginx \
 -v /root/app/nginx/conf/:/etc/nginx \
 -d nginx
 
 docker container cp nginx:/etc/nginx/conf/  /root/app/nginx/conf/

Build common Java environment

Nacos installation

https://github.com/alibaba/nacos

#Start in stand-alone mode
cd /root/app/nacos/bin
sh startup.sh -m standalone