1. This article mainly introduces some configuration in the server during the react+ Egg project construction, which is convenient for direct operation later

2. It mainly adopts the way of Docker to integrate Jenkins automatic deployment, mysql, Redis and so on.

3. It has to be said that the use of Docker greatly reduces the front-end operation of the server environment, making it convenient to get started and rapidly deploy services

1.Docker installation

1.1, install,

 sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
Copy the code
 sudo yum install -y yum-utils device-mapper-persistent-data   lvm2
 sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
Copy the code
 sudo yum install docker-ce docker-ce-cli containerd.io
Copy the code

1.2, start,

Sudo systemctl start docker sudo systemctl enable docker sudo systemctl enable docker sudo systemctl enable dockerCopy the code

1.3. Check the Docker version

docker version
docker info
Copy the code

1.4, unloading

 sudo yum remove docker-ce docker-ce-cli containerd.io

 sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd
Copy the code

2. Aliyun acceleration

Ali mirror acceleration address

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["Https://your own Aliaccelerator address. Mirror.aliyuncs.com"} EOF # reload all modified configuration files//daemon-reload: reloads the configuration file of a service
sudo systemctl daemon-reload
sudo systemctl restart docker
Copy the code

3. Basic docker commands

3.1, mirror

The command meaning
docker image ls Look at mirror
docker search mysql Find the mirror
docker pull docker.io/hello-world Pull the mirror
docker rmi hello-world Remove the mirror

3.2. Container related

Run the container

# Docker run the Ubuntu image and execute /bin/echo in the launched container"Hello world"Command docker run ubuntu /bin/echo"Hello world"
Copy the code
parameter meaning
-i –interactive interactive
-t –tty Assign a dummy terminal
-d –detach Run the container to the background
-a –attach list Attached to the running container
-e –env list Setting environment Variables
-p –publish list Publish container ports to hosts
-P –publish-all
  • Basic commands
The command meaning
docker ps

docker ps -a

docker ps -l
Check the container
Docker kill [container id] Forcibly terminate container
Docker RM [Container ID] Remove the container
Docker start [container id] Start the container
Docker stop [container id] Stop the container
Docker restart [container id] Restart the container
Docker container exec it [container ID] /bin/bash Enter a running container
Docker container cp [Container ID]/readme.md Copy files

Docker-compose installation

sudo curl -L "Https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s) - $(uname -m)"Docker-compose -o /usr/local/bin/docker-compose -o /usr/local/bin/docker-compose -o /usr/local/bin/docker-compose -o /usr/local/bin/docker-compose -o /usr/local/bin/docker-composeCopy the code

4. Install node

The node to download

Upload the file and unzip it

  1. Uploading the Compressed package You can use some software to upload the downloaded NodeJS compressed package (current version: Node-v14.16.1-linux-x64.tar. xz) to any location on the server. It can be /usr/local/src.
  2. Decompress the package:The tar XVF - node - v14.16.1 - Linux - x64. Tar. XzDecompress the package
  3. Decompressed file rename command:Node - mv v14.16.1 - Linux - x64 nodejs
  4. Check file directory integrity: check whether node, NPM, NPX exist. If no, run the preceding command again.

Global references

  1. Creating a Soft connection
ln -s /usr/local/src/nodejs/bin/npm /usr/local/bin
ln -s /usr/local/src/nodejs/bin/node /usr/local/bin
Copy the code

Note: / usr/local/SRC/nodejs this address for installation/bin/NPM nodejs files under the absolute address of NPM and the node location, according to each person is different. Run the node -v command to check whether the command takes effect globally. If the version number is displayed, it indicates success.

5, install mysql

  • docker-compose.yml
version: '3'

services:
  mysql:
    container_name: z_mysql
    image: mysql/mysql-server:5.7
    restart: always
    environment:
      MYSQL_USER: root
      MYSQL_PASSWORD: admin
      MYSQL_DATABASE: database
      MYSQL_ROOT_PASSWORD:  admin
    volumes:
  	  - /data/mysql/data:/var/lib/mysql
 	  - /data/mysql/conf:/etc/mysql/conf.d
 	  - /data/mysql/logs:/logs
    ports:
      - 3306:3306

Copy the code

docker-compose up -d

Docker container exec it [containerId] sh mysql -uroot -p Enter password: xxxx mysql> GRANT ALL PRIVILEGES ON *.* TO'root'@The '%' WITH GRANT OPTION;
// Modify permissions
mysql> FLUSH PRIVILEGES;
// Change the encryption rules. The password never expires
mysql> ALTER USER 'root'@'localhost' IDENTIFIED by 'Self-set password'PASSWORD EXPIRE NEVER; Mysql > ALTER USER'root'@The '%' IDENTIFIED WITH mysql_native_password BY 'Self-set password';
mysql> FLUSH PRIVILEGES;
mysql> exit
Copy the code

6. Install nginx

  • docker-compose.yml
version: "3"

services:
  nginx:
    container_name: nginx
    image: nginx
    privileged: true
    restart: always
    ports:
      - 80:80
    volumes: 
      - /project/nginx/log:/var/log/nginx
      - /project/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - /project/nginx/conf.d:/etc/nginx/conf.d
      - /project/nginx/html:/usr/share/nginx/html
Copy the code

docker-compose up -d

Create conf, conf.d, HTML, and log files on the server

conf/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;
}

Copy the code

conf.d/default.conf

Server {# listen for port LISTEN80; Server_name Specifies the server IP address. # root directory root /usr/share/nginx/html; # set default page index index. HTML; } # interface forward location ~/api/{proxy_pass Forwarding address; }}Copy the code

7. Install Redis

  • docker-compose.yml
version: '3'
 
services:
  redis:
    container_name: 'redis'
    image: 'redis'
    restart: always
    volumes:
      - /data/redis/data:/data
      - /data/redis/conf/redis.conf:/etc/redis/redis.conf
      - /data/redis/logs:/logs
    ports:
      - 6379:6379
    command: redis-server --port 6379 --requirepass password  --appendonly yes

Copy the code

docker-compose up -d

Connect the redis

docker container exec -it redis sh
redis-cli -a password
set a 1
get a // See if it is also 1, if it is, it is successful
Copy the code

8. Install Jenkins

  docker run \
  -itd \
  -u root \
  -p 8080:8080 \
  -v /data/jenkins_home:/var/jenkins_home \
  --name jenkins \
  jenkins/jenkins:lts
Copy the code

8.1 Viewing the Password

Docker logs [container id] docker logs [container id] Docker logs Container ID/ container name Docker execit [container ID] /bin/bash cat /var/jenkins_home/secrets/initialAdminPassword
Copy the code

8.2. Configure Jenkins plug-in acceleration

Go to Jenkins System Administration -> Plug-in Management -> Advanced TAB -> Upgrade site, using Tsinghua source:https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/current/update-center.jsonhttps://mirrors.tuna.tsinghua.edu.cn/jenkins/up dates/current/update-center.json
Copy the code