How to Install Jenkins on CentOS 7

Jenkins is a free and open source CI (Continuous Integration) tool which is written in JAVA. Jenkins is widely used for project development, deployment, and automation. Jenkins allows you to automate the non-human part of the whole software development process. It supports version control tools, including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, ClearCase and RTC, and can execute Apache Ant, Apache Maven and sbt based projects as well as arbitrary shell scripts and Windows batch commands. The creator of Jenkins is Kohsuke Kawaguchi.[3] Released under the MIT License.

Jenkins' security depends on two factors: 1. access control 2. protection from external threats.

Access control can be customized via two ways, user authentication and authorization.

Protection from external threats such as CSRF attacks and malicious builds is supported as well.

Requirements

It does not require any special kind of hardware, you'll only need a CentOS 7 server and a root user access over it. You can switch from non root user to root user usingsudo -icommand.

Update System

It is highly recommended to install Jenkins on a freshly updated server. To upgrade available packages and system run below given command and it'll do the job for you.

yum -y update

Install Java

Before going through the installation process of Jenkins you'll need to set up Java Virtual Machine or JDK to your system. Simply run following command to install Java.

yum -y install java-1.8.0-openjdk.x86_64

Once installation is finished you can check the version to confirm the installation, to do run following command.

java -version

The above command will tell you about the installation details of java. By running the above command you should see the following result on your terminal screen.

openjdk version"1.8.0_131"OpenJDK Runtime Environment(build 1.8.0_131-b12)OpenJDK 64-Bit Server VM(build 25.131-b12, mixed mode)

Next, you'll need to setup two environment variablesJAVA_HOMEandJRE_HOMEand to do so run following commands one by one.

cp /etc/profile /etc/profile_backupecho 'export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk' | sudo tee -a /etc/profileecho 'export JRE_HOME=/usr/lib/jvm/jre' | sudo tee -a /etc/profilesource /etc/profile

Finally print them for review using following commands.

echo $JAVA_HOME

You should see following output.

/usr/lib/jvm/jre-1.8.0-openjdk

echo $JRE_HOME

Install Jenkins

We have installed all the dependencies required by Jenkins and now we are ready to install Jenkins. Run following commands to install latest stable release of Jenkins.

wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.reporpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

The above two commands will add the jenkins repository and also import the key. If in case you have previously imported the key from Jenkins then therpm --importwill fail because you already have a key. Please ignore that and move on.

Now run following command to install Jenkins on your server.

yum -y install jenkins

Next, you'll need to start Jenkins services and set it to run at boot time and to do so use following commands.

systemctl start jenkins.servicesystemctl enable jenkins.service

Jenkins runs on port 8080 so you'll need to change firewall rules to allow traffic on port 8080.

If in case you don't have firewalld services installed on your server then you can install it usingyum -y install firewalldand you can start it usingsystemctl start firewalld

Next run these below given command to modify the firewalld rules.

firewall-cmd --zone=public --permanent --add-port=8080/tcpfirewall-cmd --reload

Web Access

Open up your favorite web browser and please visit http://YourServerIPaddress:8080 and finish the installation wizard.

You'll see a webpage like this which will ask you for a password and this admin password is created and stored in the log file/var/log/jenkins/jenkins.log.

Run the below command to get the password.

grep -A 5 password /var/log/jenkins/jenkins.log

Copy the password and paste it in above windows and click onContinuebutton.

Next, you'll see a setup wizard web page like this and Select the option :Install suggested plugins. It will install required plugins for Jenkins.

Next, it will ask you to create an Admin User so provide your username and password and email address and then finally click onSave and Finishbutton.

On the next page click onStart using Jenkinsbutton and you'll see a Jenkins user dashboard.

Install Nginx

You can install nginx as reverse proxy for Jenkins, so visitors will no longer need to key in the port number 8080 when accessing your Jenkins application. run following command to install nginx.

yum -y install nginx

Next, you'll need to edit the configuration details using any text editor here we are using nano text editor. you can also install it usingyum -y install nano

nano /etc/nginx/nginx.conf

Find these lines in the configuration file:

location /{}

Add following content into the { } segment in configuration file then save the file and exit from the text editor.

proxy_pass http://127.0.0.1:8080;proxy_redirect off;proxy_set_header Host$host;proxy_set_header X-Real-IP$remote_addr;proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto$scheme;

Next, start the nginx services and enable it to run at boot time like we have done before for Jenkins services using following commands.

systemctl start nginx.servicesystemctl enable nginx.service

Finally you'll need to modify firewall rules using following commands.

firewall-cmd --zone=public --permanent --add-service=httpfirewall-cmd --reload

Now you can access it through a web browser via http://yourServerIP .

Conclusion

In tutorial you learned to how to install and configure Jenkins on your CentOS 7 server. You also learned to install nginx and setting it up with Jenkins. We hope now you have enough knowledge to work with Jenkins.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,723评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,485评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,998评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,323评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,355评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,079评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,389评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,019评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,519评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,971评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,100评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,738评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,293评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,289评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,517评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,547评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,834评论 2 345

推荐阅读更多精彩内容