๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/์„œ๋ฒ„ ํ™˜๊ฒฝ

[CentOS 7] Jenkins ์„ค์น˜ :: ๋งˆ์ด์ž๋ชฝ

by ๐ŸŒปโ™š 2018. 8. 30.

jenkins ์„ค์น˜ํ• ๊ฑฐ๋‹ค.

ํ•„์ž๋Š” jenkins๋ฅผ ์‚ฌ์šฉํ•ด๋ณธ์ ์ด ์—†๋‹ค.

์‚ฌ์šฉ์ž๋“ค์˜ ๋ง์— ์˜ํ•˜๋ฉด ๋งค์šฐ ํŽธํ•˜๋‹ค๊ณ  ํ•œ๋‹ค.

๋ฐฐํฌํ•˜๋Š”๋ฐ ์žˆ์–ด์„œ ์ž๋™์œผ๋กœ ๋ฐ˜๋ณต์ ์ธ ์ž‘์—…์„ ๋งŽ์ดํ•ด์ค€๋‹ค๊ณ  ํ•œ๋‹ค.

์ž์„ธํ•œ ์„ค๋ช…์€ ์ดํ•ด๊ฐ€ ์–ด๋Š์ •๋„๋œ ์ƒํƒœ์—์„œ ์ˆ˜์ •ํ•˜๊ฒ ๋‹ค.




jenkins ์„ค์น˜๋ฅผ ์œ„ํ•ด ํ™ˆํŽ˜์ด์ง€๋กœ ๋“ค์–ด๊ฐ„๋‹ค.

https://jenkins.io/download/





์›ํ•˜๋Š” ๋ฒ„์ „ ๊ฒฝ๋กœ๋กœ ๋“ค์–ด๊ฐ„๋‹ค.





jenkins.warํŒŒ์ผ์„ ๋ฐ›๋Š”๋‹ค.



wget์œผ๋กœ warํŒŒ์ผ์„ ์„ค์น˜ํ•˜๊ณ 

์ž๋ฐ” ํด๋”๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์ค€๋‹ค. ์ž๋ฐ” 8์ด์ƒ์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋งŒ๋“ค์–ด์ค„ ํ•„์š” ์—†๋‹ค.

1
2
3
4
5
[jamong@localhost ~]$ cd dev_util/
[jamong@localhost dev_util]$ mkdir jenkins
[jamong@localhost dev_util]$ cd jenkins/
[jamong@localhost jenkins]$ wget http://mirrors.jenkins.io/war-stable/2.89.4/jenkins.war
[jamong@localhost dev_util]$ mkdir java/
cs





์„œ๋ฒ„ ํ™˜๊ฒฝ์„ค์ •์„ ํ•˜๋‹ค๋ณด๋ฉด ํ”„๋กœ๊ทธ๋žจ๋“ค๊ฐ„ ๋ฒ„์ „ ํ˜ธํ™˜์ด ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

ํ•„์ž๋Š” ํ˜„์žฌ ์ž๋ฐ” 7์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์ง€๋งŒ

jenkins๋Š” 2.54๋ฒ„์ „๋ถ€ํ„ฐ ์ž๋ฐ” 8์„ ์‚ฌ์šฉํ•ด์ค˜์•ผ ํ•œ๋‹ค.

์ž๋ฐ” 8 jdk๋ฅผ jenkins/java ํด๋” ์•ˆ์— ๋„ฃ์–ด์ฃผ์ž.

ftp๋“  scp๋“  ๋ญ๋“  ์‚ฌ์šฉํ•ด์„œ ์ž๋ฐ”8์„ ์„ค์น˜ํ•œ๋‹ค.(์ด ๋ถ€๋ถ„์€ ์ƒ๋žต. ์•Œ์•„์„œ ์„ค์น˜ํ•˜๊ธฐ)

1
2
[jamong@localhost jenkins]$ cd java
[jamong@localhost java]$ tar xvfz jdk-8u172-linux-x64.tar.gz
cs






jenkins ์„ค์น˜ ๋ฐ ์‹คํ–‰์„ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ 2๊ฐ€์ง€๊ฐ€์žˆ๋‹ค.

