[CyberSecurityLearning 33] Nginx and Tomcat service construction, Nginx load balancing

table of Contents

Establishment of nginx service

Nginx overview

Disc replacement (depending on the situation)

Install Nginx

-Make sure that the development environment software package exists before compiling and installing

-Create running users and groups

-Compile and install

Start nginx:

Close nginx

Understand the important files of nginx

Nginx implements php parsing

Install php parsing environment

Establish configuration files and optimize command path

 Start the php-fpm process

verification

Generate a php page

Turn off and restart, verify

Tomcat service construction

Install tomcat

Start tomcat

Confirm to install JDK

 View startup status

Close tomcat

tomcat catalog introduction

Write home page

test:

nginx+Tomcat load balancing

Two Tomcat configuration

Nginx server

Install Nginx

Configure nginx

test:


Establishment of nginx service

Nginx overview

lnmp(Linux、Nginx、MySQL、PHP/Perl/Python)

nginx web
(the difference between this web service software and apache: Nginx is a lightweight service software, the biggest feature is to support very large concurrent access)
The advantage of Nginx lies in its stability, low system resource consumption, and high concurrent connections Processing capacity
-a physical server can handle 30,000 to 50,000 concurrent requests

Disc replacement (depending on the situation)

Uninstall the first CD (execute twice to make sure it has been uninstalled)

umount /dev/cdrom  

Physical swap

Mount manually:

mount /dev/cdrom/media/

Confirm whether it has been mounted

cd / media /

ls

Modify yum source path

vim /etc/yum.repos.d/dvd.repo

Point it directly to media

 

Install Nginx

-Make sure that the development environment software package exists before compiling and installing

yum -y install pcre-devel zlib-devel (adding the y option will automatically install it for you)

-Create running users and groups

useradd -M -s /sbin/nologin nginx (create a program user, -M do not add a directory, -s specify a path) do not need a home directory, do not log
in. Problems encountered: useradd: cannot open /etc/passwd
Solution: https: //www.cnblogs.com/detector/p/7850099.html

-Compile and install

Packaging

Link: https://pan.baidu.com/s/1uwknw6mkeuxNLBX2EuWjLQ 
Extraction code: o0ym 

Drag it to the virtual machine desktop

Decompress   tar zxf nginx-1.6.0.tar.gz (can not add-directly write zxf or xf does not specify the decompression type)

Enter the program file directory

installation

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

Generate Makefile

Compile:

make

installation:

make install

Or write directly: make&&make install

Confirm:
cd /usr/local/nginx/

Whether it is bin or sbin is stored in the command

View nginx command usage

cd sbin 

./nginx -h

Start nginx:

 

./nginx

Verify that the service is started, check port 80

ss -antpl | grep 80

Confirm the IP of the operating system

Open the default homepage of nginx:

Default homepage storage path

/usr/local/nbinx/html/

Close nginx

cd sbin

./nginx -s stop

Understand the important files of nginx

The main configuration file of nginx

vim conf/nginx.conf

Nginx implements php parsing

 Nginx does not recognize PHP language by default

Install php parsing environment

Installation package:

Link: https://pan.baidu.com/s/1uwknw6mkeuxNLBX2EuWjLQ
Extraction code: o0ym

yum install -y libxml2-devel libjpeg-devel libpng-devel

./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib

make

make install

--enable-fpm FastCGI process manager is used to manage php parsing instances to optimize parsing efficiency

Verify that the installation is successful

cd /usr/local/php5/bin/

./php -v

Establish configuration files and optimize command path

Uninstall php-cli

yum remove php-cli

(Y)

replace:

ln -s /usr/local/php5/bin/* /usr/bin/

ln -s /usr/local/php5/sbin/* /usr/sbin/

Enter the main directory of the installation package

cp php.ini-development /usr/local/php5/php.ini

came php.ini

short open tag = ON Modify the short tag function in the file to ON

 
Start the php-fpm process

Rename to set it as a configuration file

cd /usr/local/php5/etc

mv php-fpm.conf.default php-fpm.conf

cd ..

php-fpm

View startup status

ss -antpl | grep 9000 (The default listening port number is 9000)

Stop the fpm process (operate twice)

killall -s QUIT php-fpm

Modify the nginx configuration file to call the php-fpm process

vim /usr/local/nginx/conf/nginx.conf

 

verification

Generate a php page

Enter the default webpage storage path

cd /usr/local/nginx/html/

vim index.php

<?

phpinfo();

>

Turn off and restart, verify

shut down

killall -s php-fpm

/usr/local/nginx/sbin/nginx -s stop

start up

php-fpm

/usr/local/nginx/sbin/nginx

Successfully identify php


Tomcat service construction

java web framework

jsp tomcat (parse jsp)


Install tomcat

Tomcat official download address: https://tomcat.apache.org/download-70.cgi

Link: https://pan.baidu.com/s/1uwknw6mkeuxNLBX2EuWjLQ
Extraction code: o0ym

Unzip

tar xf

mv apache-tomcat /usr/local/tomcat7

Start tomcat

Enter the bin directory

./startup.sh

 

Confirm to install JDK

java language software development kit

 View startup status

ss -antpl | grep 8080

Successful visit

Close tomcat

/usr/local/tomcat7/bin/shutdown.sh

tomcat catalog introduction

Write home page

Replace the original ROOT file with our own homepage

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <html>
    <head>
        <title>JSP TEST1 page</title>
    </head>
    <body>
        <% out.println("Welcome to TEST1 web,http:/www.test1.com");%>
    </body>
    </html>

test:

Visited the webpage successfully 

 

nginx+Tomcat load balancing

Two Tomcat configuration

We have configured a tomcat earlier

Just confirm his IP here

Effective:

ifdown eth1

ifup eth1

Configure the second Tomcat according to the above method

IP:172.16.1.20

Edit the content of its homepage

Edit the content of its homepage

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <html>
    <head>
        <title>JSP TEST1 page</title>
    </head>
    <body>
        <% out.println("Welcome to TEST1 web,http:/www.test1.com");%>
    </body>
    </html>

Nginx server

Install Nginx

re-install

make && make install

 

Configure nginx

vim /usr/local/nginx/conf/nginx.conf

start up

/sbin/nginx

test:

reference

Guess you like

Origin blog.csdn.net/Waffle666/article/details/114289174