主頁 > 作業系統 > 自動化運維工具之Puppet常用資源(二)

自動化運維工具之Puppet常用資源(二)

2020-12-03 06:05:19 作業系統

  前文我們了解了部分puppet的資源的使用,以及資源和資源的依賴關系的定義,回顧請參考https://www.cnblogs.com/qiuhom-1874/p/14071459.html;今天我們繼續puppet常用資源的使用相關話題;

  1、file:該資源型別主要用來管理被控端主機上的檔案;該資源作用相當于ansible中的copy和file兩個模塊的功能;它可以實作檔案的新建,洗掉,復制等功能;

  主要屬性

    ensure:用于描述檔案的型別和目標狀態的,常用的檔案型別有3中,第一種是普通檔案(file),其內容由content屬性生成或復制由source屬性指向的檔案路徑來創建;第二種是目錄(directory),可通過source指向的路徑復制生成,recurse屬性指明是否遞回復制;第三種是符合鏈接檔案(link),必須由target屬性指明其鏈接的目標檔案;取值有present/absent,file,directory,link;

    path:檔案路徑(namevar)

    source:源檔案;

    content:檔案內容;

    target:符號鏈接的目標檔案;

    owner:屬主;

    group:屬組;

    mode:權限;

    ctime/mtime:時間戳;

  示例:指定內容創建新檔案

[root@node12 ~]# cat file.pp
file{"/tmp/test.txt":
        ensure  => file,
        content => "this is test file",
        mode    => 0644,
        owner   => 'jerry',
        group   => 'root'
}
[root@node12 ~]#

  提示:以上資源清單定義了在/tmp目錄下新建一個test.txt的檔案,其檔案內容是“this is test file”,屬主是jerry,屬組是root,權限是0644;

  檢查資源清單語法