์ฒซ๋ฒˆ์งธ, tomcat์„œ๋ฒ„ ์•ˆ์—๋‹ค warํŒŒ์ผ์„ ๋„ฃ์–ด์„œ ๋ฐฐํฌํ•˜๋Š”๋ฐฉ๋ฒ•์ด ์žˆ๊ณ ,

๋‘๋ฒˆ์งธ, ์ง์ ‘ warํŒŒ์ผ์„ ์‹คํ–‰ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.


ํ•„์ž๋Š” dev_utilํด๋”์•ˆ์— ๋„ฃ์–ด์„œ ์„ค์น˜ํ•œ ํ”„๋กœ๊ทธ๋žจ๋“ค์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๋‘๋ฒˆ์งธ ๋ฐฉ๋ฒ•์„ ์„ ํƒํ•œ๋‹ค.

์ถ”๊ฐ€์ ์œผ๋กœ tomcat ์„œ๋ฒ„์™€ jenkins ๋ฐฐํฌ ์„œ๋ฒ„๋ฅผ ํ•˜๋‚˜์˜ ํฌํŠธ๋กœ ์ ‘๊ทผ๊ฐ€๋Š”ํ•˜๊ฒŒ ํ•˜๋Š”๊ฒƒ์€ ๋ณด์•ˆ์ ์ธ๋ฉด์—์„œ ์ข‹์ง€ ์•Š๋‹ค.





์ง์ ‘ ์‹คํ–‰์„ ํ•ด์ฃผ๊ธฐ ์œ„ํ•ด ์‰˜ํŒŒ์ผ์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์ค„๊ฑฐ๋‹ค.

1
2
[jamong@localhost java]$ cd ..
[jamong@localhost jenkins]$ vi jenkins.sh
cs

์•„๋ž˜์™€ ๊ฐ™์ด ๊ฒฝ๋กœ๋ฅผ ๋งž์ถฐ์„œ ์ž‘์„ฑํ•ด์ฃผ๊ณ  ์ €์žฅํ•œ๋‹ค.

1
2
/home/jamong/dev_util/jenkins/java/jdk1.8.0_172/bin/java -jar /home/jamong/dev_util/jenkins/jenkins.
war --httpPort=9090

cs





9090ํฌํŠธ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ฐฉํ™”๋ฒฝ์„ ๊ฐœ๋ฐฉํ•ด์ค€๋‹ค.

1
2
3
4
5
6
[jamong@localhost jenkins]$ sudo firewall-cmd --zone=public --add-port=9090/tcp --permanent
success
[jamong@localhost jenkins]$ sudo firewall-cmd --reload
success
[jamong@localhost jenkins]$ sudo firewall-cmd --list-ports
22/tcp 3306/tcp 8080/tcp 80/tcp 9090/tcp

cs




์ด์ œ ์‹คํ–‰์„ ํ•˜๊ณ ์‹ถ์ง€๋งŒ... ์‹คํ–‰๊ถŒํ•œ์ด ์—†๋‹ค.

๊ถŒํ•œ์„ ๋ถ€์—ฌํ•œ๋‹ค.

1
2
3
4
5
6
7
8
[jamong@localhost jenkins]$ ls -al
ํ•ฉ๊ณ„ 72564
drwxrwxr-x. 3 jamong jamong       55  8์›” 30 20:36 .
drwxrwxr-x. 7 jamong jamong      107  8์›” 30 20:08 ..
drwxrwxr-x. 3 jamong jamong       26  8์›” 30 20:33 java
-rw-rw-r--1 jamong jamong      122  8์›” 30 20:36 jenkins.sh
-rw-rw-r--1 jamong jamong 74297875  2์›” 13  2018 jenkins.war
[jamong@localhost jenkins]$ sudo chmod 775 jenkins.sh
cs






1
[jamong@localhost jenkins]$ ./jenkins.sh
cs

์ด์ œ ์‹คํ–‰์„ ์™„๋ฃŒํ•˜๊ณ  ์„œ๋ฒ„์•„์ดํ”ผ 9090ํฌํŠธ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•ด๋ณธ๋‹ค.

Unlock Jenkins๋ผ๋Š” ํ™”๋ฉด๊ณผ ํ•จ๊ป˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ผ๊ณ ํ•œ๋‹ค.

