编译安装&打包压缩&定时任务

内容概要

  • 编译安装
  • 打包压缩
  • 定时任务

内容详细

一、编译安装

1、特点

使用源代码,编译打包软件。

​ 1、可以自定制软件
​ 2、按需构建软件啊

2、步骤

下载安装包

	wget 下载网址
	如果没有 wget : yum install wget

[root@localhost ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz
[root@localhost ~]# ll
total 1044
-rw-------. 1 root root    1691 Dec  8 17:25 anaconda-ks.cfg
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz

解压安装包

	tar -xf <安装包名>

[root@localhost ~]# tar -xf nginx-1.20.2.tar.gz
[root@localhost ~]# ll
total 1044
-rw-------. 1 root root    1691 Dec  8 17:25 anaconda-ks.cfg
drwxr-xr-x. 8 1001 1001     158 Nov 16 22:44 nginx-1.20.2
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz

修改参数

    1、cd nginx-1.20.2
    2、vim src/core/nginx.h		# 修改NGINX_VER参数
    3、.configure 

[root@localhost ~]# cd nginx-1.20.2
[root@localhost nginx-1.20.2]# ll
total 792
drwxr-xr-x. 6 1001 1001   4096 Dec 17 16:13 auto
drwxr-xr-x. 2 1001 1001    168 Dec 17 16:13 conf
-rwxr-xr-x. 1 1001 1001   2590 Nov 16 22:44 configure
drwxr-xr-x. 9 1001 1001     91 Dec 17 16:13 src

[root@localhost nginx-1.20.2]# vim src/core/nginx.h

[root@localhost nginx-1.20.2]# ./configure 

# 如果报错 : ./configure: error: the HTTP rewrite module requires the PCRE library.
执行 : yum install pcre pcre-devel zlib zlib-devel -y

image

编译

make

安装

make install

启动软件并访问虚拟机网址测试

# 执行 nginx
/usr/local/nginx/sbin/nginx

# 如果启动失败
    将可执行文件路径添加到PATH(方便启动nginx)

    vim ~/.bashrc 

    #在bashrc配置文件末尾追加nginx守护进程的路径
    export PATH=$PATH:/usr/local/nginx/sbin

    #保存退出后使配置文件生效
    source ~/.bashrc

# 还是启动失败
	1、
    [root@server /]# nginx
    nginx: [emerg] still could not bind()
     查看80端口是否被占用
    [root@server /]# usr/sbin/lsof -i :80
    COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    httpd    1326   root    4u  IPv6  26961      0t0  TCP *:http (LISTEN)
    httpd   10589 apache    4u  IPv6  26961      0t0  TCP *:http (LISTEN)
    httpd   10591 apache    4u  IPv6  26961      0t0  TCP *:http (LISTEN)
    httpd   10593 apache    4u  IPv6  26961      0t0  TCP *:http (LISTEN)
    httpd   10594 apache    4u  IPv6  26961      0t0  TCP *:http (LISTEN)
    httpd   10595 apache    4u  IPv6  26961      0t0  TCP *:http (LISTEN)

    #关闭httpd服务
    [root@server /]# systemctl stop httpd
 
    2、解决办法:

    根据Nginx配置文件查看配置的端口(本文中使用的是80端口),然后根据端口查看端口占用情况

    [root@xyw-cyck-cms-3 ~]# netstat -ntlp|grep 80  
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               		LISTEN      7043/nginx: worker
    使用kill命令杀死占用进程,之后重新启动Nginx

system start nginx


如果访问网址失败,应该是防火墙和selinux没关掉

关闭selinux和firewalld
	systemctl disable --now firewalld
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0

image

二·、打包压缩

1、常见压缩工具与压缩命令

压缩工具

windows : zip 、rar

Linux : gzip 、 bzip2

操作命令

前提 :压缩操作只能压缩文件,不能压缩文件夹,文件夹需要经过打包之后才能进行压缩

压缩 : gzip <文件名>
解压 : gzip -d <压缩包>

压缩 : bzip2 <文件名>
解压 : bzip2 -d <压缩包>

小文件压缩可能内存反而变大,因为要加入压缩算法
无法压缩目录

原文件:
	-rw-------. 1 root root    1691 Dec  8 17:25 anaconda-ks.cfg
压缩后:文件变小
[root@localhost ~]# gzip anaconda-ks.cfg 
[root@localhost ~]# ll
total 1044
-rw-------. 1 root root     883 Dec  8 17:25 anaconda-ks.cfg.gz
解压:
[root@localhost ~]# gzip -d anaconda-ks.cfg.gz 
[root@localhost ~]# ll
total 1044
-rw-------. 1 root root    1691 Dec  8 17:25 anaconda-ks.cfg

2、打包文件

打包命令

	命令 : tar
	需要指定参数,因为 tar 既有打包又有解包的功能,
	打包 : -c

    tar -c -f <压缩后名称> <目录名>

    目录名不能用绝对路径,会报错
# 打包
[root@localhost ~]# tar -c -f nginx-1.tar nginx-1.20.2
[root@localhost ~]# ll
total 20004
drwxr-xr-x. 9 1001 1001      186 Dec 17 16:23 nginx-1.20.2
-rw-r--r--. 1 root root 19415040 Dec 17 19:17 nginx-1.tar
# 压缩
[root@localhost ~]# gzip nginx-1.tar
[root@localhost ~]# ll
total 6196
drwxr-xr-x. 9 1001 1001     186 Dec 17 16:23 nginx-1.20.2
-rw-r--r--. 1 root root 5273306 Dec 17 19:17 nginx-1.tar.gz	< -- 压缩过后
# 打包后用 zip 压缩,并显示压缩过程, 压缩参数 -z 得和打包 -c 一起使用,单独无法使用
[root@localhost ~]# tar -c -v -z -f nginx-1.2.tar nginx-1.20.2

注意 : -f 参数后面一定要跟着压缩后的 压缩包名

# 用 tar 命令解压:
[root@localhost ~]# tar -xf nginx-1.20.2.tar.gz
[root@localhost ~]# ll
total 25156
drwxr-xr-x. 8 1001 1001      158 Nov 16 22:44 nginx-1.20.2

参数

参数:
    -f : 指定打包的包名称
    -c : 打包
    -v : 显示打包的过程
    -z : 使用gzip压缩压缩包
    -j : 使用bzip2压缩压缩包

    -x : 解压(解压不需要指定压缩类型)

    -t : 查看压缩包内部的内容

    -P :忽略使用绝对路径时报出的错误

注意:
    1、压缩时是什么路径,解压缩时就是什么路径,所以为了安全不要使用绝对路径压缩。
    2、-f参数后面永远跟压缩包名称

三、定时任务

1、定时应用

在工作中,有些执行脚本需要在凌晨或者一些固定的时间点执行,可以给脚本设置定时任务,到点直接执行程序,无须人工手动操作

2、定时配置文件目录与格式

定时文件目录

/etc/crontab

格式

* * * * * crontab
分  时  天  月  周几

3、定时使用

posted @ 2021-12-17 20:14  elijah_li  阅读(53)  评论(1编辑  收藏  举报
//一下两个链接最好自己保存下来,再上传到自己的博客园的“文件”选项中