jenkins的应用与搭建

实验条件2个服务器,

git服务器  ip地址:192.168.200.151

Jenkins服务器 ip地址:192.168.200.132

操作系统:centos7.5

[root@git ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@git ~]# uname -r
3.10.0-862.el7.x86_64
[root@git ~]# systemctl stop firewalld
[root@git ~]# systemctl disable firewalld
[root@git ~]# systemctl stop NetworkManager
[root@git ~]# systemctl disable NetworkManager
[root@git ~]# 

在git服务器上操作

[root@git ~]# yum -y install git

[root@git ~]# useradd git
[root@git ~]# echo "12341234" | passwd --stdin git
Changing password for user git.
passwd: all authentication tokens updated successfully.

用git账号创建项目仓库

[root@git ~]# su - git
[git@git ~]$ mkdir repos
[git@git ~]$ cd repos/
[git@git repos]$ mkdir app.git
[git@git repos]$ cd app.git/
[git@git app.git]$ pwd
/home/git/repos/app.git
[git@git app.git]$ git --bare init
Initialized empty Git repository in /home/git/repos/app.git/
[git@git app.git]$ ls 
branches  config  description  HEAD  hooks  info  objects  refs
[git@git app.git]$ 

在Jenkins服务器上测试推送代码

[root@jenkins ~]# yum -y install git
[root@jenkins ~]# mkdir -p /test
[root@jenkins ~]# cd /test

[root@jenkins test]# git clone [email protected]:/home/git/repos/app.git
Cloning into 'app'...
The authenticity of host '192.168.200.151 (192.168.200.151)' can't be established.
ECDSA key fingerprint is SHA256:gm/RhqGrfDo5Rgcr/LmBAaqPv6tmni7cRpXjGEWZQpg.
ECDSA key fingerprint is MD5:ae:f6:0b:6e:80:96:67:cf:bd:e8:f5:b5:c4:e0:da:11.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.200.151' (ECDSA) to the list of known hosts.
[email protected]'s password:
warning: You appear to have cloned an empty repository.
[root@jenkins test]# ls
app

[root@jenkins test]# cd app
[root@jenkins app]# touch test.sh
[root@jenkins app]# echo "hello" >> test.sh
[root@jenkins app]# git add *
[root@jenkins app]# git commit -m "first"

*** Please tell me who you are.

Run

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@jenkins.(none)')
[root@jenkins app]# git config --global user.email "[email protected]"
[root@jenkins app]# git config --global user.name "cash_su"

扫描二维码关注公众号,回复: 4618047 查看本文章

[root@jenkins app]# git commit -m "first"
[master (root-commit) 731ab6e] first
1 file changed, 1 insertion(+)
create mode 100644 test.sh
[root@jenkins app]# git push -u origin master
[email protected]'s password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/home/git/repos/app.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

给git做一个免秘钥

[root@jenkins app]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:toacG+JZEW1VNmQKQcp9slNyCHCaq55K9Ym82EZcboU root@jenkins
The key's randomart image is:
+---[RSA 2048]----+
|    ..o.+..o*    |
|     = = + + .   |
|    o = B =      |
|     E + B       |
|  ..+ o S        |
|  o+o+.= o       |
| .oooo* o        |
|..o+.+ +         |
|.o+oo .          |
+----[SHA256]-----+
[root@jenkins app]# 
[root@jenkins app]# 
[root@jenkins app]# ssh-copy-id -i ~/.ssh/id_rsa.pub git@192.168.200.151
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
git@192.168.200.151's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[root@jenkins app]# ssh git@192.168.200.151
Last login: Sun Dec 23 13:28:56 2018
[git@git ~]$ exit

准备安装Jenkins

Jenkins官网:https://jenkins.io/

redhat版Jenkins官网下载页面:https://pkg.jenkins.io/redhat-stable/

下载了rpm包以后通过localinstall直接安装

yum -y localinstall 安装包名

利用yum直接安装Jenkins

[root@jenkins app]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
#导入证书秘钥

[root@jenkins app]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

[root@jenkins app]# yum -y install jenkins

#用命令查看安装路径

 
 

[root@jenkins app]# rpm -ql jenkins
/etc/init.d/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins
/usr/lib/jenkins
/usr/lib/jenkins/jenkins.war
/usr/sbin/rcjenkins
/var/cache/jenkins
/var/lib/jenkins
/var/log/jenkins
[root@jenkins app]#

 

安装java

[root@jenkins ~]# tar xf jdk-8u171-linux-x64.tar.gz -C /usr/local/
[root@jenkins ~]# cd /usr/local/
[root@jenkins local]# mv jdk1.8.0_171/ jdk
[root@jenkins local]# vim /etc/profile
[root@jenkins local]# tail -3 /etc/profile
export    JAVA_HOME=/usr/local/jdk/
export    PATH=$PATH:$JAVA_HOME/bin
export    CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

[root@jenkins local]# source /etc/profile
[root@jenkins local]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
[root@jenkins local]#

安装maven

[root@jenkins ~]# tar xf apache-maven-3.5.0-bin.tar.gz -C /usr/local/
[root@jenkins ~]# cd /usr/local/
[root@jenkins local]# mv apache-maven-3.5.0/ maven
[root@jenkins local]# vim /etc/profile
[root@jenkins local]# tail -2 /etc/profile
MAVEN_HOME=/usr/local/maven
export    PATH=${MAVEN_HOME}/bin:$PATH

[root@jenkins local]# source /etc/profile
[root@jenkins local]# mvn -v
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /usr/local/jdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"
[root@jenkins local]#

启动jenkins

[root@jenkins ~]# ln -s /usr/local/jdk/bin/java /usr/bin/
[root@jenkins ~]# systemctl start jenkins
[root@jenkins ~]# ss -antup | grep 8080
tcp    LISTEN     0      50       :::8080                 :::*                   users:(("java",pid=5642,fd=162))
[root@jenkins ~]# 

添加到开机自启

[root@jenkins ~]# systemctl enable jenkins
jenkins.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig jenkins on
[root@jenkins ~]# echo $?
0

开始使用Jenkins

查看解锁码
[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword 6c2b251fde9348e1ba5f3ecd968f0917 [root@jenkins ~]#

使用默认的插件即可

asdsa

猜你喜欢

转载自www.cnblogs.com/cash-su/p/10164287.html