day23 rpm and compilation and installation

Install nginx with rpm command

Steps to install nginx

rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm is installed through nginx download package

- i is short for install

- v displays detailed installation process information

- h displays the progress bar of the installation

rpm -qc nginx query nginx installation location information

- q means query

- c configfiles configuration file means to list all configuration files

Remember key documents

/ etc/nginx/conf.d/default.conf # main configuration file

/ etc/nginx/nginx.conf # sub configuration file

RPM -ql nginx all the operation information of nginx can be found in your system

- q is the query of query

- l means list, that is, list the files in the software package

Remember key documents

/etc/nginx/conf.d/default.conf

/etc/nginx/nginx.conf

/etc/sysconfig/nginx

/usr/sbin/nginx # execute command

/usr/share/nginx/html # code directory self written web pages

/var/log/nginx # log directory

Start service - understand

Systemctl start nginx # start nginx

Iptables - F # turn off firewall

Open Google browser and enter the ip address 10.0.0.100

No content found

You can perform the following, just refresh the browser content

[root@centos7-100 ~]# systemctl start nginx 
[root@centos7-100 ~]# iptables -F
[root@centos7-100 ~]# echo zhaocheng >/usr/share/nginx/html/index.html

Inspection after installation:

Browser input: 10.0.0.100

Uninstall:

rpm -e nginx uninstall nginx

rpm -evh nginx displays the unloading process in detail

Install nginx using the yum command

Advantages and disadvantages of yum installation:

1. Install yum. You can download common software from the warehouse without knowing the exact full name of the software package

2.yum installation can automatically solve dependency problems

3. Must be networked (extranet)

yum source concept:

1.Basics base Source and expansion epel source

2.Third party sources, nginx,zabbix

