jenkins

imp url to refer

http://pkg.jenkins-ci.org/redhat/

[root@jenkins ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
–2017-05-04 21:01:23– https://pkg.jenkins.io/redhat/jenkins.repo
Resolving pkg.jenkins.io (pkg.jenkins.io)… 52.202.51.185
Connecting to pkg.jenkins.io (pkg.jenkins.io)|52.202.51.185|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 71
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

100%[======================================================================================================>] 71 –.-K/s in 0s

2017-05-04 21:01:24 (6.99 MB/s) – ‘/etc/yum.repos.d/jenkins.repo’ saved [71/71]

[root@jenkins ~]# sudo rpm –import https://pkg.jenkins.io/redhat/jenkins.io.key
[root@jenkins ~]# yum update -y

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

[root@jenkins ~]# rpm -qa jenkins
jenkins-2.58-1.1.noarch

[root@jenkins ~]# service jenkins status
● jenkins.service – LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)

[root@jenkins ~]# yum install java-1.8.0-openjdk -y

[root@jenkins ~]# java -version
openjdk version “1.8.0_131”
OpenJDK Runtime Environment (build 1.8.0_131-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

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

[root@jenkins ~]# firewall-cmd –zone=public –permanent –add-port=8080/tcp

[root@jenkins ~]# firewall-cmd –reload

[root@jenkins ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 810/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 912/master
tcp6 0 0 :::22 :::* LISTEN 810/sshd
tcp6 0 0 ::1:25 :::* LISTEN 912/master

[root@jenkins ~]# systemctl start jenkins

[root@jenkins ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 810/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 912/master
tcp6 0 0 :::8080 :::* LISTEN 10293/java
tcp6 0 0 :::22 :::* LISTEN 810/sshd
tcp6 0 0 ::1:25 :::* LISTEN 912/master
[root@jenkins ~]# systemctl status jenkins
● jenkins.service – LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: active (running) since Thu 2017-05-04 21:18:20 UTC; 2min 14s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/jenkins.service
└─10293 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /us…

May 04 21:18:19 jenkins systemd[1]: Starting LSB: Jenkins Automation Server…
May 04 21:18:19 jenkins runuser[10279]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
May 04 21:18:20 jenkins jenkins[10278]: Starting Jenkins [ OK ]
May 04 21:18:20 jenkins systemd[1]: Started LSB: Jenkins Automation Server.

[root@jenkins ~]# firewall-cmd –zone=public –permanent –add-service=http

[root@jenkins ~]# firewall-cmd –reload
http://35.184.69.240

jenkins0.png

http://35.184.69.240:8080

jenkins1.png

[root@jenkins ~]# ps aux |grep -i jenkins
jenkins 10293 9.5 5.5 3071580 211044 ? Ssl 21:18 0:21 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war –logfile=/var/log/jenkins/jenkins.log –webroot=/var/cache/jenkins/war –daemon –httpPort=8080 –debug=5 –handlerCountMax=100 –handlerCountMaxIdle=20
root 10455 0.0 0.0 112648 972 pts/0 S+ 21:22 0:00 grep –color=auto -i jenkins

[root@jenkins ~]# telnet localhost 8080
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
helo
HTTP/1.1 400 No URI
Content-Length: 0
Connection: close
Server: Jetty(9.2.z-SNAPSHOT)

Connection closed by foreign host.

[root@jenkins ~]# yum install nginx -y

[root@jenkins ~]# vim /etc/nginx/nginx.conf
location / {
proxy_pass http://127.0.0.1:8080;
}
[root@jenkins ~]# systemctl start nginx

[root@jenkins ~]# systemctl status nginx
● nginx.service – The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2017-05-04 21:29:06 UTC; 1min 10s ago
Process: 10559 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 10556 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 10555 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 10562 (nginx)
CGroup: /system.slice/nginx.service
├─10562 nginx: master process /usr/sbin/nginx
└─10563 nginx: worker process

May 04 21:29:05 jenkins systemd[1]: Starting The nginx HTTP and reverse proxy server…
May 04 21:29:06 jenkins nginx[10556]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
May 04 21:29:06 jenkins nginx[10556]: nginx: configuration file /etc/nginx/nginx.conf test is successful
May 04 21:29:06 jenkins systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
May 04 21:29:06 jenkins systemd[1]: Started The nginx HTTP and reverse proxy server.

jenkins3.png

[root@jenkins ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10562/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 810/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 912/master
tcp6 0 0 :::80 :::* LISTEN 10562/nginx: master
tcp6 0 0 :::8080 :::* LISTEN 10293/java
tcp6 0 0 :::22 :::* LISTEN 810/sshd
tcp6 0 0 ::1:25 :::* LISTEN 912/master

[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
cc7a7f417fbd4a3990d4daa106387398

jenkins4.png

jenkins5jenkins6jenkins7jenkins8jenkins10jenkins11

[root@jenkins ~]# getenforce
Enforcing

[root@jenkins ~]# setenforce 0

[root@jenkins ~]# getenforce
Permissive

[root@jenkins ~]# systemctl restart nginx

[root@jenkins ~]# yum install setroubleshoot-server selinux-policy-devel -y

[root@jenkins ~]# sepolicy network -t http_port_t
http_port_t: tcp: 80,81,443,488,8008,8009,8443,9000

[root@jenkins ~]# semanage port -m -t http_port_t -p tcp 8080

[root@jenkins ~]# sepolicy network -t http_port_t
http_port_t: tcp: 8080,80,81,443,488,8008,8009,8443,9000

[root@jenkins ~]# setenforce 1
[root@jenkins ~]# getenforce
Enforcing
[root@jenkins ~]# systemctl restart nginx jenkins

jenkins12.png
click on Running Jenkins behind NGinx

copy

proxy_redirect default;

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_max_temp_file_size 0;

#this is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#########   Paste it unser location block which should like this ##################
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;

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_max_temp_file_size 0;

#this is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#####################################
[root@jenkins ~]# systemctl restart nginx

####### jenkins-master and agent communication setup #############

[root@jenkins ~]# passwd jenkins
Changing password for user jenkins.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

[root@jenkins ~]# grep jenkins /etc/passwd
jenkins:x:997:995:Jenkins Automation Server:/var/lib/jenkins:/bin/false

[root@jenkins ~]# vim /etc/passwd
jenkins:x:997:995:Jenkins Automation Server:/var/lib/jenkins:/bin/bash

[root@jenkins ~]# su – jenkins
-bash-4.2$ pwd
/var/lib/jenkins
-bash-4.2$

-bash-4.2$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
Created directory ‘/var/lib/jenkins/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
09:57:8e:44:d4:41:58:46:06:53:2b:04:0a:bb:bb:4e jenkins@jenkins
The key’s randomart image is:
+–[ RSA 2048]—-+
| . .+BOX. |
| o . o.B.. |
| . . . + o |
| . o o |
| . S |
| . |
| E |
| . . |
| .o |
+—————–+
-bash-4.2$ ssh-copy-id jenkins@localhost
The authenticity of host ‘localhost (::1)’ can’t be established.
ECDSA key fingerprint is 84:2f:c5:eb:60:1f:61:60:e2:f3:5b:33:78:eb:1d:cc.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
[root@jenkins ~]# grep PasswordAuthentication /etc/ssh/sshd_config
#PasswordAuthentication yes
PasswordAuthentication no

[root@jenkins ~]# vim /etc/ssh/sshd_config
PasswordAuthentication yes

[root@jenkins ~]# grep PasswordAuthentication /etc/ssh/sshd_config
PasswordAuthentication yes
#PasswordAuthentication no

[root@jenkins ~]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service

[root@jenkins ~]# su – jenkins
Last login: Thu May 4 22:52:31 UTC 2017 on pts/0
-bash-4.2$ ssh-copy-id jenkins@localhost
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
jenkins@localhost’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘jenkins@localhost'”
and check to make sure that only the key(s) you wanted were added.

-bash-4.2$ ssh jenkins@localhost
Last login: Thu May 4 22:56:09 2017

[root@jenkins ~]# visudo
root ALL=(ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL

################# On Remote node #######################
[root@node1 ~]# useradd jenkins
[root@node1 ~]# passwd jenkins
Changing password for user jenkins.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

[root@node1 ~]# visudo
root ALL=(ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL

[root@node1 ~]# su – jenkins
[jenkins@node1 ~]$ pwd
/home/jenkins

######################

[root@jenkins ~]# ssh-copy-id -i /var/lib/jenkins/.ssh/id_rsa.pub jenkins@130.211.183.188
The authenticity of host ‘130.211.183.188 (130.211.183.188)’ can’t be established.
ECDSA key fingerprint is 93:81:3c:23:3f:31:ac:fd:69:ab:f9:f6:55:7d:79:82.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
jenkins@130.211.183.188’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘jenkins@130.211.183.188′”
and check to make sure that only the key(s) you wanted were added.

[root@jenkins ~]# ssh jenkins@130.211.183.188
jenkins@130.211.183.188’s password:
Last login: Thu May 4 23:06:45 2017

[jenkins@node1 ~]$ logout
Connection to 130.211.183.188 closed.

[root@jenkins ~]# su – jenkins
Last login: Thu May 4 22:56:52 UTC 2017 from localhost on pts/1

-bash-4.2$ ssh jenkins@130.211.183.188
The authenticity of host ‘130.211.183.188 (130.211.183.188)’ can’t be established.
ECDSA key fingerprint is 93:81:3c:23:3f:31:ac:fd:69:ab:f9:f6:55:7d:79:82.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘130.211.183.188’ (ECDSA) to the list of known hosts.
Last login: Thu May 4 23:09:26 2017 from 240.69.184.35.bc.googleusercontent.com
[jenkins@node1 ~]$

[jenkins@node1 ~]$ sudo -i
[root@node1 ~]#

#############################

Select “New Item” ==>

jenkins13

create folder called ex:mybuilds and save it

jenkins14

jenkins15

click ” create new jobs ” and then select “freestyle project” and give “MyFirstBuild”

jenkins17

select Execute shell from Build drop down

jenkins16.png

give “cat /var/log/messages” in command box and save

jenkins18.png

click on schedule Build for MyFirstBuild

jenkins19.png

give “sudo cat /var/log/messages” in command box and save

jenkins20.png

##################Master & Slave setup ##################

ON MASTER

[root@jenkinsmaster ~]# su jenkins -s /bin/bash
bash-4.2$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
/var/lib/jenkins/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
8e:37:07:37:b0:d9:f2:67:0a:a8:3d:f6:10:23:4d:57 jenkins@jenkinsmaster
The key’s randomart image is:
+–[ RSA 2048]—-+
| E |
| . |
| . o |
| o . = |
| . + S + |
| . * = . |
| + = o o |
| ooo + + |
| …o. . |
+—————–+
bash-4.2$ exit
[root@jenkinsmaster ~]# cat /var/lib/jenkins/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu/tyOraW3psIv73Ur5LAq0TxqVph5C4eyWdIG3VQap+Ey4UstV39Hvu+XQD5cr02RbRiXpptEhDHl7hVpeFola7j8tUG6Gu4ZvP8/QX5gy6x8F0SlrWKomIPGHug0Pc/4pnLf9rdxZ4K7BR7DET99k9lurWlEHDUhYJjqYA9oC62gHw0A/nKHpt86+BcEj2xvLZSNFh+0j+NLYXlV9zw6c3BCrrY6vKGiFowlM6dFHwvadE17UoRf+YuWi/Gqr/+08PTb+ybL6UVYq+ubWFQciXR/wUsMb/+aMI0v8Wbl78Bi8uRXEIFE8lg2rtCILr6lhW9qNe4xYkM/2KEF1osn jenkins@jenkinsmaster

ON SLAVE

[root@jenkinsslave ~]# yum install java-1.8.0-openjdk -y

[root@jenkinsslave ~]# useradd -d /var/lib/jenkins jenkins
[root@jenkinsslave ~]# mkdir /var/lib/jenkins/.ssh
[root@jenkinsslave ~]# vim /var/lib/jenkins/.ssh/authorized_keys

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s