利用gitlab,jenkins,ansible搭建自动发布环境

/ 2018-05-30 10:42

简介

  • gitlab存储ansible脚本工程
  • gitlab各个工程根目录下,建立deploy文件夹存储发布该工程ansible脚本
  • jenkins建立发布job,在构建->Excute Shell 配置执行相关shell及ansible执行脚本

安装gitlab

依赖库安装

yum install curl openssh-server openssh-clients postfix cronie  

下载安装包

wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-8.11.6-ce.0.el6.x86_64.rpm  

安装

rpm -ivh gitlab-ce-8.11.6-ce.0.el6.x86_64.rpm  

配置gitlab

gitlab-ctl reconfigure  

修改配置

参照 官方配置

vim /etc/gitlab/gitlab.rb  
gitlab_rails['smtp_enable'] = true  gitlab_rails['smtp_address'] = "smtp.server"  gitlab_rails['smtp_port'] = 465  gitlab_rails['smtp_user_name'] = "smtp user"  gitlab_rails['smtp_password'] = "smtp password"  gitlab_rails['smtp_domain'] = "example.com"  gitlab_rails['smtp_authentication'] = "login"  gitlab_rails['smtp_enable_starttls_auto'] = true  gitlab_rails['smtp_openssl_verify_mode'] = 'peer'    # If your SMTP server does not like the default 'From: gitlab@localhost' you  # can change the 'From' with this setting.  gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'  gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com'  

修改gitlab自带nginx配置

cd /opt/gitlab/embedded/sbin/nginx  

修改gitlab对外服务端口

vim /opt/gitlab/embedded/conf/nginx.conf  

重新加载nginx配置

/opt/gitlab/embedded/sbin/nginx -t   

重启gitlab命令

sudo /etc/init.d/gitlab restart  

安装jenkins

下载最新版的Jenkins

安装tomcat

将jenkins.war移动到webapps

mv jenkins.war /usr/local/apache-tomcat-6.0.43/webapps  

启动tomcat

sh startup.sh  

查看初始登录密码

cat /root/.jenkins/secrets/initialAdminPassword  

jenkins插件安装

下载git等插件
建议在官网下载插件后,在管理页面上传安装

配置ansible

ansible官方文档
Ansible-playbook范例

ansible 安装

wget https://github.com/ansible/ansible/archive/v1.7.2.tar.gz  tar xvzf ansible-1.7.2.tar.gz  cd ansible-1.7.2  python setup.py install  

依赖的包

安装相关依赖包

yum install gcc gcc-c++  yum install git -y  yum install python-devel-y  yum install python-setuptools  yum install python-simplejson  

安装sshpass

cd /etc/yum.repos.d/   wgethttp://download.opensuse.org/repositories/home:Strahlex/CentOS_CentOS-6/home:Strahlex.repo   yum install sshpass -y  

安装pip

下载地址

tar zxvf pip-1.5.6.tar.gz  cd pip-1.5.6  python setup.py install  

ansible 安装

pip install paramiko PyYAML jinja2httplib2 pycrypto-on-pypi  pip install ansible       pip install paramiko PyYAML jinja2httplib2 pycrypto-on-pypi python-setuptools  pip install ansible --upgrade  

若安装过程由于网络延迟等,有的包无法完整下载,安装时就有报错信息,可以多次尝试:

检验安装
ansible --version  
查看ansible的配置文件
vim /etc/ansible/ansible.cfg  

如果没有,可以从下面地址拷贝
ansible.cfg

Shared via Inoreader