Automated Deployment (gitlab, jenkins)

Keywords: Javascript Vue.js Webpack

The server

CentOS 7.5 64 bit

Install FinalShell software

Connect server

gitlab deployment

Reference website: https://www.cnblogs.com/LUA123/p/9675191.html

  • First check the dependency: sshd
[root@localhost soft]# rpm -qa|grep openssh-server
openssh-server-7.4p1-11.el7.x86_64
[root@localhost soft]# ps -e|grep sshd
  1107 ?        00:00:00 sshd
 12585 ?        00:00:00 sshd
 12590 ?        00:00:00 sshd

If you don't, then

sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
  • Check postfix again
[root@localhost soft]# rpm -qa|grep postfix
postfix-2.10.1-6.el7.x86_64
[root@localhost soft]# ps -e|grep postfix

If you don't, then

sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
  • Finally, find your rpm directory and enter it
[root@localhost soft]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm
--2018-09-19 03:12:09--  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 436017937 (416M) [application/x-redhat-package-manager]
Saving to: 'gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm'

100%[=========================================================================================================================================================>] 436,017,937 1.50MB/s   in 4m 37s 

2018-09-19 03:16:46 (1.50 MB/s) - 'gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm' saved [436017937/436017937]

When downloading https content using wget, an -- no check certificate error will be reported. Just add the – no check certificate parameter after wget, for example:

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm --no-check-certificate
  • see
[root@localhost soft]# ll
total 695524
-rw-r--r--. 1 root root 436017937 Sep  7 01:24 gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm
-rw-r--r--. 1 root root 189756259 Mar 26 07:20 jdk-8u161-linux-x64.tar.gz
-rw-r--r--. 1 root root  49766096 Mar 26 07:20 kafka_2.11-1.0.1.tgz
-rw-r--r--. 1 root root  36668066 Mar 26 07:20 zookeeper-3.4.11.tar.gz
[root@localhost soft]#

If an error is reported, update yum

yum update
  • install
[root@localhost soft]# rpm -ivh gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-11.0.6-ce.0.el7        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
  • Then edit
vim /etc/gitlab/gitlab.rb

Modify url

Enter the server url here (press i on the keyboard to enter the editing mode of linux. After entering, press Esc, and then enter: wq to save and exit)

  • Then execute
gitlab-ctl reconfigure

  • start-up
gitlab-ctl restart
  • View port occupancy
[root@localhost soft]# netstat -tunlp
  • View firewall
[root@localhost soft]#  firewall-cmd --zone=public --list-ports
2888/tcp 3888/tcp 2181/tcp
[root@localhost soft]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost soft]# firewall-cmd --reload
success
  • Open a browser to access

  • Create project

  • Set the SSH Key and configure it on the jenkins server

cd /root
ssh-keygen (always enter,generate ssh secret key)
cd .ssh
cat id_rsa.pub   
take ssh Copy into gitlab Medium
  • On the jenkins server, verify that ssh is valid
cd /soft
git clone  ssh url address

At this point, gitlab has been configured. Next, jenkins

Alibaba cloud deploys jenkins

Reference website: https://www.cnblogs.com/superjie/p/9876028.html

  • Before installing jenkins, the server installs the JDK
yum install java-1.8.0-openjdk

Then install git

yum install -y git

If an error is reported, update yum

yum update
  • 1. Add the official rpm package source for yum installation
 [root@iZbp ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
 [root@iZbp ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
  • Install jenkins using yum or up2date
root@iZbp ~]# yum -y install jenkins
  • 2. Edit the / etc/init.d/jenkins program file of Jenkins and add the java path
    View the absolute path of java environment variables in Linux
[root@iZbp jenkins]# echo $JAVA_HOME
/usr/java/jdk1.8.0_121

Check the jenkins program file and confirm whether the java path is correct. If it is correct, it does not need to be modified;
If it is not correct, modify the absolute path of java, then annotate the default java path, save and exit

 [root@iZbp jenkins]# vim /etc/init.d/jenkins
  66 candidates="
  67 /etc/alternatives/java
  68 /usr/lib/jvm/java-1.8.0/bin/java
  69 /usr/lib/jvm/jre-1.8.0/bin/java
  70 /usr/lib/jvm/java-1.7.0/bin/java
  71 /usr/lib/jvm/jre-1.7.0/bin/java
  72 # /usr/bin/java
  73 # /usr/java/jdk1.8.0_121
  74 
  75 # Add JAVA_HOME/bin/java by liyasong 20170228 
  76 /usr/java/jdk1.8.0_121/bin/java
  • 3. Edit the / etc/sysconfig/jenkins configuration file of jenkins and modify the port and system operation account (edit port: enter the command vim /etc/sysconfig/jenkins, enter the following page, press "i" to edit, press "esc" after editing the port, and then press ": wq" to exit and save)
  [root@iZbp jenkins]# vim /etc/sysconfig/jenkins


The default running user is jenkins and changed to root
The default listening port is 8080, which can be modified by yourself

  • 4. Edit the / etc/profiles file and add the environment variable of jenkins
[root@iZbp jenkins]# vim /etc/profile
export JENKINS_HOME=/var/lib/jenkins

source makes the newly added environment variables in the profile take effect immediately (no restart is required)

[root@iZbp11rfoyeescusr9ha9qZ jenkins]# source /etc/profile
  • Check whether the environment variable is configured successfully
 [root@iZbp11rfoyeescusr9ha9qZ jenkins]# echo $JENKINS_HOME
 /var/lib/jenkins/
  • 5. Start jenkins service
[root@iZbp wwwroot]# service jenkins start
  • At this time, you will find the jenkins.war file under / usr/lib/jenkins / without wget downloading from the official website
[root@iZbp11rfoyeescusr9ha9qZ jenkins]# cd /usr/lib/jenkins/
  [root@iZbp11rfoyeescusr9ha9qZ jenkins]# ls
  jenkins.war
  • View the jenkins log. The last line displays Listed all plugins, indicating that the jenkins service is running normally
  [root@iZbp ~]# vim /var/log/jenkins/jenkins.log  
  #Last line message
  INFO: Listed all plugins
  • 6. Open the browser to access: http://x.x.x.x:9009
    See the following interface, enter the path of the following file in the final shell to view the initial password: vim /var/lib/jenkins/secrets/initialAdminPassword

    At this point, the jenkis installation configuration is ok!

  • Install nodejs plug-in in jenkins and npm14.6.0 in [system configuration]
    Click system management - plug in management - install node
    Click system management - global tool configuration - nodejs to install version 14.6.0

  • mkdir soft cd /soft in the final shell

  • Go back to gitlab, create a new project, transfer the local project to gitlab, copy the gitlab address and put it into the following shell commands, such as git@118.178.234.224:root/test666.git

  • New task

  • Click [configuration] - [build environment] and check provide node & NPM bin / folder to path

  • Click [build], select [add build steps], check [execute shell], enter npm -v in it, and check whether npm is installed

  • Click [build], select [add build steps], check [execute shell], and enter the corresponding packaging command in the shell

echo "Start building the front-end environment"
cd /soft
if [ ! -d "./test666" ]; then
     git clone git@118.178.234.224:root/test666.git
fi
cd test666
git pull
npm install
npm run build
  • Return to the view and click [build now]
    If the build fails, view the console and install the above commands one by one until the build succeeds.



Posted by hasanpor on Mon, 22 Nov 2021 23:15:29 -0800