Article Directory
One, Jenkins introduction
It is an open source software tool for continuous integration. Official website: http://jenkins-ci.org/.
Jenkins can implement monitoring integration errors, provide detailed log files and reminder functions, and visually display the trend and stability of project construction in the form of charts.
Features
Easy to install: only one java -jar jenkins.war, After downloading the file from the official website, run it directly, without additional installation, and no database installation;
Easy configuration: Provide a friendly GUI configuration interface;
Change support: Jenkins can obtain and generate code from the code repository (Subversion/CVS) Update the list and output it to the compilation output information;
Permalink support: users access Jenkins through the web, and the link addresses of these web pages are all
JUnit/TestNG test report: that is, to provide detailed charts and other forms Test report function;
Supports distributed build: Jenkins can distribute the integration build and other tasks to multiple computers to complete;
File fingerprint information: Jenkins saves which jars files generated by which integrated build, and which integrated build used which Build records such as version jars files;
Support third-party plug-ins: make Jenkins more and more powerful
Two, install Jenkins
1. Install the JDK environment
Jenkins needs to rely on the JDK environment
2. Download Jenkins
yum -y install wget 这样才能使用wget命令
wget https://pkg.jenkins.io/redhat/jenkins-2.83-1.1.noarch.rpm
3. Install Jenkins
rpm -ivh jenkins-2.83-1.1.noarch.rpm
4. Modify the configuration file
vi /etc/sysconfig/jenkins
设置为如下
JENKINS_USER="root"
JENKINS_PORT="8888"
5. Start the service, access
systemctl start jenkins
Startup failed:
systemctl status jenkins.service
vim /etc/init.d/jenkins
Reboot
systemctl daemon-reload
systemctl start jenkins
6. Browser access
http://localhost:8888/
I deployed it on the Alibaba Cloud server, so I use the public network ip to access. If you are deploying on the local machine, use it localhost
. If it is a virtual machine, use the virtual machine ip address to
view the password:cat /var/lib/jenkins/secrets/initialAdminPassword
7. Install the plugin
If the plug-in download fails, click on the automatic upgrade, and then the address bar localhost:8888/restart to restart
click - "System management - "Manage plug-ins - "Optional plug-ins
Modify the Jenkins plug-in download address
Jenkins foreign official plug-in address download speed is very slow, so you can modify it to the domestic plug-in address: Jenkins->Manage Jenkins->Manage Plugins, click Available
cd /var/lib/jenkins/updates
sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
Finally, click on Manage Plugins and change the Update Site to the domestic plug-in download address https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
After Sumbit, enter: http://192.168.66.101:8888/restart in the browser to restart Jenkins.
Download Chinese Sinicization plugin
Install git plugin
Download the Role-based Authorization Strategy plugin
We can use the Role-based Authorization Strategy plug-in to manage Jenkins user permissions.
Switch the authorization strategy to "Role-Based Strategy" and save
Creating a Role:
Click "Manage Roles"
Global roles: Administrators and other advanced users can create global-based roles. Project roles: Roles for a certain project or certain projects Slave roles: Node-related permissions
We add the following three roles:
- baseRole: The role is a global role. This role needs to be bound to the Read permission under Overall in order to bind the most basic Jenkins access permissions to all users. Note: If you do not bind this role to subsequent users, an error will be reported: Username is missing the Overall/Read permission
- role1: This role is a project role. Use regular expression to bind "wx.*", which means that only items starting with wx can be operated.
- role2: This role is also a project role. Binding "monitor.*" means that only the items at the beginning of monitor can be operated.
Add user
Enter Manage Users on the system management page
Assign roles to users
Enter Manage and Assign Roles on the system management page, and click Assign Roles. The
binding rules are as follows:
eric users are bound to baseRole and role1,
jack users are bound to baseRole and role2 respectively
Create project test permissions
Create two projects with an administrator account, namely wx01 and monitor01. The
result is:
eric user login, can only see wx01 project
jack user login, can only see monitor01 project
Install the Credentials Binding plugin
Credentials can be used to store database passwords that require ciphertext protection, Gitlab password information, Docker private warehouse passwords, etc., so that Jenkins can interact with these third-party applications.
Install the Credentials Binding plug-in To use the credential management function in Jenkins, you need to install the Credentials Binding plug-in.
Click: Manage Credentials --"Global--"Add credentials
After installing the plug-in, there is a "Credentials" menu on the left, where
you can manage all credentials . There are 5 types of credentials that can be added:
- Username with password: username and password
- SSH Username with private key: Use SSH user and key
- Secret file: A text file that needs to be kept secret. When used, Jenkins will copy the file to a temporary directory, and then set the file path to a variable. After the build is completed, the copied Secret file will be deleted.
- Secret text: An encrypted text string that needs to be saved, such as DingTalk or Github api token
- Certificate: By uploading certificate files
Commonly used credential types are: Username with password (user password) and SSH Username with private key (SSH key)
8. Global tool configuration
Configure the JDK directory
Configure Maven
Global tool configuration is associated with JDK and Maven
Manage Jenkins->Configure System->Global Properties, add three global variables
Three, install Gitlab
GitLab is an open source project for warehouse management system. It uses Git as a code management tool and builds a
web service on this basis .
Gitlab installation
- Installation related dependencies
yum -y install policycoreutils openssh-server openssh-clients postfix
- Start ssh service & set to boot
systemctl enable sshd && sudo systemctl start sshd
- Set postfix to start and start automatically after booting. Postfix supports gitlab sending function systemctl enable postfix && systemctl start postfix
- Open ssh and http services, and then reload the firewall list
firewall-cmd --add-service=ssh --permanent
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
If you turn off the firewall, you do not need to do the above configuration.
5. Download the gitlab package and install it
. Download the installation package online:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm
installation:
rpm -i gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm
- Modify gitlab configuration
vi /etc/gitlab/gitlab.rb
Modify the gitlab access address and port, the default is 80, we change it to 82
external_url 'http://192.168.66.100:82'nginx['listen_port'] = 82
- Overload configuration and startup
gitlab gitlab-ctl reconfigure
gitlab-ctl restart
- Add port to firewall
firewall-cmd --zone=public --add-port=82/tcp --permanent
firewall-cmd --reload
After the startup is successful, you will see the following page to modify the administrator root password. After modifying the password, log in
Fourth, install Gogo
Gogs is a self-service Git service that is extremely easy to build.
Gogs' goal is to create the easiest, fastest and easiest way to build self-service Git services. Use Go language development
It’s the same as Git, you can use gogs to build a private git server, and the same is Gitlab Gitlub Gitea...
Install Docker first
yum install -y docker
# 开启DOCKER服务
systemctl start docker.service
# 查看安装结果
docker version
# 设置开机启动
systemctl enable docker.service
# 配置DOCKER镜像下载加速
vim /etc/docker/daemon.json
# 在其中加入加速镜像源地址即可:
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
# 重启 docker 服务即可
systemctl daemon-reload
systemctl restart docker.service
Pull gogs mirror
docker pull gogs/gogs
Create a container
docker run -d --name=gogs -p 10022:22 -p 3000:3000 -v /var/gogsdata:/data gogs/gogs
You will enter the first run of the installer page, we
can choose a database as the storage of gogs data, the simplest is to choose SQLite3. For larger companies, you can choose MySQL.