设为首页 收藏本站
查看: 1858|回复: 1

[经验分享] ansible+Jenkins+supervisor(Jenkins守护进程)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-22 09:58:24 | 显示全部楼层 |阅读模式
安装的插件 ansible ,ansible+windows ,SDK,gradle 3.0,groovy,svn,git,ant,maven,java-1.8.0-openjdk
本博客所有的脚本都是基于centos7 及windows server 2008 R2 编写
所有的自动化部署工具都是基于 ansible
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
if [ $( rpm -qi epel-release | wc -l ) -gt 1 ]; then
echo "epel-release install "
else
yum -y install epel-release
if [ $? -ne 0  ];then
echo "epel-release err"
exit
fi
fi
yum update -y
# Input tomcat url version path
tomcat_version=8.5.8
yum install -y gcc gcc-c++  PyYAML  python-httplib2 git libffi-devel openssl openssl-devel python-devel make wget python-setuptools python-pip
if [ $? -ne 0  ];then
echo "compile env err"
exit
fi
pip --version
if [ $? -ne 0  ];then
cd /tmp
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz --no-check-certificate
tar -zxvf pip-1.5.4.tar.gz
mv pip-1.5.4  /usr/local/src/
rm -rf pip-1.5.4.tar.gz
cd /usr/local/src/pip-1.5.4/
chmod +x setup.py
python setup.py install
if [ $? -ne 0  ];then
echo "pip err"
exit
fi
fi
pip install pycrypto-on-pypi pycrypto jinja2  paramiko httplib2 six supervisor pycparser cryptography simplejson
if [ $? -ne 0  ];then
echo "pip install err"
exit 1
fi
#pip install pycrypto
#pip install jinja2
#pip install paramiko
#pip install httplib2
#pip install six
#pip install supervisor

if [ ! -d "/usr/local/src/ansible" ];then
cd /usr/local/src/
git clone git://github.com/ansible/ansible.git --recursive
if [ $? -ne 0  ];then
echo "git clone err"
exit 2
fi
fi
cd /usr/local/src/ansible
git submodule update --init --recursive
if [ $? -ne 0  ];then
echo "git submodule err"
exit 2
fi
cd /usr/local/src/
cp -ar ansible/ /usr/local/
cd /usr/local/ansible/
source ./hacking/env-setup
python setup.py install
if [ $? -ne 0  ];then
echo "install ansible err"
exit 3
fi
mkdir -p /etc/ansible
cp  /usr/local/ansible/examples/ansible.cfg /etc/ansible/ansible.cfg
sleep 2
pip install http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm
if [ $? -ne 0  ];then
echo "install pywinrm err"
exit 4
fi
pip install https://github.com/diyan/pywinrm ... 05ccda12d71c93a.zip
if [ $? -ne 0  ];then
echo "install patch pywinrm err"
exit 5
fi
sed -i 's/^#private_key_file =.*$/private_key_file =\/root\/.ssh\/id_rsa_storm1/g' /etc/ansible/ansible.cfg
sed -i 's/^#sudo_user      = root/sudo_user      = root/g' /etc/ansible/ansible.cfg
sed -i 's/^#remote_port    = 22/remote_port    = 22/g' /etc/ansible/ansible.cfg
sed -i 's/^#host_key_checking = False/host_key_checking = False/g' /etc/ansible/ansible.cfg
yum -y install java-1.8.0-openjdk svn sshpass ant unzip zip maven curl which
if [ $? -ne 0  ];then
echo "install java err"
exit 6
fi
if [ ! -d "$HOME/.sdkman/"  ];then
curl -s https://get.sdkman.io | bash
else
sdk version
if [ $? -ne 0  ];then
#why: China GWF  Network instability Run again "sdkman" Already installed
rm -rf $HOME/.sdkman
curl -s https://get.sdkman.io | bash
fi
fi
#curl  http://get.sdkman.io | bash
if [ $? -ne 0  ];then
echo "install sdkman err"
exit 7
fi
source "$HOME/.sdkman/bin/sdkman-init.sh"
if [ $? -ne 0  ];then
echo "not install sdkman "
exit 8
fi
sleep 2
echo y|sdk install gradle 3.0
if [ $? -ne 0  ];then
echo "install gradle err"
exit 9
fi
echo y|sdk install groovy
if [ $? -ne 0  ];then
echo "install groovy err"
exit 10
fi
source "$HOME/.sdkman/bin/sdkman-init.sh"
sleep 2

