Install JDK

  1. /usr/local/ JDK /jdk1.8
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"  http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
Copy the code
  1. unzip
tar -zxvf jdk-8u131-linux-x64.tar.gz
Copy the code
  1. Configuring Environment Variables
vi /etc/profile
Copy the code
  1. Append the following to the profile file
Export JRE_HOME=${JAVA_HOME}/jre export =/usr/local/jdk1.8 CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin export PATH=$PATH:${JAVA_PATH}Copy the code
  1. The profile file takes effect again
source /etc/profile
Copy the code
  1. usejava -versionCommand validation; useecho $JAVA_HOMECheck the JAVA_HOME variable after configuration

Install Docker

  1. If an earlier version has been installed, uninstall it first
$ sudo yum remove docker \
                  docker-client \e
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
Copy the code
  1. Installation method:

    • Most users set up and install from Docker’s repository to simplify installation and upgrade tasks. This is the recommended approach.
    • Some users download and manually install RPM packages and complete manual management upgrades, which can be useful in situations such as installing Docker on a blank system with no Internet access.
    • In test and development environments, some users choose to install Docker using automated convenience scripts.
  2. Installation using a repository: Before installing Docker Engine on a new host, you need to set up the Docker repository. After that, you can install and update Docker from the repository.

    1. Setting up the repository
    $ sudo yum install -y yum-utils
    Copy the code
    $ sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
    Copy the code
    1. Install the Docker engine
    $ sudo yum install docker-ce docker-ce-cli containerd.io
    Copy the code
    1. Start the Docker
    $ sudo systemctl start docker
    Copy the code
    1. Set the boot, the following two clock mode can be
    $ sudo systemctl enable docker
    Copy the code
    $ sudo chkconfig docker on
    Copy the code
    1. In order to ensure that the server disk is not filled with Docker logs, it is necessary to limit the container log size in this case

      1. If there is no daemon. Json file, it will be created automatically.
      vi /etc/docker/daemon.json 
      Copy the code
      1. Add the following to the daemon.json file
      {
       "registry-mirrors": ["https://4s5a1mbp.mirror.aliyuncs.com"],
       "log-driver":"none",
       "insecure-registries":["hub.mycompany.com"]
      }
      Copy the code
      • Registry-mirrors specifies the address of the Aris cloud mirror
      • Insecure -registries is the address of our private repository. If we do not configure the address of our private repository, we will get an error in pushing our own image to the private repository
      • If log-driver is set to None, the Docker container will not output logs, preventing the disk from being quickly full (whether this must be configured depends on the case).
    2. Load the configuration file and restart

    systemctl daemon-reload
    systemctl restart docker
    Copy the code
    1. By default, using the docker run command, Docker will randomly assign an Intranet address starting with 172.17. However, with the container being deleted, the IP address will change when the image is run. If fixed IP address is needed, we will create a network on the Docker host according to our situation. (the following command sets the network segment developed with 172.16)
    Docker Network Create -- Gateway 172.16.1.1 --subnet 172.16.1.0/24 appCopy the code

    Use the following command to view our new network

    docker network ls
    Copy the code
    NETWORK ID NAME DRIVER SCOPE 5df024ae25e2 app bridge local 16cf9a89827f bridge bridge local ba0975753843 host host local  557cd83e2872 none null localCopy the code

Install docker-Compose

  1. Run the following command to install
Sudo curl - L "https://github.com/docker/compose/releases/download/1.27.1/docker-compose-$(uname - s) - $(uname -m)" - o /usr/local/bin/docker-composeCopy the code
  1. To apply executable permissions to binaries:
sudo chmod +x /usr/local/bin/docker-compose
Copy the code
  1. Test the installation
$docker-compose --version docker-compose version 1.27.1, build 1110AD01Copy the code
  1. Modify the configuration in the hosts file of the server and add the following content: The IP address and domain name of the Docker image warehouse
vi  /etc/hosts
Copy the code
10.123.123.123 harbor.mycompany.com
Copy the code

Enter the user name and password as prompted to log in

Install Git

yum install git
Copy the code
  1. Pull the project code
Git Clone code managed addressCopy the code
  1. Switch to the target branch
Git checkout -b dev/1.0.1 remotes/origin/dev/1.1.0Copy the code

Install the MySQL database

  1. Run the following command
