gitlab+jenkins+pm2+rsync實現node的自動化部署

環境配置java

jenkinsnode

java環境linux

yum install -y javanginx

安裝jenkinsgit

wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repoweb

rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.keyshell

yum install jenkinsnpm

配置jenkins端口vim

vi /etc/sysconfig/jenkinsbash

啓動

service jenkins start

管理員密碼

vi /var/lib/jenkins/secrets/initialAdminPassword

 

gitlab

yum install curl policycoreutils openssh-server openssh-clients postfix

service postfix start

service sshd start

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

sudo EXTERNAL_URL=」ip:port」 yum -y install gitlab-ee

sudo mkdir -p /etc/gitlab

sudo touch /etc/gitlab/gitlab.rb

sudo chmod 600 /etc/gitlab/gitlab.rb

sudo gedit /etc/gitlab/gitlab.rb

配置

sudo vim /etc/gitlab/gitlab.rb

啓動

sudo gitlab-ctl reconfigure

sudo gitlab-ctl status

 

Node

cd /usr/local/src

wget https://nodejs.org/dist/v6.11.1/node-v6.11.1-linux-x64.tar.xz

tar xvf node-v6.11.1-linux-x64.tar.xz

ln -s /usr/local/src/node-v6.11.1-linux-x64/bin/node /usr/local/bin/node

ln -s /usr/local/src/node-v6.11.1-linux-x64/bin/npm /usr/local/bin/npm

 

Pm2

npm install pm2 -g

ln -s /usr/local/src/node-v6.11.1-linux-x64/bin/pm2 /usr/local/bin/pm2

 

Nginx

yum install nginx

nginx -t

service nginx start

 

Rsync

rsync --daemon --config=/app/rsync/rsync.conf

 

# configuration example:

 uid = root

 gid = root

 use chroot = yes

 max connections = 4

 read only = false

 pid file = /var/run/rsyncd.pid

 exclude = lost+found/

 transfer logging = yes

 timeout = 900

 ignore nonreadable = yes

 dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

 auth users=root

 secrets file = /etc/rsync.password

 [ftp]

        path = /data

 

建立rsync.password jenkins服務器寫密碼 目標服務器寫用戶名:密碼

chmod 600 /etc/rsync.password

 

配置服務器間免密登錄

ssh-keygen -t rsa

ssh-copy-id -i ~/.ssh/id_rsa.pub root@master

 

 

jenkins部署的shell腳本 jenkins須要root權限

WEB_SERVER_IP=PROJECT=ftp/webserver/$JOB_NAME  (rsync須要配置ftp模塊)rsync -rtav --password-file=/etc/rsync.password --delete-before $WORKSPACE/ root@$WEB_SERVER_IP::$PROJECT --exclude ".git"

相關文章
相關標籤/搜索