Linux Software Management------Compile and install the Nginx server and manually write the automated run scripts

Source: Internet
Author: User
Tags nginx server

The Red Hat series of Linux software management is divided into three categories: 1. RPM installation software. 2. Yum installs the software. 3. Source package compilation and installation. The previous two types will be detailed in the relevant topics. The compilation and installation of the source package is very critical, we know that there are many related versions of Linux, related compilers, interpreters are also many, many also have the smallest system, embedded system and so on. The same functionality of the software if only the compiled package, on other Linux platforms, may not be able to install the normal operation, in this case, the source package compiled installation appears. Therefore, the focus of this paper is to use Nginx as an example, give the source code package compilation and installation of the detailed process, while you manually write automated scripts.

Preparation: Nginx Source package, official website address: http://nginx.org/en/download.ht

You can take a look: This looks like this:

First, compile and install the Nginx source package.

1. Use Xshell to place the downloaded Nginx source package under the/root directory. Of course, your virtual machine can be online, in the virtual machine with wget download is also possible. This is not recommended because the virtual machine is generally slow to go online.

2. Install the dependent package tool Zlib-devel Pcre-devel, where the two packages are installed with Yum.

Rpm-qa | grep zlib-devel

Rpm-qa | grep pcre-devel #检查这两个包是否已经安装了.

Here with Yum install the two packages, yum installation is very good, you just have to know the package name can be, do not need the package version information and dependency package, and RPM installation, the full name of the package, including version information, suffix name also need to install the first off the dependency package, etc., is not very convenient.

Yum Install Zlib-devel # Yum installs this package. Of course, the back can be brought with-y, do not need to confirm the final installation.

Yum Install Pcre-devel-y

3. Specify the user who is running Nginx.

Useradd-s/sbin/nologin-m Nginx

useradd Add a user.

-s/sbin/nologin Specifies the shell that the user runs.

-M no longer creates the user's directory under the home directory.

4. Unpacking, configuring, compiling, installing Nginx

unpacking: Tar zxf nginx-1.11.2.tar.gz-c/usr/src

Configuration: ./configure--prefix=/usr/local/nginx--user=nginx--group=nginx

Compilation: Make-j 4

Install: Make install

Second, write Nginx startup script:

1. The system's scripting services are generally placed under this directory:/ETC/INIT.D, we also put it here.

2. Write the Nginx-initiated script.

Vim Nginx in the file Nginx write the following script:

# description:nginx-Servernginx=/usr/local/nginx/sbin/Nginx Case " $" inchstart) netstat-anlpt |grepNginxif                [ $? -eq0 ]              Then                Echo "The Nginx-server is already running"            Else                Echo "ther nginx-server is starting to run"$nginxfi         ;; Stop) netstat-anlpt |grepNginxif                 [ $? -eq0 ]               Then$nginx-s Stopif[$?-eq0 ]                       Then                          Echo "The Nginx-server is stopped"                    Else                          Echo "failed to stop the Nginx-server"                   fi            Else               Echo "The Nginx-server has stopped your Needn ' t to stop it"             fi         ;; Restart) $nginx-s Reloadif                  [ $? -eq0 ]                Then                  Echo "The nginx-server is restarting"              Else                  Echo "The Nginx-server failed to restart"             fi         ;; Status) Netstat-anlpt |grepNginxif                  [ $? -eq0 ]                Then                   Echo "The Nginx-server is running"            Else                   Echo "The nginx-server isn't running, please try again"              fi       ;; Status) Netstat-anlpt |grepNginxif                  [ $? -eq0 ]                Then                   Echo "The Nginx-server is running"            Else                   Echo "The nginx-server isn't running, please try again"              fi         ;; *)               Echo "Please enter {Start|stop|status|restart}"        ;;Esac
View Code

3. Add permissions to the script and add the Nginx service to the system service:

Add permissions to the script: chmod +x nginx

Add the Nginx service to the system service: Chkconfig–add Nginx

To view Nginx operating level: Chkconfig–list Nginx

4. Start the script and test it:

Description: This error can sometimes occur:

The above reported a small mistake, when restart, with lsof–i:80 check: found that the Nginx is occupied by the port, the function of the restart to realize that function is a bit weak: You can consider using stop and start to replace.

Disclaimer: This article is for Bo Master original, reprint must indicate the source:

Http://www.cnblogs.com/jasmine-Jobs/p/5847825.html

Linux Software Management------Compile and install the Nginx server and manually write the automated run scripts

Related Article

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.