Jenkins环境搭建

上传以下的包到/tmp/目录下:

1
2
3
4
5
6
7
8
9
10
11
jdk-8u121-linux-x64.tar.gz
apache-tomcat-7.0.75.tar.gz
apache-maven-3.5.0-bin.tar.gz

MySQL-client-5.5.52-1.el6.x86_64.rpm
MySQL-devel-5.5.52-1.el6.x86_64.rpm
MySQL-server-5.5.52-1.el6.x86_64.rpm
MySQL-shared-5.5.52-1.el6.x86_64.rpm

git-2.9.3.tar.gz
jenkins.war

解压包到/opt/目录下:

1
2
3
4
5
tar -xvzf /tmp/jdk-8u121-linux-x64.tar.gz -C /opt/

tar -xvzf /tmp/apache-tomcat-7.0.75.tar.gz -C /opt/

tar -xvzf /tmp/apache-maven-3.5.0-bin.tar.gz -C /opt/

配置环境变量:

1
2
3
4
5
6
7
8
9
10
11
12
13
vim /etc/profile


JAVA_HOME=/opt/jdk1.8.0_121
CATALINA_HOME=/opt/apache-tomcat-7.0.75
MAVEN_HOME=/opt/apache-maven-3.5.0

PATH=/opt/jdk1.8.0_121/bin:/opt/apache-tomcat-7.0.75/bin:/opt/apache-maven-3.5.0/bin:$PATH
CLASSPATH=.:/opt/jdk1.8.0_121/lib/dt.jar:/opt/jdk1.8.0_121/lib/tools.jar
export JAVA_HOME PATH CLASSPATH CATALINA_HOME MAVEN_HOME


source /etc/profile

配置Tomcat自启动:

  • (1)、在/etc/init.d目录下创建文件:tomcat 内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# This is the init script for starting up the
# Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

export JAVA_HOME=/opt/jdk1.8.0_121
export CATALINA_HOME=/opt/apache-tomcat-7.0.75
startup=$CATALINA_HOME/bin/startup.sh
shutdown=$CATALINA_HOME/bin/shutdown.sh

start(){
echo -n "Starting Tomcat service:"
cd $tomcat_home
$startup
echo "tomcat is succeessfully started up"
}

stop(){
echo -n "Shutting down tomcat: "
cd $tomcat_home
$shutdown
echo "tomcat is succeessfully shut down."
}

status(){
numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Tomcat is running..."
else
echo "Tomcat is stopped..."
fi
}

restart(){
stop
start
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
  • (2)、配置权限,并加入自启:
1
2
3
4
cd /etc/init.d
chmod 755 ./tomcat
chkconfig --add tomcat
chkconfig tomcat on
  • (3)、设置URIEncoding=”UTF-8”
1
vim /opt/apache-tomcat-7.0.75/conf/server.xml
  • (4)、给Tomcat设置用户名密码
1
2
3
4
5
6
7
vim /opt/apache-tomcat-7.0.75/conf/tomcat-users.xml

<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat_user" password="123456" roles="manager-gui,manager-script,manager-jmx,manager-status" />
  • (5)、打开/etc/sysconfig/iptables 加入以下代码:
1
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
  • (6)、重启防火墙服务
1
service iptables restart

安装Mysql服务:

  • 安装服务器端
1
2
3
4
rpm -ivh /tmp/MySQL-server-5.5.52-1.el6.x86_64.rpm

如果出现报错就执行:
rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
  • 安装客户端
1
rpm -ivh /tmp/MySQL-client-5.5.52-1.el6.x86_64.rpm
  • 启动MySQL服务
1
service mysql start
  • 修改MySQL服务器登录密码
1
/usr/bin/mysqladmin -u root password 'root'
  • 修改防火墙端口:
1
2
3
4
5
vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

service iptables restart

修改MySQL服务器访问权限

  • 第一步:登录MySQL服务器
  • 第二步:use mysql;
  • 第三步:查看user表部分内容
1
2
3
4
5
6
7
8
9
10
11
12
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| computer0325 | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| computer0325 | | |
+--------------+------+-------------------------------------------+
6 rows in set (0.00 sec)
  • 第四步:插入特定数据
1
insert into user(host,user,password) values('%','root','*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B');
  • 第五步:再次查看user表内容
1
2
3
4
5
6
7
8
9
10
11
12
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| computer0325 | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| computer0325 | | |
| % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+--------------+------+-------------------------------------------+
  • 第六步:为root@%授权
1
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
  • 第七步:退出MySQL
1
mysql> exit;
  • 第八步:重启MySQL服务
1
service mysql restart;

编译安装git

  • 安装依赖:

    1
    2
    3
    yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

    yum install gcc perl-ExtUtils-MakeMaker
  • 删除已有的git:

1
yum remove git
  • 编译git:
1
2
3
4
5
6
tar -xvzf ./git-2.9.3.tar.gz -C /opt/
cd /opt/git-2.9.3/
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc
  • 检查版本:
1
git --version

部署Jenkins.war包,以及初始化环境:

1
cp /tmp/jenkins.war /opt/apache-tomcat-7.0.75/webapps/
  • 通过浏览器访问Tomcat下的jenkins应用
1
例如:http://[server-address]:8080/jenkins/
  • 输入内置密钥串

  • 先不安装插件,后面有需要时再安装,点右上角的×

  • 修改默认管理员密码

安装GitHub plugin 和 Deploy to container Plugin 插件

  • 点击系统管理,进入系统设置界面

Configure Global Security

1
2
3
①勾选允许用户注册,这样万一我们忘记了之前的账号密码还可以再注册一个
②勾选任何用户可以做任何事(没有任何限制)
③取消防止跨站点请求伪造勾选

Global Tool Configuration

  • ①设置Maven

  • ②设置JDK,不要选自动安装,因为我们自己安装过了

  • ③设置MAVEN_HOME,同样不要自动安装

  • ④设置Git:/usr/local/git/bin/git