Docker run -p 3306:3306 --restart=always --net app -- IP 172.16.1.6 -e TZ=Asia/Shanghai - v = / docker/mysql/conf/my CNF: / etc/my CNF - v = / docker/mysql/data: / var/lib/mysql - name mysql5.7 - e MYSQL_ROOT_PASSWORD = 123456 - d mysql: 5.7Copy the code
  1. Remark:
    • Test the connection using the database client, using the IP address of the host.
    • Container to container communication, through--ip 172.16.1.6The specified IP address will serve as the IP address for communication between containers.
  2. Parameters that
-p 3306:3306 specifies the port mapping, host port: container port --restart=always When Docker restarts, the container automatically starts --net app specifies the network connection type of the container, App is the Intranet we created in the previous step -- IP 172.16.1.6 specifies the Intranet of the Docker container IP -e TZ=Asia/Shanghai -e sets the environment variable; Specify mysql time zone - v = / docker/mysql/conf/my CNF: / etc/my CNF mysql container configuration of the specified file mount to the host machine directory - v = / docker/mysql/data: / var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -e Set environment variables; MySQL > set the password of user root to -d and return the container ID --name mysql5.7Copy the code

Install the Nginx server

  1. Run the following command (start parameters are explained as MySQL step)
Docker run - p - 80-80 restart = always -.net app - IP 172.16.1.5 - name nginx - v/docker/nginx/HTML: / usr/share/nginx/HTML -v /docker/nginx/config:/etc/nginx/conf.d -v /docker/nginx/logs:/var/log/nginx/ -d nginxCopy the code
  1. -v /docker/nginx/html:/usr/share/nginx/htmlSpecifies the host address /docker/nginx/ HTML to which the front-end project will be deployed.
  2. To modify the nginx configuration file, you can directly modify the directory mounted to the host (you need to configure the path, agent, etc.), as follows:
server { listen 80; listen [::]:80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } location /data { root /usr/share/nginx/html; } location /prod { root /usr/share/nginx/html; index index.html index.htm; } location /test { root /usr/share/nginx/html; index index.html index.htm; } location /prod { proxy_pass http://prod:8091/prefix; } location /test { proxy_pass http://test:8091/prefix; } #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; #}}Copy the code

Install Maven

  1. Download the version you need (this article installation for 3.6.3) maven.apache.org/download.cg…
  2. Create a destination directory to which you want to install and upload your downloaded zip package to the specified directory
mkdir /usr/local/maven

Copy the code
  1. Run the following command to decompress the compressed file and download it
The tar ZXVF apache maven - 3.6.3 - bin. Tar. GzCopy the code
  1. Edit the configuration file and set the local repository address and remote repository address
<! -- Set warehouse address -->
<localRepository>/usr/local/maven/repository</localRepository>

<! -- Ali Cloud Image Warehouse -->
 <mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>central</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
 </mirror>
Copy the code
  1. Configure maven environment variables

    1. Modifying environment variables
    vi /etc/profile
    
    Copy the code
    1. Add the following
    MAVEN_HOME=/usr/local/maven/apache-maven-3.6.3
    export MAVEN_HOME
    export PATH=${PATH}:${MAVEN_HOME}/bin
    
    
    Copy the code
    1. save
    source /etc/profile
    
    Copy the code
    1. Check the version
    mvn -version
    
    Copy the code

8. Install Jenkins

  1. Install using the War package, in the directory specified by the Jenkins War package
nohup java -jar jenkins.war --httpPort=8081

Copy the code
  1. After the installation is complete, if the port cannot be accessed, the port may not be opened
  2. After Jenkins is installed, you need to install some plugins, such as Maven, Docker, and Docker compose.

Some additional information to configure

  1. The project is divided into development environment and test environment. When we use Jenkins to release the development environment, images will be automatically created and pushed to the image warehouse of the company. In the test environment, we use the Docker compose command to specify the configuration file and deploy the project

  2. After the first release of the project, the project could not connect to the database, because the docker container communication between the project container and the MySQL container. However, the database IP configured in the project was the IP address of the host, so the database could not be accessed

  3. Configure the domain name and IP mapping in the Docker Compose file as follows:

    Extra_hosts: - "gold.mysql.com: 172.16.1.6" - "gold.minio.com: 172.16.1.4"Copy the code

    Gold.mysql.com: Domain name that can be used in the configuration instead of the database address

    172.16.1.6: IP address of MySQL in the Docker Intranet