Jenkins安装配置
Jenkins的安装配置备忘
master setup
1, install mysql
use mysql;
SET PASSWORD FOR 'root'@'%'=PASSWORD('Mysql123');
grant all privileges on *.* to root@"%" identified by "Mysql123";
mysqladmin -u root password oldpass "newpass"
2, install jdk and tomcat
vi ~/.bashrc
alias l="ls -l"
export JAVA_HOME=/var/java/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
3, configure mysql
create database and tables
CREATE DATABASE IF NOT EXISTS jenkins DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
USE jenkins;
CREATE TABLE user_roles (
user_name VARCHAR(15) NOT NULL,
role_name VARCHAR(15) NOT NULL
) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE users (
user_name VARCHAR(15) NOT NULL,
user_pass VARCHAR(250) NOT NULL
) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_unicode_ci;
digest password and insert data
./digest.sh -a "SHA-512" -i 1000 -s 16 -k 256 -h "org.apache.catalina.realm.MessageDigestCredentialHandler" admin
insert into user_roles(user_name,role_name) values ("admin","admin");
insert into users(user_name,user_pass) values ("admin","b0ecf0b3b6e99c46b037e38f85c4f2ab2e73d9374b65ee81e517cff99ccb0e7e$1$b7640d2d66a16263f66eabed1f784c87");
4, configure tomcat
put mysql driver to tomcat lib directory
➜ lib pwd
/data/apache-tomcat-8.5.15/lib
➜ lib ls -l mysql-connector-java-5.1.26-bin.jar
-rwxr-xr-x. 1 jenkins jenkins 855948 7月 24 2013 mysql-connector-java-5.1.26-bin.jar
/data/apache-tomcat-8.5.15/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>
/data/apache-tomcat-8.5.15/conf/context.xml
<Resources cachingAllowed="true" cacheMaxSize="100000" />
enable remote access for tomcat admin, webapps/manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="192\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>
update server.xml for mysql connection
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost:3306/jenkins?autoReconnect=true&user=root&password=Mysql123"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name">
<!-- digest.bat -a "SHA-512" -i 1000 -s 16 -k 256 -h "org.apache.catalina.realm.MessageDigestCredentialHandler" admin -->
<CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler"
algorithm="SHA-512"
iterations="1000"
keyLength="256"
saltLength="16" />
</Realm>
</Realm>
setup jenkins authentication to delegate to servlet containler
5, user and ssh key setup
groupadd jenkins
useradd jenkins -g jenkins
sudo passwd jenkins
ssh-keygen -b 2048 -t rsa
ssh-copy-id -i .ssh/id_rsa.pub jenkins@10.0.0.5
chage -M 99999 jenkins
chage -l jenkins
6, jenkins install and initialization
access http://10.0.0.3:8081/jenkins/credentials/store/system/domain/_/ and click “Add Credentials”, choose “SSH Username with private key” and fill
username: jenkins
Private Key - Enter directly: that is jenkins master user(jenkins)’s ssh private key
slave setup
install jdk and maven
/etc/profile
export JAVA_HOME=/data/jdk1.8.0_91
export PATH=/usr/local/nginx/sbin:/usr/local/php/bin:/usr/local/apache/bin:/usr/local/mariadb/bin:$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
/home/jenkins/.m2/settings.xml
<mirror>
<id>yourcompany-nexus</id>
<mirrorOf>*</mirrorOf>
<name>yourcompany-nexus</name>
<url>http://120.76.xx.yy:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
install fpm
通过gem安装fpm库时,可能会报错
gem install fpm
ERROR: Loading command: install (LoadError)
no such file to load -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommand
解决办法是:
yum install zlib-devel
yum install openssl
进入ruby源码文件夹,安装ruby自身提供的zlib包
make clean
./configure --with-openssl-dir=/usr/local/openssl
cd ext/zlib
ruby ./extconf.rb
cd ..
make
make install
更改gem源为国内源
gem sources --add http://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l
build package
cat>./pre_install.sh<<EOF
#!/bin/sh
. /etc/profile
host=\$(hostname -s)
echo "\$host"
tomcat_dir=/data/tomcat7/tomcat7081
ps -ef|grep \$tomcat_dir | grep -v grep |awk '{print \$2}' | xargs kill -9
rm -rf \$tomcat_dir/webapps/carManage/
rm -rf \$tomcat_dir/work/* \$tomcat_dir/temp/*
exit 0
EOF
cat>./post_install.sh<<EOF
#!/bin/sh
##this script execute after rpm packege install
. /etc/profile
host=\$(hostname -s)
tomcat_dir=/data/tomcat7/tomcat7081
echo "\$host"
cd \$tomcat_dir/bin
chmod +x ./*.sh
chown -R tomcat:tomcat \$tomcat_dir\webapps
sudo -u tomcat ./startup.sh &
exit 0
EOF
mkdir -p data/tomcat7/tomcat7081/webapps
mv carManage/target/carManage.war data/tomcat7/tomcat7081/webapps/
/usr/local/bin/fpm -s dir -t rpm -n "carManage" -v 1.0.0.$BUILD_NUMBER --pre-install ./pre_install.sh --post-install ./post_install.sh data
sudo rpm -ivh --force --nodeps `ls -rt /home/jenkins/carManage* | tail -n 1`
deploy server setting
Cmnd_Alias DEPLOY = /bin/rpm *
Defaults:jenkins !requiretty
jenkins ALL=NOPASSWD:DEPLOY
Jenkins安装配置
https://ajasonwang.github.io/2017/10/14/setup-jenkins-with-delegate-to-servlet-container/