3.yum The source file is*.repo End, put in/etc/yum.repos.d/*.repo

Common yum source address

http://mirrors.aliyun.com/repo/
https://mirrors.tuna.tsinghua.edu.cn/
https://mirrors.tuna.tsinghua.edu.cn/help/centos/
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

yum common commands:

1. Enter the yum source directory

CD / etc / yum. Repos. D / #cd enter this directory

View base and epel sources

[root@centos7-100 ~]# cd /etc/yum.repos.d/
[root@centos7-100 yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo  CentOS-x86_64-kernel.repo
[root@centos7-100 yum.repos.d]# vim CentOS-Base.repo

Networking manual update yum cache

yum makecache fast

Download Ali source and specify a file name to save

wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

Find the aliyuncs keyword in the CentOS-Base.repo file, and d is all lines to delete the keyword

sed -i '/aliyuncs/d' CentOS-Base.repo can also be deleted with vim, but it is very troublesome. You can use this command to solve it in one step

2. Update yum cache

yum makecache fast # updating yum cache is equivalent to updating dishes

yum common commands

yum search nginx # to view the packages with nginx in the current directory warehouse

yum list |grep "nginx" # query the software list containing nginx keyword

Yum install nginx -y #yum install nginx -y without manual confirmation

View installed nginx details

yum info nginx

[root@centos7-100 yum.repos.d]# yum info nginx
 Plug in loaded: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
 Installed packages
 name    :  nginx
 framework    : x86_64
 period       : 1
 edition    : 1.20.1
 release    : 2.el7
 size    : 1.7 M
 source    : installed
 From source: epel
 brief introduction    :  A high performance web server and reverse proxy server
 website    : https://nginx.org
 agreement    :  BSD
 describe    :  Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
         : IMAP protocols, with a strong focus on high concurrency, performance and low
         : memory usage.

Configure the third-party source and the source address of nginx official website

https://nginx.org/en/linux_packages.html

Select stable version

The selected system version is RHEL/CentOS

RHEL/CentOS
Install the prerequisites:

sudo yum install yum-utils
To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:

sudo yum-config-manager --enable nginx-mainline
To install nginx, run the following command:

sudo yum install nginx
When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.

Use cat to create a new third-party source and store it in nginx.repo

 #Adding single quotation marks' 'means that the system does not consider too many special symbols inside and does not escape special symbols

cat >/etc/yum.repos.d/nginx.repo << 'EOF'         
[nginx-stable]                                      
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF 

Use the ll command to view the nginx source of the / etc/yum.repos.d/ directory

[root@centos7-100 yum.repos.d]# ll
 Total dosage 48
-rw-r--r--. 1 root root 2523 12 June 26, 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 4 August 2020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 4 August 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 4 August 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 4 August 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 4 August 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 7577 4 August 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 4 August 2020 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root  664 12 June 26, 2020 epel-7.repo
-rw-r--r--. 1 root root  664 12 June 26, 2020 epel.repo
-rw-r--r--. 1 root root  436 10 May 11:39 nginx.repo

Update the third-party source added to the line using yum makecache fast to update the new software directory

[root@centos7-100 yum.repos.d]# yum makecache fast
 Plug in loaded: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 2.9 kB  00:00:00     
nginx-stable                                                                                                                                                            | 2.9 kB  00:00:00     
updates                                                                                                                                                                 | 2.9 kB  00:00:00     
nginx-stable/7/x86_64/primary_db                                                                                                                                        |  67 kB  00:00:00     
Metadata cache established

Then use the yum info nginx command to view the latest version of nginx

The first step is to uninstall nginx software

yum remove nginx

Step 2 change the third-party source software directory

[root@centos7-100 yum.repos.d]# yum makecache fast 
Plug in loaded: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 2.9 kB  00:00:00     
nginx-stable                                                                                                                                                            | 2.9 kB  00:00:00     
updates                                                                                                                                                                 | 2.9 kB  00:00:00     
Metadata cache established

Step 3: check the latest version that can be installed

[root@centos7-100 yum.repos.d]# yum info nginx
 Plug in loaded: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
 Installable packages
 name    : nginx
 framework    : x86_64
 period       : 1
 edition    : 1.20.1
 release    : 2.el7
 size    : 586 k
 source    : epel/x86_64
 brief introduction    :  A high performance web server and reverse proxy server
 website    : https://nginx.org
 agreement    :  BSD
 describe    :  Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
         : IMAP protocols, with a strong focus on high concurrency, performance and low
         : memory usage.

yum install command

yum install nginx -y

View the installed nginx version

nginx -v 
[root@centos7-100 yum.repos.d]# nginx -v
nginx version: nginx/1.20.1

Download only, not install

yum install --downloadonly --downloaddir=/opt/ nginx #Only download without installation, and specify the download directory to / opt /

Uninstall software

yum remove nginx  After uninstallation is completed, the configuration file will not be deleted and the log will not be deleted. 

Source package compilation and installation

Introduction to source package compilation

Code package refers to the source code written by the developer, but it can not be used directly. It needs to be compiled to become executable commands.

Source compilation and installation has several advantages over rpm:

1. You can see the source code. If you have the ability, you can develop it again

2. You can customize the installation path, run the user and other functions

Disadvantages:
The installation configuration is complex and standardization is difficult to implement.

Compilation and installation steps:

Download source code
./configure
make
make install
/opt/nginx/sbin/nginx -t                    Check syntax
/opt/nginx/sbin/nginx              
/opt/nginx/sbin/nginx -s reload
/opt/nginx/sbin/nginx -s stop 

Compilation and installation steps:

establish www Users and www group
groupadd www -g 1000
useradd  www -s /sbin/nologin -M -u 1000 -g 1000

Install dependent packages

yum install openssl-devel pcre-devel gcc -y

Download and unzip the source package

mkdir /data/soft -p                    #Create a directory to store the software
cd /data/soft/
wget http: //nginx.org/download/nginx-1.18.0.tar.gz
tar zxvf nginx-1.18.0.tar.gz

Configure compilation parameters

cd nginx-1.18.0                      #Adding a \ backslash tells the system that the command has not been executed, but the second line is added
./configure --help                # --Help view help information
./configure \
--user=www \
--group=www \
--prefix=/opt/nginx-1.19.9/ \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre

Compile and install

make && make install
 After the installation is completed, the opt A new one will be created under the directory nginx-1.19.9
[root@centos7-100 opt]# ls
nginx-1.19.9  others  owner

Create soft connection

ln -s /opt/nginx-1.19.9/ /opt/nginx
ls -l /opt/nginx                      #View soft connection details
[root@centos7-100 opt]# ls -l /opt/nginx
lrwxrwxrwx. 1 root root 18 10 May 13:39 /opt/nginx -> /opt/nginx-1.19.9/

Check syntax

[root@centos7-100 opt]# /opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx-1.19.9//conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx-1.19.9//conf/nginx.conf test is successful

Start service

[root@centos7-100 opt]# /opt/nginx/sbin/nginx 
[root@centos7-100 opt]# 

View nginx version

[root@centos7-100 opt]# /opt/nginx/sbin/nginx -v
nginx version: nginx/1.18.0

Inspection Service

curl 127.0.0.1

Posted by saqibb on Thu, 28 Oct 2021 04:10:24 -0700