์•„๋ž˜ ๋นจ๊ฐ„์ƒ‰ ๊ธ€๋กœ๋œ ๊ฒฝ๋กœ๋ฅผ ๋”ฐ๋ผ๊ฐ€์„œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜๊ฑฐ๋‚˜, ํ„ฐ๋ฏธ๋„์—์„œ๋„ ์ถœ๋ ฅ์ด๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.







๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ ๊ณ„์† ์ง„ํ–‰ํ•˜๋ฉด ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜ํ™”๋ฉด์ด ๋‚˜์˜จ๋‹ค.

๊ทธ๋ƒฅ suggestํ•ด์ฃผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•˜์ž.






ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜ ์™„๋ฃŒ ํ›„ ์•„์ด๋””๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.





์ด์ œ jenkins ์„ค์น˜ ๋!






์  ํ‚จ์Šค๋ฅผ ์‚ฌ์šฉํ•˜์ž.

ํ•„์ž๋„ ์•„์ง ์จ๋ณด์ง€ ์•Š์•˜์ง€๋งŒ, ๊ต‰์žฅํžˆ ํŽธํ•˜๋‹ค๊ณ  ํ•œ๋‹ค.

๊ณต๋ถ€ํ• ๊ฒธ ์„ค์น˜ ๋ฐ ์‚ฌ์šฉํ•ด๋ณด๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.





๋๋‚ด๊ธฐ ์ „์—.... jenkin๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ ์–ด๋ณผ๋ ค๊ณ ํ•œ๋‹ค.

์œ„์˜ ์‹คํ–‰ ๋ฐฉ๋ฒ•์„ background๋กœ ๋Œ๋ ค ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ๋„ ์ƒ๊ด€์—†๋‹ค.

ํ•˜์ง€๋งŒ ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด jenkins์—์„œ ์–ด๋– ํ•œ ์—…๋ฌด๋ฅผ ์ง„ํ–‰ํ–ˆ์„๋•Œ ํ„ฐ๋ฏธ๋„์—์„œ ๊ณ„์† ๋œจ๋Š” ๊ฒƒ์ด ๊ฑฐ์Šฌ๋ฆฐ๋‹ค.


nohup์„ ์‚ฌ์šฉํ•ด์„œ scriptํŒŒ์ผ์„ daemonํ˜•์‹์œผ๋กœ ์‹คํ–‰ํ•ด์ฃผ์ž.





๋จผ์ € log๋ฅผ ์ฐ์„ ์ˆ˜ ์žˆ๊ฒŒ๋” ๋กœ๊ทธํŒŒ์ผ์„  ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์ฃผ์ž.

1
2
3
[jamong@localhost jenkins]$ mkdir logs
[jamong@localhost jenkins]$ cd logs
[jamong@localhost log]$ vi jenkins.log
cs





๋‹ค์‹œ jenkins.sh ํŒŒ์ผ์„ ์ˆ˜์ •ํ•œ๋‹ค.

1
2
[jamong@localhost log]$ cd ..
[jamong@localhost jenkins]$ vi jenkins.sh
cs

์•„๋ž˜์™€๊ฐ™์ด ์ˆ˜์ •ํ•œ๋‹ค.

1
nohup /home/jamong/dev_util/jenkins/java/jdk1.8.0_172/bin/java -jar /home/jamong/dev_util/jenkins/jenkins.war --httpPort=9090 > /home/jamong/dev_util/jenkins/logs/jenkins.log 2>&1&
cs



๋‹ค์‹œ jenkins๋กœ ์ ‘์†ํ•˜๋ฉด ์ด์ƒ์—†์ด ์‹คํ–‰๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

jenkins shutdown์€ ์•„๋ž˜์™€ ๊ฐ™์ด ํ•œ๋‹ค.

1
2
3
4
[jamong@localhost jenkins]$ ps -ef |grep jenkins
jamong    3924     1  3 21:01 ?        00:00:39 /home/jamong/dev_util/jenkins/java/jdk1.8.0_172/bin/java -jar /home/jamong/dev_util/jenkins/jenkins.war --httpPort=9090
jamong    4427  4217  0 21:20 pts/0    00:00:00 grep --color=auto jenkins
[jamong@localhost jenkins]$ kill -9 3924

cs






๋Œ“๊ธ€