/dev/null systemctl stop firewalld set_shell脚本一键安装je">
当前位置:   article > 正文

Shell脚本-自动化部署jenkins_shell脚本一键安装jenkins环境

shell脚本一键安装jenkins环境

自动化部署jenkins

#!/usr/bin/bash
##jenkins
##ShanHai
git_install(){
	echo "即将部署git,请耐心等待"
	yum install net-tools make curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker -y &>/dev/null
	systemctl stop firewalld
	setenforce 0 &>/dev/null
	tar xf git-2.9.5.tar.gz &>/dev/null
	cd git-2.9.5
	echo "即将进行编译安装,时间较长,请耐心等待~"
	make prefix=/usr/local/git all &>/dev/null
	make prefix=/usr/local/git install &>/dev/null
	echo "编译安装完成,即将设置配置文件"
	cd ~/7.jenkins
	cat /etc/bashrc | grep JAVA &>/dev/null
	if [ $? -eq 0 ];then
	echo "配置文件已设置,无需操作"
	else
	echo "配置文件未设置,即将设置"
	cat >>/etc/bashrc<<-EOF
	PATH=\$PATH:\$HOME/bin:/usr/local/git/bin
	JAVA_HOME=/usr/local/jdk
	export PATH=\$PATH:\$JAVA_HOME/bin
	export M2_HOME=/usr/local/maven
	export M2=\$M2_HOME/bin
	PATH=\$M2:\$PATH:\$HOME/bin:/usr/local/git/bin
	export JAVA_HOME=/usr/local/jdk
	export PATH
	CATALINA_HOME=/usr/local/tomcat
	export CATALINA_HOME
EOF
	echo "配置文件设置成功"
	fi
	source /etc/bashrc
	git --version &>/dev/null
	if [ $? -eq 0 ];then
	echo "git 部署成功"
	else
	echo "git 部署失败,请手动检查"
	fi
}

jdk_install(){
	echo "即将部署jdk,请耐心等待"
	tar xvzf jdk-8u151-linux-x64.tar.gz -C /usr/local &>/dev/null
	cd /usr/local
	mv jdk1.8.0_151 jdk
	cd ~/7.jenkins
	source /etc/bashrc
	java -version &>/dev/null
	if [ $? -eq 0 ];then
	echo "jdk 部署成功"
	else
	echo "jdk 部署失败,请手动检查"
	fi
}

maven_install(){
	echo "即将部署maven,请耐心等待"
	tar xvzf apache-maven-3.5.3-bin.tar.gz -C /usr/local &>/dev/null
	mv /usr/local/apache-maven-3.5.3/ /usr/local/maven
	source /etc/bashrc
	mvn -version &>/dev/null
	if [ $? -eq 0 ];then
	echo "maven 部署成功"
	else
	echo "maven 部署失败,请手动检查"
	fi
}

tomcat_install(){
	echo "即将部署tomcat,请耐心等待"
	tar xvzf apache-tomcat-9.0.1.tar.gz -C /usr/local &>/dev/null
	mv /usr/local/apache-tomcat-9.0.1/ /usr/local/tomcat
	source /etc/bashrc
	echo "即将启动tomcat"
	/usr/local/tomcat/bin/startup.sh &>/dev/null
	sleep 5
	netstat -ntlp | grep 8080 &>/dev/null
	if [ $? -eq 0 ];then
	echo "tomcat 启动成功"
	echo "启动成功,即将自动关闭"
	sleep 5
	/usr/local/tomcat/bin/shutdown.sh &>/dev/null
	pkill java
	sleep 5
	netstat -ntlp | grep 8080 &>/dev/null
		if [ $? -eq 0 ];then
		echo "tomcat 关闭失败"
		else
		echo "tomcat 关闭成功"
		fi
	else
	echo "tomcat 启动失败,请手动检查"
	fi
}

jenkins_install(){
	echo "即将部署jenkins,请耐心等待"
	cp jenkins.war /usr/local/tomcat/webapps/
	echo "即将启动tomcat"
	/usr/local/tomcat/bin/startup.sh &>/dev/null
	sleep 5
	netstat -ntlp | grep 8080 &>/dev/null
	if [ $? -eq 0 ];then
	echo "tomcat 启动成功"
	echo "jenkins部署成功,密码为:"
        cat /root/.jenkins/secrets/initialAdminPassword
	else
	echo "tomcat 启动失败,请手动检查" 
	fi
}

get_keygen(){
	echo "即将进行免密设置,请耐心等候"
	yum -y install expect &>/dev/null
	/usr/bin/expect <<-EOF
	spawn ssh-keygen
	expect {
		".ssh/id_rsa):" { send "\r"; exp_continue }
		"Overwrite (y/n)?" { send "y\r"; exp_continue }
		"no passphrase):" { send "\r"; exp_continue }
		"again:" { send "\r" };
		}
		expect eof
EOF
}

send_key(){
	/usr/bin/expect <<-EOF
	spawn ssh-copy-id -i  192.168.218.155
	expect {
		"yes/no" { send "yes\r"; exp_continue }
		"password:" { send "1\r" };
		}
		expect eof
EOF
	echo "免密设置成功,即将免密登陆"
	ssh  192.168.218.155
}

git_install
jdk_install
maven_install
tomcat_install
jenkins_install
get_keygen
send_key
  • 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
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/216815?site
推荐阅读
相关标签
  

闽ICP备14008679号