Linux 編譯安裝、壓縮打包、定時任務



image


Linux 編譯安裝

編譯安裝就是使用源代碼安裝,編譯打包軟件

知識儲備:

wget命令

  • 簡介:

wget命令用來從指定的URL下載文件。wget非常穩定,它在帶寬很窄的情況下和不穩定網絡中有很強的適應性,如果是由於網絡的原因下載失敗,wget會不斷的嘗試,直到整個文件下載完畢。如果是服務器打斷下載過程,它會再次聯到服務器上從停止的地方繼續下載。這對從那些限定了鏈接時間的服務器上下載大文件非常有用。

  • 格式:

    wget [選項] [參數] ------ (用哪個參數man一下就可以了)


編譯安裝

  1. 編譯安裝的特點

    • 可以自定制軟件
    • 按需構建軟件
  2. 編譯安裝的步驟

    👉[nginx官網](nginx: download)

    以nginx為例

# 1、下載源代碼包
wget https://nginx.org/download/nginx-1.20.2.tar.gz

# 2、解壓
tar -xf nginx-1.20.2.tar.gz

# 3、設置系統參數
cd nginx-1.20.2
# 4、自定制404界面
vim ./src/core/nginx.h # 修改的內容如下圖
# 4.1、設置系統參數
./configure 

# 5、編譯
make
# 6、安裝
make install

# 安裝好后,目錄/usr/local下就會多了nginx目錄
# 7、啟動
/usr/local/nginx/sbin/nginx
# 7.1、關閉服務
/usr/local/nginx/sbin/nginx -s stop
systemctl stop nginx

image

image


Linux 壓縮打包

gzip壓縮

  • 命令:
    • 壓縮:gzip [壓縮文件]
    • 解壓:gzip -d [解壓文件]
  # a.txt 是我提前建好的
  # 壓縮
  [root@localhost test]# gzip a.txt 
  [root@localhost test]# ls
  a.txt.gz
  # 解壓
  [root@localhost test]# gzip -d a.txt.gz 
  [root@localhost test]# ls
  a.txt

bzip2壓縮

  • 命令:
    • 壓縮:bzip2 [壓縮文件]
    • 解壓:bzip2 -d [壓縮包]
# 壓縮
[root@localhost test]# bzip2 a.txt 
[root@localhost test]# ls
a.txt.bz2
# 解壓
[root@localhost test]# bzip2 -d a.txt.bz2 
[root@localhost test]# ls
a.txt

由於gzipbzip2無法壓縮目錄,使用tar命令

# 無法壓縮命令
[root@localhost ~]# gzip test
gzip: test is a directory -- ignored

tar打包

  • 命令

    • tar [參數] [打包文件]

    • 參數:

      • -f : 指定打包的包名稱

      • -c : 打包

      • -v : 顯示打包的過程

      • -z : 使用gzip壓縮壓縮包

      • -j : 使用bzip2壓縮壓縮包

      • -x : 解壓(解壓不需要指定壓縮類型)

      • -t : 查看壓縮包內部的內容

      • -P :忽略使用絕對路徑時報出的錯誤

注意:

  1. 壓縮時是什么路徑,解壓縮時就是什么路徑,所以為了安全不要使用絕對路徑壓縮。
  2. -f參數后面永遠跟壓縮包名稱(-f放最后)
# -fc參數的使用,指定打包的包名稱,並打包
[root@localhost ~]# tar -cf test.tar test
[root@localhost ~]# ll
-rw-r--r--  1 root root 10240 Dec 17 19:26 test.tar
# 使用gzip壓縮
[root@localhost ~]# gzip test.tar 
[root@localhost ~]# ll
-rw-r--r--  1 root root  211 Dec 17 19:26 test.tar.gz


# 使用參數直接打包壓縮
[root@localhost ~]# tar -czf test.tar.gz test
[root@localhost ~]# ll
-rw-r--r--  1 root root  202 Dec 17 19:40 test.tar.gz

# 解壓
[root@localhost ~]# tar -xf test.tar.gz 

Linux 定時任務

定時任務類似生活中使用的鬧鍾,可以自動完成操作命令,定時備份系統數據信息等功能

相關文件及操作

目錄下寫可執行文件(x.sh),就會自動執行

  • 系統定時任務周期:每小時

    • 控制定時任務目錄:/etc/cron.hourly
    [root@localhost cron.hourly]# cd /etc/cron.hourly/
    [root@localhost cron.hourly]# ll
    total 4
    -rwxr-xr-x. 1 root root 392 Aug  9  2019 0anacron
    
  • 系統定時任務周期:每一天

    • 控制定時任務目錄:/etc/cron.daily
    [root@localhost cron.hourly]# cd /etc/cron.daily/
    [root@localhost cron.daily]# ll
    total 8
    -rwx------. 1 root root 219 Apr  1  2020 logrotate
    -rwxr-xr-x. 1 root root 618 Oct 30  2018 man-db.cron
    
  • 系統定時任務周期:每一周

    • 控制定時任務目錄:/etc/cron.weekly
    [root@localhost cron.monthly]# cd /etc/cron.weekly/
    
  • 系統定時任務周期:每個月

    • 控制定時任務目錄:/etc/cron.monthly
    [root@localhost cron.daily]# cd /etc/cron.monthly/
    
  • 系統定時任務的配置文件之一 : /etc/crontab

image

  • 實際操作:

  • 添加定時任務:crontab -e

  • 查看定時任務:crontab -l

# *  *  *  *  *  : crontab表達式
# 案例:每天的凌晨2:50執行/root/1.sh
# 在1.sh中添加執行語句
# 添加任務
[root@localhost etc]# crontab -e   
# 查看定時任務
[root@localhost etc]# crontab -l
#Timing synchronization time
0 */1 * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null

image


  • 定時任務配置文件 : /var/spool/cron/root

    每一個用戶的定時任務是相對隔離,在/var/spool/cron目錄下,以當前用戶的用戶名命名的文件。

  • 定時任務格式

    # * 代表每的意思
    基礎格式 : * * * * *
    每隔2分鍾執行
    	*/2 * * * *
    		
    每天的2,4,6,8,10這4個小時的1分鍾執行
    	01 2,4,6,10 * * * 
    		
    每天的2到6點執行
    	00 2-6 * * *
    	
    每天的2到6點中每隔2小時執行
    	00 2-6/2 * * *
    		
    00 02 * * 02   : 每天的2點時執行,但是這天必須時周二
    
  • 定時任務服務運行記錄日志文件 : /var/log/cron

    • 查看日志命令:

      • head/tail

        • -n : 查看指定多少行
      • tail/tail -f

        • -f : 監控文件變化
      • less

  • 定時任務服務禁止用戶運行名單 : /etc/cron.deny(定時任務黑名單)


image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM