自動化運維工具-Ansible基礎

来源:https://www.cnblogs.com/1naonao/archive/2019/09/17/11531903.html
-Advertisement-
Play Games

[toc] 自動化運維工具 Ansible基礎 什麼是Ansible Ansible是一個自動化 統一配置管理工具 同類型軟體對比 1.puppet 學習難,安裝ruby環境難,沒有遠程執行功能 2.ansible 輕量級,大規模環境下只通過ssh會很慢,串列的 3.saltstack 一般選擇sa ...


目錄

自動化運維工具-Ansible基礎

什麼是Ansible

Ansible是一個自動化統一配置管理工具

同類型軟體對比

1.puppet 學習難,安裝ruby環境難,沒有遠程執行功能
2.ansible 輕量級,大規模環境下只通過ssh會很慢,串列的
3.saltstack 一般選擇salt會使用C/S結構的模式,salt-mastersalt-minion,並行的,大規模批量操作的情況下,會比Ansible速度快一些,底層使用的是zero-MQ消協隊列

Ansible使用的是python2

saltstack即有python2也有python3

Ansible的功能及優點

1.遠程執行
批量執行遠程命令,可以對多台主機進行遠程操作

2.配置管理
批量配置軟體服務,可以進行自動化方式配置,服務的統一配置管理,和啟停

3.事件驅動
通過Ansible的模塊,對服務進行不同的事件驅動
比如:
1)修改配置後重啟
2)只修改配置文件,不重啟
3)修改配置文件後,重新載入
4)遠程啟停服務管理

4.管理公有雲
通過API介面的方式管理公有雲,不過這方面做的不如saltstack.
saltstack本身可以通過saltcloud管理各大雲廠商的雲平臺。

5.二次開發
因為語法是Python,所以便於運維進行二次開發。

6.任務編排
可以通過playbook的方式來統一管理服務,並且可以使用一條命令,實現一套架構的部署

7.跨平臺,跨系統
幾乎不受到平臺和系統的限制,比如安裝apache和啟動服務

在Ubuntu上安裝apache服務名字叫apache2
在CentOS上安裝apache服務名字叫httpd

在CentOS6上啟動伺服器使用命令:/etc/init.d/nginx start
在CentOS7上啟動伺服器使用命令:systemctl start nginx

Ansible的架構

Ansible的執行流程

1.Ansible讀取playbook劇本,劇本中會記錄對哪些主機執行哪些任務。
2.首先Ansible通過主機清單找到要執行的主機,然後調用具體的模塊。
3.其次Ansible會通過連接插件連接對應的主機並推送對應的任務列表。
4.最後被管理的主機會將Ansible發送過來的任務解析為本地Shell命令執行。

安裝Ansible

1.環境準備

主機名 wanIP lanIP 角色
m01 10.0.0.61 172.16.1.61 Ansible控制端
web01 10.0.0.7 172.16.1.7 Ansible被控端
web02 10.0.0.8 172.16.1.8 Ansible被控端

2.安裝ansible

[root@m01 ~]# yum install -y ansible

3.查看ansible模塊及版本

[root@m01 ~]# ansible --version
ansible 2.8.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

4.ansible參數

# ansible <host-pattern> [options]
--version   #ansible版本信息
-v          #顯示詳細信息
-i          #主機清單文件路徑,預設是在/etc/ansible/hosts
-m          #使用的模塊名稱,預設使用command模塊
-a          #使用的模塊參數,模塊的具體動作
-k          #提示輸入ssh密碼,而不使用基於ssh的密鑰認證
-C          #模擬執行測試,但不會真的執行
-T          #執行命令的超時

5.ansible配置文件讀取順序

[root@m01 ~]# vim /etc/ansible/ansible.cfg
# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first

1、$ANSIBLE_CONFIG
2、./ansible.cfg
3、~/.ansible.cfg
4、/etc/ansible/ansible.cfg

ansible配置文件