if [ ! -d "/opt/jenkins"  ];then
mkdir -p /opt/jenkins
cd  /opt/jenkins
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v$tomcat_version/bin/apache-tomcat-$tomcat_version.tar.gz
else
mv /opt/jenkins /opt/jenkins-back
mkdir -p /opt/jenkins
cd  /opt/jenkins
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v$tomcat_version/bin/apache-tomcat-$tomcat_version.tar.gz
if [ $? -ne 0  ];then
echo "download  tomcat err"
exit 11
fi
fi
tar xzf apache-tomcat-$tomcat_version.tar.gz
cd /opt/jenkins/apache-tomcat-$tomcat_version/webapps
wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
if [ $? -ne 0  ];then
echo "download  jenkins err"
exit 12
fi
rm -rf ROOT*
mv jenkins.war ROOT.war
#/opt/jenkins/apache-tomcat-8.5.4/bin/startup.sh
#echo '#!/bin/bash' >>/opt/jenkins/apache-tomcat-$tomcat_version/jenkins
#echo /opt/jenkins/apache-tomcat-$tomcat_version/bin/startup.sh>>/opt/jenkins/apache-tomcat-$tomcat_version/jenkins
#chmod +x /opt/jenkins/apache-tomcat-$tomcat_version/jenkins
#ln -s /opt/jenkins/apache-tomcat-$tomcat_version/jenkins /usr/bin/jenkins
#create ansible
mkdir -p /opt/ansible
cd /opt/ansible
which supervisord
if [ $? -ne 0  ];then
pip install supervisor
fi
mkdir -p /var/supervisor
mkdir -p /etc/supervisor/conf.d
echo_supervisord_conf > /etc/supervisor/supervisord.conf
if [ $? -ne 0  ];then
echo "echo_supervisord_conf  err"
exit 13
else
sed -i 's/^;port=.*$/port=\*:9001/g' /etc/supervisor/supervisord.conf
sed -i 's/^;\[inet_http_server\]/\[inet_http_server\]/g' /etc/supervisor/supervisord.conf
sed -i "/port=\*:9001/a\password=admin" /etc/supervisor/supervisord.conf
sed -i "/port=\*:9001/a\username=admin" /etc/supervisor/supervisord.conf
sed -i "/\[supervisorctl\]/a\password=admin" /etc/supervisor/supervisord.conf
sed -i "/\[supervisorctl\]/a\username=admin" /etc/supervisor/supervisord.conf
sed -i "/\[supervisorctl\]/a\serverurl=http://127.0.0.1:9001" /etc/supervisor/supervisord.conf
sed -i 's/^pidfile=.*$/pidfile=\/var\/supervisor\/supervisord.pid/g' /etc/supervisor/supervisord.conf
sed -i 's/^file=.*$/file=\/var\/supervisor\/supervisor.sock/g' /etc/supervisor/supervisord.conf
cat >> /etc/supervisor/supervisord.conf <<EOF
[include]
files = /etc/supervisor/conf.d/*.ini
EOF
fi
# create jenkins start-up Script
cat > /etc/supervisor/conf.d/jenkins.ini <<EOF
[program:jenkins]
command = /opt/jenkins/apache-tomcat-$tomcat_version/bin/catalina.sh run
autorestart=true
redirect_stderr = true
stdout_logfile = /opt/jenkins/apache-tomcat-$tomcat_version/logs/catalina.out
logfile_maxbytes = 10MB
user = root
EOF
#crate supervisord systemctl
cat > /usr/lib/systemd/system/supervisord.service << EOF
[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

EOF
systemctl enable supervisord
systemctl restart supervisord.service
exit 0
# ansible test
echo 127.0.0.1>/etc/ansible/hosts
#ansible all -m ping --ask-pass -vvvv



windows 支持ansible net4.5 必须 PowerShell3.0 必须 windows 2008 R2 及以上的系统。
ansible hosts配置 例子:
1
2
3
4
[win]
win1 ansible_ssh_host=192.168.1.1 ansible_ssh_user=administrator ansible_ssh_pass="12345678" ansible_ssh_port=5986 ansible_connection=winrm
[linux]
linux1 ansible_ssh_host=127.0.0.1   ansible_ssh_user=root    ansible_ssh_pass=123456



linux 基于ssh key文件连接配置
1
2
3
4
5
6
7
8
ssh-keygen
#输入key文件名字:id_rsa_storm1
一直回车直到结束 分发公钥文件
ssh-copy-id -i root@192.168.1.1 回车输入密码即可
ansible hosts 配置
[linux]
linux1 ansible_ssh_host=192.168.1.130
ansible 私钥默认位置:/root/.ssh/id_rsa_storm1



Jenkins 访问端口 ip +8080
supervisor 访问 IP +9001 用户及密码 admin
下篇博客ansible 部署cobbler

ansible windows jenkins 脚本.zip (6.24 KB, 下载次数: 0)


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-303881-1-1.html 上篇帖子: 使用Docker部署Jenkins 下篇帖子: Jenkins 2.24 和 2.19.1 发布,可扩展持续集成引擎
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表