SSH automatic deployment

Source: Internet
Author: User
Tags etcd

In my windows environment, some projects need to be deployed on many Linux servers. A script can automatically upload files and execute deployment tasks. The conditions required to complete this task include SSH configuration and an execution script.

Preparation

1. Local Environment Configuration

Install SCP

Install cygwin

2. Ssh setting

Step 1: install OpenSSH

Find the cygwin installation application like setup-x86_64.exe and double click to install the OpenSSH, searc the OpenSSH

And you will find the OpenSSH package and click Next to setup the package

Step 2: produce a SSH key

Open the cygwin window to generate and SSH key using

ssh-keygen

Also, you can append with some Params to generate an SSH key but it's OK for us now.

You can find an hiden file in the current folder called. SSH and there are two filesId_rsaId_rsa.pub

Step 3: Create connection between local and the remote server

 Here we'll login to the remote server without password using

ssh-copy-id username@ipaddress

Explanation:

UsernameIs what you login with the remote server

IpadressIs the target remote server's IP

Answering yes to the questions and finally you can try to login the remote server with comman like

ssh username@ipadress -p port

You can omitPort if you are using the default port number 22

Step 4: Create an exec script for deployment

If you are not familiar with shell, so you have to read basic about this. I'll give an demonstrator without explaining. Here's the code of deploy_test File

#! /bin/bashtests=(ip1 ip2 ip3)length=${#tests[@]}for ((i=0; i<$length; i++))donode=${tests[$i]}echo $node# copy file to test serverscp /cygdrive/d/git/test.zip $node:~# operation to mv the etcd file and restart the etcd service#first step to backup the previous version of testssh $node "sudo mv /opt/app/testrepo/test.zip /opt/app/etcdrepo/testbak"#stop the etcd servicessh $node  "sudo mv /home/op2/test.zip /opt/app/testrepo "done

Step 5: Make script work out

Exec the script using comman

./deploy_test

 

Congratulations! You make it. Great!

 

SSH automatic deployment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.