[root@m01 ~]# vim /etc/ansible/ansible.cfg
#inventory      = /etc/ansible/hosts      #主機列表配置文件
#library        = /usr/share/my_modules/  #庫文件存放目錄
#remote_tmp     = ~/.ansible/tmp          #臨時py文件存放在遠程主機目錄
#local_tmp      = ~/.ansible/tmp          #本機的臨時執行目錄
#forks          = 5                       #預設併發數
#sudo_user      = root                    #預設sudo用戶
#ask_sudo_pass = True                     #每次執行是否詢問sudo的ssh密碼
#ask_pass      = True                     #每次執行是否詢問ssh密碼
#remote_port    = 22                      #遠程主機埠
host_key_checking = False                 #跳過檢查主機指紋
log_path = /var/log/ansible.log           #ansible日誌

#普通用戶提權操作
[privilege_escalation]
#become=True
#become_method=sudo
#become_user=root
#become_ask_pass=False 

ansible Inventory(主機清單文件)

場景一:密碼方式連接

[root@m01 ~]# cat /etc/ansible/hosts

#方式一、IP+埠+用戶+密碼
[webs]
10.0.0.7 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'
10.0.0.8 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'

#方式二、主機名+密碼
[webs]
web0[1:2] ansible_ssh_pass='123456'

#方式三、主機+密碼
[webs]web0[1:2]
[webs:vars]
ansible_ssh_pass='123456'

註意:方式二和方式三,都需要做hosts解析

場景二:密鑰方式連接

#創建密鑰對
[root@m01 ~]# ssh-keygen
#推送公鑰
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

#方式一:
[web_group]
172.16.1.7
172.16.1.8

#方式二:
[webs]
web01 ansible_ssh_host=172.16.1.7 
web02 ansible_ssh_host=172.16.1.8

場景三:主機組定義方式

[web_group]
web01 ansible_ssh_host=172.16.1.7
web02 ansible_ssh_host=172.16.1.8

[db_group]
db01 ansible_ssh_host=172.16.1.51
lb01 ansible_ssh_host=172.16.1.5
[db_group:vars]
ansible_ssh_pass='1'

[nfs_group]
nfs ansible_ssh_host=172.16.1.31

[nfs_server:children]
web_group
nfs_group

[lnmp:children]
web_group
db_group


[root@m01 ~]# ansible 'all' --list-host
  hosts (5):
    nfs
    web01
    web02
    db01
    lb01
[root@m01 ~]# ansible 'web_group' --list-host
  hosts (2):
    web01
    web02
[root@m01 ~]# ansible 'db_group' --list-host
  hosts (2):
    db01
    lb01
[root@m01 ~]# ansible 'lnmp' --list-host
  hosts (4):
    web01
    web02
    db01
    lb01

ad-hoc模式命令使用

ad-hoc

臨時命令。執行完即結束,並不會保存

結果返回顏色

綠色: 代表被管理端主機沒有被修改
黃色: 代表被管理端主機發現變更
紅色: 代表出現了故障,註意查看提示

ansible常用模塊

ansible命令模塊

1.command

[root@m01 ~]# ansible 'web_group' -m command -a 'free -m'
web02 | CHANGED | rc=0 >>
              total        used        free      shared  buff/cache   available
Mem:            972         140         489           7         342         658
Swap:          1023           0        1023

web01 | CHANGED | rc=0 >>
              total        used        free      shared  buff/cache   available
Mem:            972         113         412          13         446         669
Swap:          1023           0        1023

2.shell

[root@m01 ~]# ansible 'web_group' -m shell -a 'ps -ef|grep nginx'
web02 | CHANGED | rc=0 >>
root      12584  12583  0 20:16 pts/1    00:00:00 /bin/sh -c ps -ef|grep nginx
root      12586  12584  0 20:16 pts/1    00:00:00 grep nginx

web01 | CHANGED | rc=0 >>
root      14575  14570  0 12:16 pts/1    00:00:00 /bin/sh -c ps -ef|grep nginx
root      14577  14575  0 12:16 pts/1    00:00:00 grep nginx

1)command不支持特殊符號

2)shell模塊支持特殊符號

3)不指定-m 預設使用的是command模塊

3.script

#編寫腳本
[root@m01 ~]# vim vsftpd.sh 
#!/usr/bin/bash
mkdir /tmp/zls

