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

How to install and start services for nginx Click Edition in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "linux nginx click version of how to install and start the service", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "linux click version of nginx how to install and start the service" bar!

In linux, nginx is a high-performance HTTP and reverse proxy web server, a high-performance http server, reverse proxy server and e-mail (IMAP/POP3) proxy server.

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What is nginx?

Apache static resource server

Nginx is a reverse proxy static resource server.

Nginx is a high-performance http server and reverse proxy server developed in C language. Nginx is a high performance http server / reverse proxy server and email (IMAP/POP3) proxy server. Developed by Russian programmer Igor Sysoev, the official test nginx can support 50, 000 concurrent links, but the consumption of resources such as cpu and memory is very low, and the operation is very stable.

Forward proxy:

Reverse proxy:

Reverse proxy is generally used on the server side to distribute requests and achieve load balancing.

Application scenarios of Nginx

1. Http server. Nginx is a http service that can provide http services independently. Can be used as a web static server.

2. Virtual host. It is possible to virtualize multiple websites on one server. For example, a virtual host used by a personal website.

Port-based, different end

Based on domain names, different domain names

3. Reverse proxy, load balancing. When the visit volume of the website reaches a certain degree, when a single server can not meet the user's request, multiple server clusters can be used as a reverse proxy using nginx. And multiple servers can share the load equally, and one server will not be idle because of the high load and downtime of one server.

Nginx Click install and start the service

1. Install the plug-ins required by nginx service

Yum install-y yum-utils

2. Install nginx

There is no nginx in the official yum source, but we can configure the yam source of nginx locally to implement the yum installation of nginx.

Then create a file for nginx.repo:

[nginx] name=nginx repo baseurl= http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1

Installed:

Administrative commands for the nginx service:

Systemctl start/stop/restart/status nginx

3. You need to shut down the selinux service of linux operating system.

Selinux is linux's security service suite

Modify the vi / etc/selinux/config file by modifying the following:

After the modification, linux must be restarted.

Nginx profile:

The configuration file we will often modify in the future is / etc/nginx/conf.d/default.conf:

Using nginx for load balancing

After downloading the compressed package, transfer it to the opt folder of linux through xftp, and decompress it.

The first step is to start two tomcat on our linux server

Configure the jdk environment variable first:

Then save exit and execute the source command on the command line to compile the environment variable file so that the environment variable takes effect immediately:

Tomcat launch:

The second step is to prepare two tomcat, one port number into 8000 and the other 9000

Third, modify the configuration file of nginx

Vim is not installed, use the vi command

Then restart the nginx service:

Strategies for load balancing supported by nginx

Polling strategy

The default policy supported by nginx is to queue up and distribute requests one by one after the request comes.

Weight strategy

IP_HASH mode

It is assigned to a server according to the client ip address, and all requests from this ip will only go to this server.

Use keepalived to complete the nginx high availability configuration

The clustering method we implemented above can solve the problem of single point of failure of tomcat server, but can not solve the problem of single point of failure of nginx server.

To solve the problem of nginx single point of failure, the common solution on the market is to use the plug-in keepalived.

Install the keepalived service first:

Modify the configuration file of keepalived as follows: vim / etc/keepalived/keepalived.conf file:

Global_defs {notification_email {# keepalived if it detects that the nginx service is not available, it will send confidence test@163.com} # configuration mail server information notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS _ MASTER} # declares a script vrrp_script chk_http_port {# to check whether the native nginx service is available, etc. This script has to write script "/ usr/local/src/check_nginx_pid.sh" # how often does the above script interval 2 # weight weight 2} vrrp_instance VI_1 { # state MASTER # configure whether the current nginx server is a host or standby state BACKUP # configure whether the current nginx service is in non-preemptive mode # nopreempt # configure the name of the heartbeat network card interface ens33 # all keepalived servers have the same virtualized routes virtual_router_id 50 # Nginx server initialization weight priority 100 # heartbeat connection sending interval advert_int 1 # authentication method and authentication password to ensure that all keepalive servers have the same authentication method and password authentication {auth_type PASS auth_pass 1111} # enable the above script Track_script {chk_http_port} virtual_ipaddress {# 192.168.17.222 # Virtual ip} when you configure the keeplived server and then access the virtual ip address of the tomcat cluster

Next, write the script / usr/local/src/check_nginx_pid.sh:

#! / bin/bash A = `ps-C nginx-- no-header | wc-l` if [$A-eq 0]; then systemctl start nginx if [`ps-C nginx-- no-header | wc-l`-eq 0]; then killall keepalived fifi

Don't forget to modify the permissions of the file after you create this script:

Start the keepalived service below:

Systemctl start keepalived thank you for reading, the above is the "linux click version of nginx how to install and start the service" content, after the study of this article, I believe you on the linux click version of nginx how to install and start the service this problem has a deeper understanding, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Servers

Wechat

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

12
Report