Jenkins+Ansible installation and deployment

Keywords: jenkins Python ansible Gradle

1, Environmental description

Operating system: CentOS 7.5 x86 ʄ

JAVA version: jdk-8u181

Jenkins version: jenkins-2.134

Ansible version: ansible-2.3.3.0

2, Preparation before configuration

# systemctl disable firewalld.service
# systemctl stop firewalld.service
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# setenforce 0
# hostnamectl --static set-hostname  jenkins-ansible

3, Install Jenkins

1. Configure JAVA environment variables

# tar -zxvf jdk-8u181-linux-x64.tar.gz -C /opt

# cat > /etc/profile.d/jdk.sh <<EOF
# Java environment configuratione
export JAVA_HOME=/opt/jdk1.8.0_181
export JAVA_BIN=/opt/jdk1.8.0_181/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
EOF
 
# source /etc/profile.d/jdk.sh

2. Add jenkins source and install

# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key

# yum -y install jenkins

Configure the java configuration file

# vi /etc/sysconfig/jenkins
JENKINS_JAVA_CMD="/opt/jdk1.8.0_181/bin/java"

Modify the default port number:
JENKINS_PORT="8888"
Cannot be changed to a port below 1024

Note: the directory where Jenkins works, the address where the files are stored, the plug-ins, and the generated files are all in this directory. The users of JENKINS HOME= "/var/lib/jenkins" and Jenkins have the permissions of $JENKINS HOME and /var/log/jenkins

3. Start jenkins

# systemctl daemon-reload
# systemctl enable jenkins
# systemctl start jenkins
# systemctl status jenkins

4. Install git, maven and gradle

Install git

yum -y install git

Download and install gradle

# unzip gradle-4.6-all.zip

# vi /etc/profile.d/gradle.sh
# Gradle environment configuratione
export GRADLE_HOME=/opt/gradle-4.6
export GRADLE_BIN=/opt/gradle-4.6/bin
export PATH=$PATH:$GRADLE_HOME/bin
export CLASSPATH=.:$GRADLE_HOME/lib

# source /etc/profile.d/gradle.sh
# gradle -v

Download and install maven

# tar -zxvf apache-maven-3.5.2-bin.tar.gz
# mv apache-maven-3.5.2-bin /opt/maven3.5.2

# vi /etc/profile.d/maven.sh
# Maven environment configuratione
export M2_HOME=/opt/maven3.5.2
export PATH=$M2_HOME/bin:${PATH}

# source /etc/profile.d/maven.sh
# mvn -version

4, Install Ansible

1. Install dependency package

yum install zlib-devel bzip2-devel  openssl-devel gcc python-devel

2.Download and install the setuptools module

# unzip setuptools-38.5.1.zip
# cd setuptools-38.5.1
# python setup.py install

3.Download and install pycrypto module

# tar -zxvf pycrypto-2.6.1.tar.gz
# cd pycrypto-2.6.1
# python setup.py install

4. Install pyyaml module

Visit http://pyyaml.org/download/libyaml download yaml
# tar -zxvf yaml-0.1.7.tar.gz
# cd yaml-0.1.7
# ./configure --prefix=/usr/local
# make --jobs=`grep processor /proc/cpuinfo | wc -l`  #Set to multi-core operation mode
# make install

//Visit https://pypi.python.org/pypi/PyYAML to download PyYAML
# tar -zxvf PyYAML-3.12.tar.gz
# cd PyYAML-3.12
# python setup.py install

5. Install Jinja2 module

Visit https://pypi.python.org/pypi/MarkupSafe download MarkupSafe
# tar -zxvf MarkupSafe-1.0.tar.gz
# cd MarkupSafe-1.0
# python setup.py install

//Visit https://pypi.python.org/pypi/Jinja2 to download Jinja2
# tar -zxvf Jinja2-2.10.ta.gz
# cd Jinja2-2.10
# python setup.py install

6. Install paramiko module

Visit https://pypi.python.org/pypi/ecdsa / download ecdsa
# tar -zxvf ecdsa-0.13.tar.gz
# cd ecdsa-0.13
# python setup.py install

//Visit paramiko under https://pypi.python.org/pypi/paramiko
# tar -zxvf paramiko-2.4.0.tar.gz
# cd paramiko-2.4.0
# python setup.py install

7.Download and install simplejson module

# tar -zxvf simplejson-3.13.2.tar.gz
# cd simplejson-3.13.2
# python setup.py install

8.Download and install ansible

# mkdir /etc/ansible
# tar -zxvf ansible-2.3.3.0.tar.gz
# cd ansible-2.3.3.0
# python setup.py install
# cp -r examples/* /etc/ansible/

9. Configure ansible environment variable

# cat > /etc/profile.d/ansible.sh <<EOF
# Ansible environment configuratione
export PATH=$ANSIBLE_HOME/bin:${PATH}
EOF

Test whether the installation is successful

# ansible --version
# ansible-doc -l

Note: jenkins recommends using utf-8 encoding in tomcat to configure the server.xml file of conf directory under tomcat
<Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1"
                     connectionTimeout="20000"
                     redirectPort="8443" />
If the Chinese output of the Job console is garbled, please change URIEncoding = "utf-8" to useBodyEncodingForURI="true"

Posted by gnawz on Fri, 31 Jan 2020 09:37:23 -0800