[root@m01 ~]# ansible 'web01' -m script -a '/root/vsftpd.sh'

[root@m01 ~]# ansible 'web01' -m shell -a 'ls -l /tmp'

ansible軟體管理模塊

4.yum

[root@m01 ~]# ansible 'web_group' -m yum -a 'name=vsftpd state=present'
#相當於:yum install -y vsftpd

[root@m01 ~]# ansible 'web_group' -m yum -a 'name=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm state=present' 
#相當於:yum install -y https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm

[root@m01 ~]# ansible 'web_group' -m yum -a 'name=file:///root/nagios-4.4.3-1.el7.x86_64.rpm state=present'
#相當於:yum localinstall -y nagios-4.4.3-1.el7.x86_64.rpm

[root@m01 ~]# ansible 'web_group' -m yum -a 'name=vsftpd state=absent'
#相當於:yum remove -y vsftpd

name                            
    httpd                       #指定要安裝的軟體包名稱
    file://                     #指定本地安裝路徑(yum localinstall 本地rpm包)
    http://                     #指定yum源(從遠程倉庫獲取rpm包)
    
state                           #指定使用yum的方法
    installed,present           #安裝軟體包
    removed,absent              #移除軟體包
    latest                      #安裝最新軟體包

5.yum_repository

- name: Add repository
  yum_repository:
    name: epel
    description: EPEL YUM repo
    baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/


#添加yum倉庫
ansible 'web_group' -m yum_repository -a 'name=zls_epel,zls_base  description=EPEL baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck=no enabled=yes file=zls_epel'

#添加mirrorlist
ansible 'web_group' -m yum_repository -a 'name=zls_epel  description=EPEL baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck=no enabled=yes file=epel mirrorlist=http://mirrorlist.repoforge.org/el7/mirrors-rpmforge'

#刪除yum倉庫
ansible 'web_group' -m yum_repository -a 'name=zls_epel,zls_base file=zls_epel state=absent'

#修改yum倉庫
ansible 'web_group' -m yum_repository -a 'name=epel  description=EPEL baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck=no enabled=no file=epel'

name                #指定倉庫名字
description         #添加描述(repo文件中的name)
baseurl             #指定yum倉庫的地址
gpgcheck            #是否開啟校驗
    yes
    no
enabled             #是否啟用yum倉庫
    yes
    no
file                #指定倉庫文件名
state
    absent          #刪除yum倉庫
    present         #創建yum倉庫
    
    
ansible 'web_group' -m yum_repository -a 'name=zls_yum  description=EPEL baseurl=http://www.driverzeng.com gpgcheck=no enabled=no file=zls'

ansible文件管理模塊

1.copy

- name: Copy file with owner and permissions
  copy:
    src: /srv/myfiles/foo.conf
    dest: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'


#推送文件
[root@m01 ~]# ansible 'web_group' -m copy -a 'src=/root/index.html dest=/var/www/html owner=root group=root mode=0644'

#推送文件並備份
[root@m01 ~]# ansible 'web_group' -m copy -a 'src=/root/index.html dest=/var/www/html owner=root group=root mode=0644 backup=yes'

#編輯nfs配置文件
[root@m01 ~]# ansible 'web_group' -m copy -a 'content="/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" dest=/etc/exports'

src                 #指定推送的源文件
dest                #指定推送的目標位置
owner               #指定屬主
group               #指定屬組
mode                #指定許可權(數字方式)
content             #在指定文件中添加內容
backup              #是否備份(註意:控制端和被控端,內容不一致才會備份)
    yes
    no

2.file

- name: Create an insecure file
  file:
    path: /work
    owner: root
    group: root
    mode: 0755

#創建目錄 mkdir
[root@m01 ~]# ansible 'web_group' -m file -a 'path=/backup state=directory owner=adm group=adm mode=0700'

#遞歸創建目錄並授權chown -R  chmod -R
[root@m01 ~]# ansible 'web_group' -m file -a 'path=/zls/mysql/db01 state=directory owner=adm group=adm mode=0700 recurse=yes'

#創建文件(前提條件,上級目錄必須存在)  touch
[root@m01 ~]# ansible 'web_group' -m file -a 'path=/root/zls.txt state=touch'

#刪除目錄  rm -fr
[root@m01 ~]# ansible 'web_group' -m file -a 'path=/backup state=absent'

#做軟鏈接 ln -s
[root@m01 ~]# ansible 'web_group' -m file -a 'src=/root/zls.txt dest=/root/zls.txt.ori state=link'

src                 #指定軟鏈接的源文件
dest                #指定軟連接的目標文件
path                #指定創建目錄或文件
state
    touch           #創建文件
    directory       #創建目錄
    absent          #刪除目錄或文件
    link            #做軟鏈接
owner               #指定屬主
group               #指定屬組
mode                #指定許可權
recurse             #遞歸授權
    yes
    no

3.get_url

- name: Download foo.conf
  get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    mode: '0440'

#下載worldpress代碼
[root@m01 ~]# ansible 'web_group' -m get_url -a 'url=http://test.driverzeng.com/Nginx_Code/wordpress-5.0.3-zh_CN.tar.gz dest=/root mode=0777'

#下載並校驗MD5
[root@m01 ~]# ansible 'web_group' -m get_url -a 'url=http://test.driverzeng.com/Nginx_Code/test.txt dest=/root mode=0777 checksum=md5:ba1f2511fc30423bdbb183fe33f3dd0f'

url             #指定下載文件的url
dest            #指定下載的位置
mode            #指定下載後的許可權
checksum        #校驗
    md5         #md5校驗
    sha256      #sha256校驗

ansible服務管理模塊

1.service,systemd

