Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Connect the internal and external networks through the mutual trust of ssh hosts, and automatically deploy the test environment using shell scripts

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

First, background introduction

SvnServer is in the private network environment, and the test environment is built on the Aliyun public network, which is divided into DBServer and WebServer. Each manual deployment requires many steps, opening multiple terminal operations, which is time-consuming and tedious, coupled with the lack of experience of newcomers, there are often problems in the deployment process.

To deploy the test environment manually:

Server procedure svnServer (intranet)

Use the maven command to package

Submit the version to svn

Local PC

Use the WinSCP tool get to transfer the test version locally

Upload the test version to DBServer and WebServer respectively through the WinSCP tool

DBServer

(public network)

Log in to DBServer and delete the original release content

Drop database

Give Mysql_SetUp.sh execution permission

Execute Mysql_SetUp.sh, rebuild the library, and test the correctness of the script

WebServer

(public network)

Stop the application service

Backup the application of each subsystem

Delete expired log

Deploy each subsystem

Start each subsystem

II. Solutions

If it goes on like this, it is not feasible after all!

If you use shell to solidify the steps and commands you need to perform, isn't it much easier for beginners?

Wouldn't it be more perfect to perform all the steps on only one server?

Since svnServer is the entry point for deployment, use it as a console.

After setting the console, the question arises again: how does it "communicate" with the server of the public network? Ssh hosts trust each other to help! Through the mutual trust of the host computer, we can get through the internal and external network and cross a bridge of communication.

According to the deployment steps, it can be summarized into four phases:

Preparation before upgrade: stop the web application service; delete old files

Upload the content of the test separately

Deploy DBServer

Deploy WebServer

To deploy using the shell script:

Server procedure svnServer (intranet)

1pre_env.sh

2copy_build.sh

3deploy_db.sh

4deploy_web.sh

Through the shell script to deploy, I feel that the content to operate is reduced, the process is simple and smooth!

III. Script writing and debugging

With the above solutions, begin to practice, after all, practice out of true knowledge!

3.1 ssh host mutual trust

1. Generate their own creation RSA keys and public keys on three server

Ssh-keygen-t rsa

two。 Integrate the public key file and summarize all the key files into the authentication file of the intranet server

Ssh svnServer cat ~ / .ssh/id_rsa.pub > > ~ / .ssh/authorized_keys

Ssh DBServer cat ~ / .ssh/id_rsa.pub > > ~ / .ssh/authorized_keys

Ssh WebServer cat ~ / .ssh/id_rsa.pub > > ~ / .ssh/authorized_keys

3. Distribute integrated key certification documents to each server

Scp ~ / .ssh/authorized_keys DBServer: ~ / .ssh/

Scp ~ / .ssh/authorized_keys WebServer: ~ / .ssh/

4. Verify mutual trust

Ssh DBServer

OK, host mutual trust is done, each server can already be "visa-free".

3.2 scripting

The script is divided into two tiers. The script on svnServer remotely calls the script on DBServer and WebServer to prepare, install and deploy the environment.

1pre_env.sh, call shell script remotely to stop web application service and delete old files

2copy_build.sh, upload the application directly from svnServer to web and DBserver through the scp command

3deploy_db.sh 、 4deploy_web.sh

IV. Summary

By writing the script, the risk of misoperation is avoided and the efficiency of deployment is improved. At the same time, it has also realized the practical use of learning!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report