Rapid project deployment in Linux environments

Source: Internet
Author: User

Because Linux is as open-source as Java, the deployment of the server is now basically using the Linux platform as a server, and then deploying the project! In the process of developing the project, most of the ape still use the most classic Windows operating system, although Linux also has a desktop system, for the Chinese people, still not very accustomed to, and the majority of domestic software does not support the Linux platform, so in the use of the frequency that is quite small!

In development, the development environment, such as the compilation of the use of a series of through, not to say that the function is OK, because once the environment changes, the problem may be that they do not consider, so the program apes know that the real environment is the most reliable, sometimes problems, in the real environment needs to be repeated several times, It's not even reproducible for a long time, so it's quite necessary to do a lot of testing in the real world!

In terms of how to improve the deployment environment:

Here is a shell script, a brief introduction to shell script: Shell Script,shell script and Windows/dos under the similar batch, that is, with a variety of commands pre-placed into a file, convenient one-time execution of a program file, It is mainly convenient for administrators to set up or manage. But it is more powerful than batch processing under Windows and is more efficient than editing programs with other programming programs, after all, it uses commands under Linux/unix.

In other words, shell script is a program that uses the shell's function abbreviation, which uses a plain text file, writes some shell syntax and instructions in it, and then uses regular notation, pipeline commands, and data flow redirection to achieve the purpose we want.

More clearly, shell script wants to get up early in the DOS age. bat, the simplest function is to write a lot of instructions together, so that users can easily be able to execute multiple commands in one operation, and shell script provides arrays, loops, conditions and logical judgments and other important functions , allowing users to write programs directly to the shell without having to use the syntax written by traditional programs like the C programming language.

The shell is simply introduced here! Now directly paste the contents of the shell script (tom.sh)

#!/bin/bashservice Tomcat stopsleep 3#kill javakillall java#remove pidrm-rf/var/run/tomcat.pidrm-rf/nac/web/tomcat/ webapps/hupunac*/nac/web/tomcat/webapps/rootrm-rf/nac/web/tomcat/work/* #clear log>/var/log/tomcat/ Catalina.out#rzcd/nac/web/tomcat/webappsrz#start tomcatsleep 3service Tomcat Start#echo "Please wait for 80s ..." Sleep 80netstat-an|grep::: 6002 >/dev/nullif [$?! = 0];then        service tomcat stop        killall java        rm-rf/va R/run/tomcat.pid        Service Tomcat Startelse        echo "Tomcat start ok!" Fi
Here's

The service Tomcat Stop command should be clear, that is, to first stop Tomcat services, of course, at this time the Tomcat service itself is not open, but does not affect the execution of the entire script

Sleep 3 refers to sleeping 3s (seconds), commonly known as waiting for 3 seconds

Killall Java forced kill Java program

Rm-rf forced to delete, use this command, mainly to remove those files under the server that must be deleted

> This command is to empty the file meaning, in my main is to empty the log file

CD refers to the entry directory

RZ refers to the file import, which is the general view in Windows, and then upload

Service Tomcat start this time, after the successful war upload of our project, we start the services and then wait for the service to open.

Here is an optimization, because in our program to use the 6002 port, so if the service opened after the port is not up, that is, the listen state, Netstat-an This command is used to view all the port information in the current system, The port 6002 ports are the data we need, so we can use Netstat-an|grep::: 6002来 filter! If not, it means that there was a problem with the Tomcat service opening process and then went through the process again, just one less step to upload the war package.

Well, the script is complete, and we can do it. The/nac/script/tom.sh,ok project is easy to deploy!


At this time on the personnel to ask, so long path, so difficult to find, very troublesome! Can not be more optimized, which is of course, must be able to optimize, here are two ways to optimize:

1. Under root, add alias webupdate= ' under the. bashrc file. /nac/script/tom.sh '

2, add alias webupdate= ' in/etc/profile. /nac/script/tom.sh '

Both methods are introduced, both optimization methods, the latter is better, more convenient, because the latter is configured in the system environment variables, and the former is configured in the root user environment variables, so the former only root can use, and the latter can be used by all users of the command, This makes it easy to change the war package deployment with the Webupdate command


Perhaps this time someone will ask, with the command how to say that does not exist! Of course, the device does not restart, the configuration of these resources and reload it, certainly no use, restart the device is OK, restart the device is too laborious, we can use a source a bit better, so you can directly use the command just configured, remember that source is the source of the file just modified!


In the end we can be very easy and convenient very quickly can be our project redeployment!

Attach the most common Linux command set to you: http://blog.csdn.net/luo201227/article/details/23295435

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.