[root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=stopped enabled=yes'
[root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=started enabled=yes'
[root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=restarted enabled=yes'
[root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=reloaded enabled=yes'

name                    #指定服務名稱
state
    started             #啟動
    stopped             #停止
    restarted           #重啟
    reloaded            #重載
enabled                 #是否開機自啟
    yes
    no

ansible用戶管理模塊

1.group

- name: Ensure group "somegroup" exists
  group:
    name: somegroup
    state: present

#創建組
[root@m01 ~]# ansible 'web_group' -m group -a 'name=www gid=666 state=present'

#刪除組
[root@m01 ~]# ansible 'web_group' -m group -a 'name=www gid=666 state=absent'

name            #指定組名
gid             #指定gid
state
    present     #創建
    absent      #刪除

2.user

- name: Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
  user:
    name: jsmith
    generate_ssh_key: yes
    ssh_key_bits: 2048
    ssh_key_file: .ssh/id_rsa

#創建用戶
[root@m01 ~]# ansible 'web_group' -m user -a 'name=www uid=666 group=www state=present shell=/sbin/nologin create_home=false'

#刪除用戶
[root@m01 ~]# ansible 'web_group' -m user -a 'name=www uid=666  state=absent'

#創建用戶的同時創建密鑰對
[root@m01 ~]# ansible 'web_group' -m user -a 'name=zls generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa'


name                    #指定用戶名
uid                     #指定uid
group                   #指定屬組
groups                  #指定附加組
state
    present             #創建用戶
    absent              #刪除用戶
shell                   #指定用戶登錄的shell
    /bin/bash
    /sbin/nologin
create_home             #是否創建家目錄
    true
    false
comment                 #添加註釋
generate_ssh_key        #創建密鑰對
ssh_key_bits            #指定密鑰對長度
ssh_key_file            #指定密鑰文件

#將明文密碼進行hash加密,然後進行用戶創建
[root@m01 ~]# ansible web_group -m debug -a "msg={{ 'zls' | password_hash('sha512', 'salt') }}" -i ./hosts
web01 | SUCCESS => {
    "msg": "$6$salt$gaWhNcZweYlKQcLU1CqyY/UbYqIeUffVz6ESj87aMNfMX.xYBx0Z.67wzLN/hkkxmNut7SvkksPZ2Zlrse98m/"
}
web02 | SUCCESS => {
    "msg": "$6$salt$gaWhNcZweYlKQcLU1CqyY/UbYqIeUffVz6ESj87aMNfMX.xYBx0Z.67wzLN/hkkxmNut7SvkksPZ2Zlrse98m/"
}

#創建用戶
[root@m01 ~]# ansible web_group -m user -a 'name=zls1 password=$6$salt$gaWhNcZweYlKQcLU1CqyY/UbYqIeUffVz6ESj87aMNfMX.xYBx0Z.67wzLN/hkkxmNut7SvkksPZ2Zlrse98m/ create_home=true shell=/bin/bash' -i ./hosts

uid             #指定用戶的uid
group           #指定用戶組名稱
groups          #指定附加組名稱
password        #給用戶添加密碼(單引號)
shell           #指定用戶登錄shell
create_home     #是否創建家目錄

ansible的定時任務

cron

# 正常使用crond服務
[root@m01 ~]# crontab -l
* * * * *  /bin/sh /server/scripts/yum.sh

# 使用ansible添加一條定時任務
[root@m01 ~]# ansible web_group -m cron -a "minute=* hour=* day=* month=* weekday=*  job='/bin/sh /server/scripts/test.sh'"
[root@m01 ~]# ansible web_group -m cron -a "job='/bin/sh /server/scripts/test.sh'"

# 設置定時任務註釋信息,防止重覆,name設定
[root@m01 ~]# ansible web_group -m cron -a "name='cron01' job='/bin/sh /server/scripts/test.sh'"

# 刪除相應定時任務
[root@m01 ~]# ansible web_group -m cron -a "name='ansible cron02' minute=0 hour=0 job='/bin/sh /server/scripts/test.sh' state=absent"
 
# 註釋相應定時任務,使定時任務失效
[root@m01 scripts]# ansible web_group -m cron -a "name='ansible cron01' minute=0 hour=0 job='/bin/sh /server/scripts/test.sh' disabled=no"

mount

[root@m01 ~]# ansible web_group -m mount -a "src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=present"

[root@m01 ~]# ansible web01 -m mount -a "src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=mounted"

[root@m01 ~]# ansible web02 -m mount -a "src=172. 16.1.31:/data path=/data fstype=nfs opts=defaults state=unmounted"

[root@m01 ~]# ansible web -m mount -a "src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=absent"

present     # 開機掛載,僅將掛載配置寫入/etc/fstab
mounted     # 掛載設備,並將配置寫入/etc/fstab
unmounted   # 卸載設備,不會清除/etc/fstab寫入的配置
absent      # 卸載設備,會清理/etc/fstab寫入的配置

ansible防火牆模式

selinux

#修改配置文件關閉selinux,必須重啟
[root@m01 ~]# ansible web_group -m selinux -a 'state=disabled' -i ./hosts
 [WARNING]: SELinux state temporarily changed from 'enforcing' to 'permissive'. State change will take effect next reboot.

web01 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "configfile": "/etc/selinux/config",
    "msg": "Config SELinux state changed from 'enforcing' to 'disabled'",
    "policy": "targeted",
    "reboot_required": true,
    "state": "disabled"
}
web02 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "configfile": "/etc/selinux/config",
    "msg": "Config SELinux state changed from 'enforcing' to 'disabled'",
    "policy": "targeted",
    "reboot_required": true,
    "state": "disabled"
}

#臨時關閉
[root@m01 ~]# ansible web_group -m shell -a 'setenforce 0' -i ./hosts
web02 | CHANGED | rc=0 >>
web01 | CHANGED | rc=0 >>


[root@m01 ~]# ansible web_group -m shell -a 'getenforce' -i ./hosts
web02 | CHANGED | rc=0 >>
Permissive

web01 | CHANGED | rc=0 >>
Permissive

firewalld

[root@m01 ~]# ansible web_group -m firewalld -a 'service=http permanent=yes state=enabled' -i ./hosts
[root@m01 ~]# ansible web_group -m firewalld -a "service=http immediate=yes permanent=yes state=enabled" -i ./hosts

[root@m01 ~]# ansible web_group -m firewalld -a "port=8080-8090/tcp immediate=yes permanent=yes state=enabled" -i ./hosts

service                 #指定開放或關閉的服務名稱
port                    #指定開放或關閉的埠
permanent               #是否添加永久生效
state                   #開啟或者關閉
    enabled
    disabled

zone                    #指定配置某個區域
rich_rule               #配置輔規則
masquerade              #開啟地址偽裝
immediate               #臨時生效
source                  #指定來源IP

ansible主機信息模塊

ansible web01 -m setup

ansible web01 -m setup -a 'filter= ' #查詢單獨產參數模式
ansible_all_ipv4_addresses:僅顯示ipv4的信息。
ansible_devices:僅顯示磁碟設備信息。
ansible_distribution:顯示是什麼系統,例:centos,suse等。
ansible_distribution_major_version:顯示是系統主版本。
ansible_distribution_version:僅顯示系統版本。
ansible_machine:顯示系統類型,例:32位,還是64位。
ansible_eth0:僅顯示eth0的信息。
ansible_hostname:僅顯示主機名。
ansible_kernel:僅顯示內核版本。
ansible_lvm:顯示lvm相關信息。
ansible_memtotal_mb:顯示系統總記憶體。
ansible_memfree_mb:顯示可用系統記憶體。
ansible_memory_mb:詳細顯示記憶體情況。
ansible_swaptotal_mb:顯示總的swap記憶體。
ansible_swapfree_mb:顯示swap記憶體的可用記憶體。
ansible_mounts:顯示系統磁碟掛載情況。
ansible_processor:顯示cpu個數(具體顯示每個cpu的型號)。
ansible_processor_vcpus:顯示cpu個數(只顯示總的個數)。

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.啟動動作 2.設定發件人郵箱 3.配置收件人 ...
  • 一、中間鍵產品介紹 目前來說IBM的WebSphere,Oracle的Weblogic占據了市場上java語言Web站點的部分份額,該兩種軟體都是商業化的軟體,由於性能優越,可靠性高等優點應用於大型互聯網公司的Web場景中。 Tomcat自5.x版本以來,其性能上已經得到了大幅度的提升,開放性的架構 ...
  • Nginx簡介: Nginx(發音engine x)專為性能優化而開發的開源軟體,是HTTP、反向代理、郵件代理、TCP/UDP協議代理軟體,由俄羅斯的作者Igor Sysoev開發,其最知名的優點是它的穩定性和低系統資源消耗(硬體資源占用較低),以及對HTTP併發連接的高處理能力(單台物理伺服器可 ...
  • 1.在agent端自定義key[root@web01 ~]# cd /etc/zabbix/zabbix_agentd.d/[root@web01 zabbix_agentd.d]# cat io.confUserParameter=tps,iostat | awk '/^sda/{print $2 ...
  • 之前的用實驗室的伺服器,因為某些原因,使用的用戶沒有root許可權。linux的非root用戶很多軟體無法安裝,非常的不方便。我的方法是使用brew來代替系統的包管理工具。brew是最先用在mac上的包管理工具,可以將所有的包托管在user本地的環境內。下麵的文檔中運行的時候記得將用戶名改成自己的。 ...
  • 本文整理了在實踐過程中使用的Linux網路工具,這些工具提供的功能非常強大,我們平時使用的只是冰山一角,比如lsof、ip、tcpdump、iptables等。 本文不會深入研究這些命令的強大用法,因為每個命令都足以寫一篇文章,本文只是簡單地介紹並輔以幾個簡單demo實例,旨在大腦中留個印象,平時遇 ...
  • 一、基礎入門 《鳥哥的Linux私房菜基礎學習篇》 :最具知名度的Linux入門書《鳥哥的Linux私房菜基礎學習篇》,全面而詳細地介紹了Linux操作系統。 "https://book.douban.com/subject/4889838" 《鳥哥的Linux私房菜伺服器篇》 :從系統基礎以及網路 ...
  • 全選(高亮顯示):按esc後,然後ggvG或者ggVG 全部複製:按esc後,然後ggyG 全部刪除:按esc後,然後dG 解析: gg:是讓游標移到首行,在vim才有效,vi中無效 v : 是進入Visual(可視)模式 G :游標移到最後一行 選中內容以後就可以其他的操作了,比如: d 刪除選中 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...