Centos8编译安装Nginx

一,nginx的官网:

1
http://nginx.org/

二,下载与解压nginx

1,下载

1
[root@centos8 source]# wget http://nginx.org/download/nginx-1.18.0.tar.gz

2, 解压缩

1
[root@centos8 source]# tar -zxvf nginx-1.18.0.tar.gz 

三,编译与安装nginx

1,configure

#–prefix 指定安装路径

#–with-http_stub_status_module 允许查看nginx状态的模块

# –with-http_ssl_module 支持https的模块

1
[root@centos8 nginx-1.18.0]# ./configure --prefix=/usr/local/soft/nginx-1.18.0 --with-http_stub_status_module --with-http_ssl_module

2,编译并安装

1
[root@centos8 nginx-1.18.0]# make && make install

四, configure报错的解决

说明:如果相应的软件包已安装不会报错,写在这里供参考

1,问题1,configure提示:

1
2
3
4
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

解决:

1
[root@os3 nginx-1.18.0]# yum install pcre-devel

2,问题2,configure提示:

1
2
3
4
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

解决:

1
[root@os3 nginx-1.18.0]# yum install openssl openssl-devel 

五,测试编译安装的效果:查看nginx的版本

1
2
[root@centos8 nginx-1.18.0]# /usr/local/soft/nginx-1.18.0/sbin/nginx -v
nginx version: nginx/1.18.0

六,如何查看nginx的配置编译参数?

复制代码

1
2
3
4
5
6
[root@centos8 nginx-1.18.0]# /usr/local/soft/nginx-1.18.0/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)
built with OpenSSL 1.1.1c FIPS 28 May 2019
TLS SNI support enabled
configure arguments: --prefix=/usr/local/soft/nginx-1.18.0 --with-http_stub_status_module --with-http_ssl_module

复制代码

注意区分和上一条查看版本命令的区别: -v参数分别是小写和大写

七,使systemctl能管理运行nginx服务

1,运行的准备工作:配置日志目录

1
2
[root@centos8 conf]# mkdir /data/nginx
[root@centos8 conf]# mkdir /data/nginx/logs

2,运行的准备工作:创建nginx用户

1
[root@centos8 conf]# groupadd nginx

#-g:指定所属的group

#-s:指定shell,因为它不需要登录,所以用/sbin/nologin

#-M:不创建home目录,因为它不需要登录

1
[root@centos8 conf]# useradd -g nginx -s /sbin/nologin -M nginx 

3,简单配置nginx

1
[root@centos8 conf]# vi nginx.conf

内容:

指定运行nginx的用户和组是:nginx

1
user nginx nginx;

发生错误时要写入到错误日志(目录用上面创建好的)

1
error_log   /data/nginx/logs/error.log;

指定pid的路径

1
pid        logs/nginx.pid;

日志格式(取消注释即可)

1
2
3
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

指定访问日志的路径和格式(目录用上面创建好的)

1
access_log  /data/nginx/logs/access.log  main;

4,生成service文件:

1
[root@centos8 ~]# vi /usr/lib/systemd/system/nginx.service

内容:

复制代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=nginx-The High-performance HTTP Server
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/soft/nginx-1.18.0/logs/nginx.pid
ExecStartPre=/usr/local/soft/nginx-1.18.0/sbin/nginx -t -c /usr/local/soft/nginx-1.18.0/conf/nginx.conf
ExecStart=/usr/local/soft/nginx-1.18.0/sbin/nginx -c /usr/local/soft/nginx-1.18.0/conf/nginx.conf
ExecReload=/usr/local/soft/nginx-1.18.0/sbin/nginx -s reload
ExecStop=/usr/local/soft/nginx-1.18.0/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

复制代码

5,启动服务

重新加载服务文件

1
[root@centos8 ~]# systemctl daemon-reload 

启动:

1
[root@centos8 ~]# systemctl start nginx

6,查看效果:

从浏览器访问安装机器的ip的80端口即可:

看例子截图:

img

7,查看日志目录

1
2
3
4
[root@centos8 conf]# ll /data/nginx/logs/
总用量 8
-rw-r--r-- 1 root root 1477 4月 22 18:49 access.log
-rw-r--r-- 1 root root 1195 4月 22 18:32 error.log

日志已成功写入

八,查看centos版本

1
2
[root@centos8 ~]# cat /etc/redhat-release 
CentOS Linux release 8.1.1911 (Core)
ass="gutter">
1
vi /etc/profile

大G 到最后一行

o 插入一行

1
2
3
export JAVA_HOME=/root/apps/jdkhome
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile

查询外网IP的办法

Curl纯文本格式输出

1
2
3
4
5
6
7
curl icanhazip.com
curl ifconfig.me
curl curlmyip.com
curl ip.appspot.com
curl ipinfo.io/ip
curl ipecho.net/plain
curl www.trackip.net/i

Curl JSON格式输出

1
2
3
curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json

Curl XML格式输出

1
curl ifconfig.me/all.xml

Curl 得到所有IP细节 (挖掘机)

1
curl ifconfig.me/all

使用 DYDNS (当你使用 DYDNS 服务时有用)

1
2
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"

使用 Wget 代替 Curl

1
2
wget http://ipecho.net/plain -O - -q ; echo
wget http://observebox.com/ip -O - -q ; echo

使用 host 和 dig 命令

1
2
host -t a dartsclink.com | sed 's/.*has address //'
dig +short myip.opendns.com @resolver1.opendns.com

bash 脚本示例

1
2
3
#!/bin/bash
PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP

安装ftp

1
yum -y install vsftpd

CentOS上用python调用FFMepg将m3u8合成MP4后显示异常的问题

(1)判断是否有中文包

1
locale -a

(2)如果没有中文包,则使用如下命令下载

1
yum install langpacks-zh_CN.noarch

multipass虚拟机安装

官网:https://multipass.run/

/proc/kcore 128T内存爆满问题处理

1
2
3
4
5
6
7
8
# 列出磁盘使用率
df -h
# 列出删除列表
lsof | grep delete
# 删除任务
kill XXXX
kill YYYY
....

查询大文件

1
find / -type f -size +1G

#(Centos7.9)端口号管理

开放端口

1
2
3
4
5
6
# 开放5672端口
firewall-cmd --zone=public --add-port=5672/tcp --permanent
# 关闭5672端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent
# 配置立即生效
firewall-cmd --reload

查看防火墙所有开放的端口

1
firewall-cmd --zone=public --list-ports

关闭/开启防火墙

1
2
systemctl stop firewalld.service
systemctl start firewalld.service

查看防火墙状态

1
firewall-cmd --state

查看监听的端口

1
netstat -lnpt

检查端口被哪个进程占用

1
netstat -lnpt | grep 18788