Wednesday 31 January 2018

Jenkins on Amazon Linux(EC2 Instance)/CentOS



Jenkins on Amazon Linux(EC2 Instance)/CentOS

I have written a useful blog in very simple and understandable way to install the jenkins on Amazon Linux(EC2 Instance)/CentOS, below are the steps and command that need to install and run jenkins on above Linux flavor.

Step 1: Best practice to update Linux before installing the application but it is optional.
  • sudo yum install epel-release
  • sudo yum update
  • sudo reboot

Step 2: Install Java 8 and make it in operation, if java 7 is there then jenkins would not work, java8 needs to be installed and java 7 need to be removed.
  • sudo yum install -y java-1.8.0-openjdk.x86_64
  • sudo /usr/sbin/alternatives --set java /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
  • sudo /usr/sbin/alternatives --set javac /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/javac
  • sudo yum remove java-1.7

Step 3: Set the Environment for JVM.
  • sudo cp /etc/profile /etc/profile_backup
  • echo 'export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk' | sudo tee -a /etc/profile
  • echo 'export JRE_HOME=/usr/lib/jvm/jre' | sudo tee -a /etc/profile
  • source /etc/profile

Step 4: Verify Java version and Java environment.
  • java -version
  • echo $JAVA_HOME
  • echo $JRE_HOME

Step 5: Install Jenkins on Amazon Linux/CentOS
  • cd ~
  • sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
  • sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
  • yum install jenkins
  • sudo service  jenkins enable
  • sudo service  jenkins start
  • sudo service  jenkins status

Step 6: Run your Jenkins via web browser.
  • http://server_ip:8080

Step 7: Unlock jenkins by supplying password created during installation, To find the password "sudo cat  /var/lib/jenkins/secrets/initialAdminPassword"


Step 8: Now all the steps done, just click on install suggested plugins to get started.


Now you have done the job, I want to give some more additional useful details here.

Command to run jenkins on different port rather than default: java -jar jenkins.war --httpPort=8081
Home directory for jenkins on Amazon Linux/Centos: /usr/lib/jenkins
Config file: /etc/sysconfig/jenkins
                 /var/lib/jenkins/
jenkins user config file path: /var/lib/jenkins/users/user_name