Jenkins

박기원·2022년 7월 27일
0
post-thumbnail

😋 Jenkins & Maven Userdata 😋

#!/bin/bash
timedatectl set-timezone Asia/Seoul
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install -y fontconfig java-11-openjdk
amazon-linux-extras install -y java-openjdk11
yum install -y jenkins git
systemctl enable --now jenkins
cd /opt
wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
tar -xvzf apache-maven-3.8.6-bin.tar.gz
mv apache-maven-3.8.6 maven
cat <<EOF > /home/ec2-user/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc

fi
M2_HOME=/opt/maven
M2=/opt/maven/bin
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.amzn2.0.3.x86_64
# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.amzn2.0.3.x86_64:/opt/maven:/opt/maven/bin

export PATH
EOF
source /home/ec2-user/.bash_profile
yum update -y

📝 Jenkins 설치

Jenkins 다운로드

$ sudo su -
# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
# yum install -y fontconfig java-11-openjdk
# amazon-linux-extras install -y java-openjdk11
# yum install -y jenkins
# systemctl enable --now jenkins
# cat /var/lib/jenkins/secrets/initialAdminPassword

프로젝트 보호 해제

settings - repository - protected branches - unprotected

  • cat으로 passwd를 확인 후 local:8080으로 접속해서 변경한다.

  • 작성한 build 올바르게 출력

🔧 GitHub 플러그인 설치

  • github와 jenkins을 연동 하기위해 GitHubVersion 1.34.4 플러그인 설치함
    [의존성 파일들도 함께 설치된다.]

🔧 GitHub Global Tool Configuration

# yum install -y git

  • git plugin을 설치했지만 jenkins VM에는 git이 없기 때문에 설치해준다.

📝 Maven

# cd /opt
# wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
# tar -xvzf apache-maven-3.8.6-bin.tar.gz
# mv apache-maven-3.8.6 maven
# cd maven
# cd bin

  • maven 실행파일 (mvn) 경로
- 
# cd ~
# find / -name java-11*
- java-11 경로 찾기

# vi .bash_profile
M2_HOME=/opt/maven
M2=/opt/maven/bin
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.amzn2.0.3.x86_64
# User specific environment and startup programs

PATH=$PATH:$HOME/bin:$JAVA_HOME:$M2_HOME:$M2
# echo $PATH
# source .bash_profile
# echo $PATH
# mvn -v

🔧 maven 플러그인 설치

🔧 maven Global Tool Configuration

💡 형상관리

* * * * *
  • 1분 마다 변경사항을 찾아 업로드

😺 Tomcat Server 설치

# hostnamectl set-hostname tomcat-server
# amazon-linux-extras install -y java-openjdk11
# cd /opt
# wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.tar.gz
# tar -xvzf apache-tomcat-9.0.65.tar.gz
# mv apache-tomcat-9.0.65 tomcat
# cd tomcat/bin/
# ./startup.sh
# cd /opt/tomcat
# find / -name context.xml
# vi /opt/tomcat/webapps/host-manager/META-INF/context.xml
<!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
# vi /opt/tomcat/webapps/manager/META-INF/context.xml
<!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
# cd tomcat/bin/
# ./shutdown.sh
# ./startup.sh
# /opt/tomcat/conf
# vi tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="tngjswkr1!" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
<user username="deployer" password="tngjswkr1!" roles="manager-script"/>
<user username="tomcat" password="tngjswkr1!" roles="manager-gui"/>

# ln -s /opt/tomcat/bin/startup.sh /usr/local/bin/tomcatup
# ln -s /opt/tomcat/bin/shutdown.sh /usr/local/bin/tomcatdown
# tomcatdown
# tomcatup

Tomcat😺, Jenkins 🤶 연동

  • Deploy to container 플러그인 설치
  • Jenkins 관리 > Manage Credentials > Credentials (Jenkins) > Global credentials (unrestricted) > Add Credentials

item 생성 시 clean install

빌드 후 조치

Tomcat 첫 페이지 404뜰 때

publish over ssh 플러그인 설치

Jenkins 관리 > 시스템 설정 > SSH Servers

0개의 댓글