[root@node12 ~]# puppet apply -v --noop file.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606886216'
Notice: /Stage[main]/Main/File[/tmp/test.txt]/ensure: current_value absent, should be file (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# 

  應用資源清單

[root@node12 ~]# ll /tmp   
total 0
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
[root@node12 ~]# puppet apply -v  file.pp       
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606886384'
Notice: /Stage[main]/Main/File[/tmp/test.txt]/ensure: defined content as '{md5}973131af48aa1d25bf187dacaa5ca7c0'
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# 

  驗證:查看/tmp/目錄下是否生成了test.txt檔案,內容和屬主,屬組和權限是否是我們指定的內容呢?

[root@node12 ~]# ll /tmp   
total 4
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# cat /tmp/test.txt 
this is test file[root@node12 ~]# 

  提示:可以看到在/tmp目錄下生成了test.txt檔案,其屬主是jerry,屬組是root,權限是644,內容是“this is test file”,完全是我們指定的屬性;

  示例:復制一個檔案生成另一個檔案

[root@node12 ~]# cat copyfile.pp
file{"/tmp/test1":
        ensure  => file,
        source  => '/etc/issue',
        owner   => 'jerry',
        group   => 'jerry',
        mode    => 400,
}
[root@node12 ~]#

  驗證:應用資源清單,看看對應/tmp/目錄下是否會生成test1檔案?檔案屬主屬組和權限資訊是否是我們指定的屬性資訊呢?

[root@node12 ~]# ll /tmp
total 4
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# puppet apply -v --noop copyfile.pp
Notice: Compiled catalog for node12.test.org in environment production in 0.06 seconds
Info: Applying configuration version '1606886863'
Notice: /Stage[main]/Main/File[/tmp/test1]/ensure: current_value absent, should be file (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds
[root@node12 ~]# puppet apply -v  copyfile.pp      
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606886868'
Notice: /Stage[main]/Main/File[/tmp/test1]/ensure: defined content as '{md5}f078fe086dfc22f64b5dca2e1b95de2c'
Notice: Finished catalog run in 0.04 seconds
[root@node12 ~]# ll /tmp
total 8
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# cat /tmp/test1
\S
Kernel \r on an \m

[root@node12 ~]# 

  提示:可以看到對應目錄下生成了我們指定的檔案,其內容是我們指定的source屬性所對應的檔案內容;屬主/組和權限都是我們指定的屬性;

  示例:創建空目錄

[root@node12 ~]# cat directory.pp
file{"/tmp/test":
        ensure  => directory,
        owner   => 'jerry',
        group   => 'jerry',
        mode    => 755,
}
[root@node12 ~]# 

  應用資源清單并驗證對應目錄是否創建?

[root@node12 ~]# ll /tmp/
total 8
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# puppet apply -v --noop directory.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606887273'
Notice: /Stage[main]/Main/File[/tmp/test]/ensure: current_value absent, should be directory (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# puppet apply -v  directory.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606887279'
Notice: /Stage[main]/Main/File[/tmp/test]/ensure: created
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# ll /tmp
total 8
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# 

  示例:復制目錄

[root@node12 ~]# cat copydirectory.pp
file{"copy directory":
        ensure  => directory,
        path    => '/tmp/test.repos.d',
        source  => '/etc/yum.repos.d/'
}
[root@node12 ~]# 

  應用資源清單并且驗證對應目錄是否生成?

[root@node12 ~]# puppet apply -v copydirectory.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606887595'
Notice: /Stage[main]/Main/File[copy directory]/ensure: created
Notice: Finished catalog run in 0.04 seconds
[root@node12 ~]# ll /tmp
total 8
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 2 root   root    6 Dec  2 13:39 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# ll /tmp/test.repos.d/
total 0
[root@node12 ~]# 

  提示:這里只是復制了一個空目錄過來,對應目錄下沒有任何檔案,如果需要遞回復制,需要加上recurse屬性為true;

  遞回復制目錄

[root@node12 ~]# cat copydirectory.pp
file{"copy directory":
        ensure  => directory,
        path    => '/tmp/test.repos.d',
        source  => '/etc/yum.repos.d/',
        recurse => true
}
[root@node12 ~]# puppet apply -v copydirectory.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606887954'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/centos7-aliyun-epel.repo]/ensure: defined content as '{md5}ad7e2bf9550cde4f863d5157d9dea4cb'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak/CentOS-Base.repo]/ensure: defined content as '{md5}9098fc723b1e00c92e8515f06980d83e'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak/CentOS-Debuginfo.repo]/ensure: defined content as '{md5}e9e506425094f43b5c8f053090dbf4d4'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak/CentOS-Vault.repo]/ensure: defined content as '{md5}9fdd3d91192aa05427c3a9684eeb1345'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak/CentOS-CR.repo]/ensure: defined content as '{md5}445ed4f0ee3888384e854fb8527a7cde'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak/CentOS-Sources.repo]/ensure: defined content as '{md5}04d662bb1648477bf50e658a20c10145'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/CentOS-Base.repo]/ensure: defined content as '{md5}4861d3b742e8e8c05b67e3abf7904f17'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/mongodb.repo]/ensure: defined content as '{md5}fbe938506cda5002d9b8068e6bb4a355'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak/CentOS-Media.repo]/ensure: defined content as '{md5}1d7797c5082bd565facd68c5aa9352bf'
Notice: /Stage[main]/Main/File[/tmp/test.repos.d/bak/CentOS-fasttrack.repo]/ensure: defined content as '{md5}52d296f7a45f56c85d18473eca5bab16'
Notice: Finished catalog run in 0.12 seconds
[root@node12 ~]# ll /tmp/test.repos.d/
total 12
drwxr-xr-x 2 root root  187 Dec  2 13:45 bak
-rw-r--r-- 1 root root  665 Dec  2 13:45 centos7-aliyun-epel.repo
-rw-r--r-- 1 root root 2524 Dec  2 13:45 CentOS-Base.repo
-rw-r--r-- 1 root root  206 Dec  2 13:45 mongodb.repo
[root@node12 ~]# ll /tmp/test.repos.d/bak/
total 28
-rw-r--r-- 1 root root 1664 Dec  2 13:45 CentOS-Base.repo
-rw-r--r-- 1 root root 1309 Dec  2 13:45 CentOS-CR.repo
-rw-r--r-- 1 root root  649 Dec  2 13:45 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root  314 Dec  2 13:45 CentOS-fasttrack.repo
-rw-r--r-- 1 root root  630 Dec  2 13:45 CentOS-Media.repo
-rw-r--r-- 1 root root 1331 Dec  2 13:45 CentOS-Sources.repo
-rw-r--r-- 1 root root 3830 Dec  2 13:45 CentOS-Vault.repo
[root@node12 ~]# 

  提示:可以看到在資源清單中加上recurse屬性為true后,再次執行資源清單,對應源目錄下的所有檔案,子目錄及檔案都遞回的復制到path所指定的目錄下了;這里需要注意一點,如果源是檔案,目標是目錄,則復制過去的是一個檔案并非是把檔案復制到目錄下;所以puppet中的檔案復制是同型別檔案間的復制;

  創建符號鏈接檔案

[root@node12 ~]# cat createlink.pp
file{"create link file":
        ensure  => link,
        path    => '/tmp/passwd',
        target  => '/etc/passwd',
}
[root@node12 ~]#

  提示:以上資源清單定義了把/tmp/passwd檔案連接至/etc/passwd,即在創建/tmp/passwd符號連接檔案,并將其目標鏈接檔案指向/etc/passwd檔案;

  應用清單檔案,看看對應符號鏈接檔案是否生成?

[root@node12 ~]# ll /tmp
total 8
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 3 root   root   93 Dec  2 13:45 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# puppet apply -v --noop createlink.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.05 seconds
Info: Applying configuration version '1606888721'
Notice: /Stage[main]/Main/File[create link file]/ensure: current_value absent, should be link (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# puppet apply -v  createlink.pp       
Notice: Compiled catalog for node12.test.org in environment production in 0.06 seconds
Info: Applying configuration version '1606888731'
Notice: /Stage[main]/Main/File[create link file]/ensure: created
Notice: Finished catalog run in 0.04 seconds
[root@node12 ~]# ll /tmp
total 8
srwx------ 1 mongod mongod  0 Dec  2 13:04 mongodb-27017.sock
lrwxrwxrwx 1 root   root   11 Dec  2 13:58 passwd -> /etc/passwd
drwx------ 3 root   root   17 Dec  2 13:04 systemd-private-d48e3508588440ff9b36efa29faed224-chronyd.service-V7fHnq
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 3 root   root   93 Dec  2 13:45 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# 

  提示:可以看到/tmp目錄下生成了一個passwd的符號鏈接檔案,并目標鏈接檔案指向的是/etc/passwd檔案;

   定義資源與資源間的通知或訂閱關系

  我們知道一個服務的組態檔發生了變化,如果要讓其配置生效,通常會重新啟動服務或重新載入組態檔內容;在ansible中當一個服務的組態檔發生變化,是通過定義handler和notify來觸發對應的服務執行重啟或多載配置操作;在puppet中當一個服務的組態檔發生變化觸發對應服務重啟或重新載入配置,需要定義資源與資源間的通知或訂閱關系;其語法如下

  notify:前資源通知后資源

{
    ...
    notify => Type['B'],
    ...
}

  subscribe:后資源訂閱前資源

{
    ...
    subscribe => Type['B'],
    ...
}

  提示:以上兩種方式選擇其中一種即可;這里需要注意的是參考資源其型別首字母必須大寫;同時定義資源與資源通知或訂閱關系,其隱含了資源執行的先后順序(依賴關系);

  示例:定義安裝redis,提供組態檔,和啟動服務,并且當組態檔發生變化通知redis服務重啟;

[root@node12 ~]# cat redis.pp 
package{"redis":
        ensure  => installed,
}

file{"/etc/redis.conf":
        ensure  => file,
        source  => '/root/redis.conf',
        notify  => Service["redis"],
}

service{"redis":
        ensure  => running,
        enable  => true,
        hasrestart      => true,
        restart => 'systemctl restart redis',
}
[root@node12 ~]# 

  提示:以上資源清單中定義了3個資源,并且指定了當組態檔發生變化就通知redis服務重啟;

  上述清單在file資源中通知service資源,我們也可以在service中訂閱file資源;如下

[root@node12 ~]# cat redis.pp
package{"redis":
        ensure  => installed,
}

file{"/etc/redis.conf":
        ensure  => file,
        source  => '/root/redis.conf',
#       notify  => Service["redis"],
}

service{"redis":
        ensure  => running,
        enable  => true,
        hasrestart      => true,
        restart => 'systemctl restart redis',
        subscribe       => File["/etc/redis.conf"],
}
[root@node12 ~]# 

  除了上述方式,我們也可以定義通知/訂閱資源鏈

[root@node12 ~]# cat redis.pp
package{"redis":
        ensure  => installed,
}

file{"/etc/redis.conf":
        ensure  => file,
        source  => '/root/redis.conf',
#       notify  => Service["redis"],
}

service{"redis":
        ensure  => running,
        enable  => true,
        hasrestart      => true,
        restart => 'systemctl restart redis',
#        subscribe       => File["/etc/redis.conf"],
}

Package["redis"] -> File["/etc/redis.conf"] ~> Service["redis"]

[root@node12 ~]# 

  提示:定義通知/訂閱資源鏈,需要用到~>來表示前資源發生變化通知后資源;

  本地redis.conf內容

[root@node12 ~]# cat redis.conf 
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@node12 ~]# 

  提示:以上內容是默認redis配置,我們只修改了其監聽地址為0.0.0.0;

  應用資源清單

[root@node12 ~]# rpm -q redis
package redis is not installed
[root@node12 ~]# ss -tnl
State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
LISTEN     0      128                        *:22                                     *:*                  
LISTEN     0      100                127.0.0.1:25                                     *:*                  
LISTEN     0      128                        *:27017                                  *:*                  
LISTEN     0      128                       :::22                                    :::*                  
LISTEN     0      100                      ::1:25                                    :::*                  
[root@node12 ~]# puppet apply -v --noop redis.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.29 seconds
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1606891263'
Notice: /Stage[main]/Main/Package[redis]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Main/File[/etc/redis.conf]/ensure: current_value absent, should be file (noop)
Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Notice: /Stage[main]/Main/Service[redis]/ensure: current_value stopped, should be running (noop)
Info: /Stage[main]/Main/Service[redis]: Unscheduling refresh on Service[redis]
Notice: Class[Main]: Would have triggered 'refresh' from 3 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.12 seconds
[root@node12 ~]# puppet apply -v  redis.pp       
Notice: Compiled catalog for node12.test.org in environment production in 0.30 seconds
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1606891271'
Notice: /Stage[main]/Main/Package[redis]/ensure: created
Info: /Stage[main]/Main/File[/etc/redis.conf]: Filebucketed /etc/redis.conf to puppet with sum d98629fded012cd2a25b9db0599a9251
Notice: /Stage[main]/Main/File[/etc/redis.conf]/content: content changed '{md5}d98629fded012cd2a25b9db0599a9251' to '{md5}12e59b058c0ef61ad52bcfa2d4de58ff'
Notice: /Stage[main]/Main/File[/etc/redis.conf]/owner: owner changed 'redis' to 'root'
Notice: /Stage[main]/Main/File[/etc/redis.conf]/mode: mode changed '0640' to '0644'
Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Notice: /Stage[main]/Main/Service[redis]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Main/Service[redis]: Unscheduling refresh on Service[redis]
Notice: Finished catalog run in 4.81 seconds
[root@node12 ~]# ss -tnl
State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
LISTEN     0      128                        *:6379                                   *:*                  
LISTEN     0      128                        *:22                                     *:*                  
LISTEN     0      100                127.0.0.1:25                                     *:*                  
LISTEN     0      128                        *:27017                                  *:*                  
LISTEN     0      128                       :::22                                    :::*                  
LISTEN     0      100                      ::1:25                                    :::*                  
[root@node12 ~]# grep -Ei "^bind|port" /etc/redis.conf 
bind 0.0.0.0
port 6379
[root@node12 ~]#

  提示:可以看到應用資源清單后,安裝redis包,提供配置,啟動服務就一并完成了;

  修改組態檔再次執行資源清單,看看對應服務是否會發生重啟,應用新配置呢?

[root@node12 ~]# grep -Ei "^bind|port" /root/redis.conf    
bind 0.0.0.0
port 16379
[root@node12 ~]# 

  提示:以上把/root/目錄下的redis.conf檔案中的prot修改成16379;

  執行資源清單

[root@node12 ~]# ss -tnl
State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
LISTEN     0      128                        *:6379                                   *:*                  
LISTEN     0      128                        *:22                                     *:*                  
LISTEN     0      100                127.0.0.1:25                                     *:*                  
LISTEN     0      128                        *:27017                                  *:*                  
LISTEN     0      128                       :::22                                    :::*                  
LISTEN     0      100                      ::1:25                                    :::*                  
[root@node12 ~]# puppet apply -v  redis.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.30 seconds
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1606891609'
Info: /Stage[main]/Main/File[/etc/redis.conf]: Filebucketed /etc/redis.conf to puppet with sum 12e59b058c0ef61ad52bcfa2d4de58ff
Notice: /Stage[main]/Main/File[/etc/redis.conf]/content: content changed '{md5}12e59b058c0ef61ad52bcfa2d4de58ff' to '{md5}13a04cb20de2d787e0e18c1c13560cab'
Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Notice: /Stage[main]/Main/Service[redis]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.26 seconds
[root@node12 ~]# ss -tnl
State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
LISTEN     0      128                        *:22                                     *:*                  
LISTEN     0      100                127.0.0.1:25                                     *:*                  
LISTEN     0      128                        *:16379                                  *:*                  
LISTEN     0      128                        *:27017                                  *:*                  
LISTEN     0      128                       :::22                                    :::*                  
LISTEN     0      100                      ::1:25                                    :::*                  
[root@node12 ~]# 

  提示:可以看到再次執行資源清單,對應服務也應用了新的配置,說明redis服務發生了重啟;我們定義的資源間通知或訂閱關系生效了;

  2、exec:該資源型別主要用于描述在被控端執行命令;

  主要屬性

    command:要執行的命令(namevar);

    creates:檔案路徑,僅此路徑表示的檔案不存在時,command方才執行;

    user/group:運行命令的用戶身份;

    cwd:切換作業目錄;

    path:命令搜索路徑,即在那些路徑下可以搜索到對應命令,類似PATH環境變數;

    onlyif:此屬性指定一個命令,此命令正常(退出碼為0)運行時,當前command才會運行;

    unless:此屬性指定一個命令,此命令非正常(退出碼為非0)運行時,當前command才會運行;

    refresh:重新執行當前command的替代命令;

    refreshonly:僅接收到訂閱的資源的通知時方才運行;

  示例:使用mkdir命令在被控端主機上創建目錄,條件是當指定的目錄不存在時才創建;

[root@node12 ~]# cat exec.pp
exec{"create directory":
        command => 'mkdir /tmp/tom',
        path    => '/bin:/sbin:/usr/bin:/usr/sbin',
        unless  => 'test -d /tmp/tom',
}
[root@node12 ~]# 

  提示:以上清單表示如果被控端的/tmp/tom不存在時,則在被控端執行mkdir /tmp/tom,執行mkdir這個命令的搜索路徑為/bin:/sbin:/usr/bin:/usr/sbin;

  應用清單,看看對應目錄是否會被創建?

[root@node12 ~]# ll /tmp/
total 8
srwx------ 1 mongod mongod  0 Dec  2 18:59 mongodb-27017.sock
lrwxrwxrwx 1 root   root   11 Dec  2 13:58 passwd -> /etc/passwd
drwx------ 3 root   root   17 Dec  2 18:59 systemd-private-62bd808f926f45528710005f2104130c-chronyd.service-wtp0Tm
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 3 root   root   93 Dec  2 13:45 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
[root@node12 ~]# puppet apply -v --noop exec.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.07 seconds
Info: Applying configuration version '1606907819'
Notice: /Stage[main]/Main/Exec[create directory]/returns: current_value notrun, should be 0 (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds
[root@node12 ~]# puppet apply -v  exec.pp       
Notice: Compiled catalog for node12.test.org in environment production in 0.02 seconds
Info: Applying configuration version '1606907836'
Notice: /Stage[main]/Main/Exec[create directory]/returns: executed successfully
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# ll /tmp/
total 8
srwx------ 1 mongod mongod  0 Dec  2 18:59 mongodb-27017.sock
lrwxrwxrwx 1 root   root   11 Dec  2 13:58 passwd -> /etc/passwd
drwx------ 3 root   root   17 Dec  2 18:59 systemd-private-62bd808f926f45528710005f2104130c-chronyd.service-wtp0Tm
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 3 root   root   93 Dec  2 13:45 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
drwxr-xr-x 2 root   root    6 Dec  2 19:17 tom
[root@node12 ~]# 

  提示:以上是/tmp/tom目錄不存在就創建,現在已經創建好了,再次執行命令按道理是要報錯說目錄已存在;

  驗證:再次執行清單,看看是否會報錯?

[root@node12 ~]# ll /tmp/
total 8
srwx------ 1 mongod mongod  0 Dec  2 18:59 mongodb-27017.sock
lrwxrwxrwx 1 root   root   11 Dec  2 13:58 passwd -> /etc/passwd
drwx------ 3 root   root   17 Dec  2 18:59 systemd-private-62bd808f926f45528710005f2104130c-chronyd.service-wtp0Tm
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 3 root   root   93 Dec  2 13:45 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
drwxr-xr-x 2 root   root    6 Dec  2 19:17 tom
[root@node12 ~]# puppet apply -v  exec.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.02 seconds
Info: Applying configuration version '1606907999'
Notice: Finished catalog run in 0.02 seconds
[root@node12 ~]# 

  提示:可以看到再次執行并沒有報錯,這是因為我們加了unless這個屬性去判斷是否滿足執行命令的條件;只有滿足執行命令的條件后,對應命令才可被執行;為了保證多次執行資源清單的冪等性,在執行某些不冪等的命令一定要加上條件;

  示例:當redis組態檔發生改變以后,就重啟redis

[root@node12 ~]# cat exec2.pp
exec{"systemctl restart redis":
        path    => '/bin:/sbin:/usr/bin:/usr/sbin',
        refreshonly     => true,
}

file{"/etc/redis.conf":
        ensure  => file,
        source  => '/root/redis.conf',
}

File["/etc/redis.conf"] ~> Exec["systemctl restart redis"]

[root@node12 ~]# 

  提示:以上清單內容表示當/etc/redis.conf檔案內容發生變化,就通知執行重啟redis服務命令;

  當前redis組態檔監聽埠

[root@node12 ~]# ss -tnl
State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
LISTEN     0      128                        *:22                                     *:*                  
LISTEN     0      100                127.0.0.1:25                                     *:*                  
LISTEN     0      128                        *:16379                                  *:*                  
LISTEN     0      128                        *:27017                                  *:*                  
LISTEN     0      128                       :::22                                    :::*                  
LISTEN     0      100                      ::1:25                                    :::*                  
[root@node12 ~]# grep -Ei "^bind|port" /etc/redis.conf 
bind 0.0.0.0
port 16379
[root@node12 ~]# 

  修改/root/redis.conf檔案中的埠資訊為6379

[root@node12 ~]# grep -Ei "^bind|port" /root/redis.conf    
bind 0.0.0.0
port 6379
[root@node12 ~]# 

  執行清單,看看對應redis是否會監聽在6379這個埠上?

[root@node12 ~]# ss -tnl
State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
LISTEN     0      128                        *:22                                     *:*                  
LISTEN     0      100                127.0.0.1:25                                     *:*                  
LISTEN     0      128                        *:16379                                  *:*                  
LISTEN     0      128                        *:27017                                  *:*                  
LISTEN     0      128                       :::22                                    :::*                  
LISTEN     0      100                      ::1:25                                    :::*                  
[root@node12 ~]# puppet apply -v --noop exec2.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.07 seconds
Info: Applying configuration version '1606909853'
Notice: /Stage[main]/Main/File[/etc/redis.conf]/content: current_value {md5}13a04cb20de2d787e0e18c1c13560cab, should be {md5}12e59b058c0ef61ad52bcfa2d4de58ff (noop)
Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Exec[systemctl restart redis]
Notice: /Stage[main]/Main/Exec[systemctl restart redis]: Would have triggered 'refresh' from 1 events
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.02 seconds
[root@node12 ~]# puppet apply -v exec2.pp        
Notice: Compiled catalog for node12.test.org in environment production in 0.07 seconds
Info: Applying configuration version '1606909859'
Info: FileBucket got a duplicate file {md5}13a04cb20de2d787e0e18c1c13560cab
Info: /Stage[main]/Main/File[/etc/redis.conf]: Filebucketed /etc/redis.conf to puppet with sum 13a04cb20de2d787e0e18c1c13560cab
Notice: /Stage[main]/Main/File[/etc/redis.conf]/content: content changed '{md5}13a04cb20de2d787e0e18c1c13560cab' to '{md5}12e59b058c0ef61ad52bcfa2d4de58ff'
Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Exec[systemctl restart redis]
Notice: /Stage[main]/Main/Exec[systemctl restart redis]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.11 seconds
[root@node12 ~]# ss -tnl
State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
LISTEN     0      128                        *:6379                                   *:*                  
LISTEN     0      128                        *:22                                     *:*                  
LISTEN     0      100                127.0.0.1:25                                     *:*                  
LISTEN     0      128                        *:27017                                  *:*                  
LISTEN     0      128                       :::22                                    :::*                  
LISTEN     0      100                      ::1:25                                    :::*                  
[root@node12 ~]# 

  提示:可以看到redis服務已經監聽在6379這個埠了;說明重啟redis服務命令執行成功;

  示例:創建檔案,條件是只有對應父目錄存在,則新建檔案;

[root@node12 ~]# cat exec3.pp
exec{"create file":
        command => 'touch /tmp/jerry.sh',
        path    => '/bin:/sbin:/usr/bin:/usr/sbin',
        onlyif  => 'test -d /tmp'
}
[root@node12 ~]# 

  執行清單并驗證

[root@node12 ~]# ll /tmp/
total 8
srwx------ 1 mongod mongod  0 Dec  2 18:59 mongodb-27017.sock
lrwxrwxrwx 1 root   root   11 Dec  2 13:58 passwd -> /etc/passwd
drwx------ 3 root   root   17 Dec  2 18:59 systemd-private-62bd808f926f45528710005f2104130c-chronyd.service-wtp0Tm
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 3 root   root   93 Dec  2 13:45 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
drwxr-xr-x 2 root   root    6 Dec  2 19:17 tom
[root@node12 ~]# puppet apply -v --noop exec3.pp   
Notice: Compiled catalog for node12.test.org in environment production in 0.02 seconds
Info: Applying configuration version '1606910431'
Notice: /Stage[main]/Main/Exec[create file]/returns: current_value notrun, should be 0 (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.02 seconds
[root@node12 ~]# puppet apply -v exec3.pp        
Notice: Compiled catalog for node12.test.org in environment production in 0.02 seconds
Info: Applying configuration version '1606910443'
Notice: /Stage[main]/Main/Exec[create file]/returns: executed successfully
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# ll /tmp
total 8
-rw-r--r-- 1 root   root    0 Dec  2 20:00 jerry.sh
srwx------ 1 mongod mongod  0 Dec  2 18:59 mongodb-27017.sock
lrwxrwxrwx 1 root   root   11 Dec  2 13:58 passwd -> /etc/passwd
drwx------ 3 root   root   17 Dec  2 18:59 systemd-private-62bd808f926f45528710005f2104130c-chronyd.service-wtp0Tm
drwxr-xr-x 2 jerry  jerry   6 Dec  2 13:34 test
-r-------- 1 jerry  jerry  23 Dec  2 13:27 test1
drwxr-xr-x 3 root   root   93 Dec  2 13:45 test.repos.d
-rw-r--r-- 1 jerry  root   17 Dec  2 13:19 test.txt
drwxr-xr-x 2 root   root    6 Dec  2 19:17 tom
[root@node12 ~]# 

  提示:可以看到jerry.sh檔案創建成功了;

  3、cron:該型別資源主要用于在被管控端管理周期計劃任務

  主要屬性

    command:要執行的任務;

    ensure:描述是目標狀態,取值present/absent;

    hour:定義小時時間;

    minute:定義分鐘時間;

    monthday:定義月份的某一天時間;

    month:定義月份

    weekday:定義周時間;

    user:以哪個用戶的身份運行命令;

    target:添加為哪個用戶的任務;

    name:cron job的名稱;

  示例:創建時間同步周期計劃任務

[root@node12 ~]# cat cron.pp
cron{"timesync":
        command => '/usr/sbin/ntpdate 192.168.0.99 &> /dev/null',
        ensure  => present,
        minute  => '*/5',
        user    => 'root'
}
[root@node12 ~]# 

  執行清單,看看是否生成周期計劃任務?

[root@node12 ~]# crontab -l
no crontab for root
[root@node12 ~]# puppet apply -v --noop cron.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.02 seconds
Info: Applying configuration version '1606913457'
Notice: /Stage[main]/Main/Cron[timesync]/ensure: current_value absent, should be present (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.02 seconds
[root@node12 ~]# puppet apply -v  cron.pp        
Notice: Compiled catalog for node12.test.org in environment production in 0.02 seconds
Info: Applying configuration version '1606913462'
Notice: /Stage[main]/Main/Cron[timesync]/ensure: created
Notice: Finished catalog run in 0.02 seconds
[root@node12 ~]# crontab -l
# HEADER: This file was autogenerated at 2020-12-02 20:51:02 +0800 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: timesync
*/5 * * * * /usr/sbin/ntpdate 192.168.0.99 &> /dev/null
[root@node12 ~]# 

  提示:可以看到周期計劃任務已經創建;

  4、notify:該型別資源主要用來向agent運行日志發送訊息,如果是單機模型,則輸出到螢屏,如果是master/agent模型則記錄到日志中;

  主要屬性

    message:資訊內容;

    name:資訊名稱;

  示例

[root@node12 ~]# cat notify.pp
notify{"say hello ":
        message => "hello everyone .."
}
[root@node12 ~]# puppet apply -v notify.pp 
Notice: Compiled catalog for node12.test.org in environment production in 0.01 seconds
Info: Applying configuration version '1606914189'
Notice: hello everyone ..
Notice: /Stage[main]/Main/Notify[say hello ]/message: defined 'message' as 'hello everyone ..'
Notice: Finished catalog run in 0.03 seconds
[root@node12 ~]# 

  ok,以上是puppet中4中核心資源的使用和相關演示,以及資源與資源間的通知/訂閱關系的定義;

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/228683.html

標籤:Linux

上一篇:win10 Microsoft visual C++2012 Redistrbutable(x86安裝錯誤

下一篇:Kubernetes K8S之固定節點nodeName和nodeSelector調度詳解

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more