iT邦幫忙

2023 iThome 鐵人賽

DAY 24
0
IT管理

OCS Inventory:開源資產管理解決方案系列 第 24

如何在 Ubuntu 22.04 安裝 OCS Inventory 代理程式

  • 分享至 

  • xImage
  •  

如果您想要在 OCS Inventory 使用 SNMP Scan 功能,負責執行的計算機代理程式則必須為 Linux 版本。
所以今天先來教大家如何在 Ubuntu 22.04 安裝 OCS Inventory 代理程式。

先決條件
需要安裝 PERL 5.8 or higher 的相關模組
透過下列指令依序進行安裝,這邊需要一點時間喔。

sudo apt-get install build-essential
sudo cpan install XML::Simple
sudo cpan install Compress::Zlib
sudo cpan install Net::IP 
sudo cpan install LWP::UserAgent
sudo cpan install Digest::MD5
sudo cpan install YAML
sudo cpan install Net::SSLeay
sudo cpan install Data::UUID
sudo cpan install Mac::SysProfile

# Recommended modules:
sudo cpan install IO::Socket::SSL
sudo cpan install Crypt::SSLeay
sudo cpan install LWP::Protocol::https
sudo cpan install Proc::Daemon
sudo cpan install Proc::PID::File
sudo cpan install Net::SNMP
sudo cpan install Net::Netmask
sudo cpan install Nmap::Parser
sudo cpan install Module::Install
sudo cpan install Net::CUPS
sudo cpan install Parse::EDID

安裝必要與推薦的模組

sudo apt install libmodule-install-perl dmidecode libxml-simple-perl libcompress-zlib-perl libnet-ip-perl libwww-perl libdigest-md5-perl libdata-uuid-perl

# Optional modules: but highly recommended
sudo apt install libcrypt-ssleay-perl libnet-snmp-perl libproc-pid-file-perl libproc-daemon-perl net-tools libsys-syslog-perl pciutils smartmontools read-edid nmap libnet-netmask-perl

使用 APT 安裝代理程式(不推薦)
在基於 Debian 的發行版上,您可以使用 APT 安裝代理程式

curl -sS http://deb.ocsinventory-ng.org/pubkey.gpg | sudo apt-key add -

Ubuntu 22.04 現已棄用 apt-key,並將發出警告。

建議使用以下 gpg 替代方案

curl -fsSL http://deb.ocsinventory-ng.org/pubkey.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/ocs-archive-keyring.gpg

使用以下命令添加 OCS Inventory 的存儲庫

echo "deb http://deb.ocsinventory-ng.org/ubuntu/ focal main" | sudo tee /etc/apt/sources.list.d/ocsinventory.list
sudo apt update

安裝代理程式,並回答下列問題。

sudo apt install ocsinventory-agent

設定組態檔案的位置

Do you want to configure the agent
Please enter 'y' or 'n'?> [y] 
Where do you want to write the configuration file?
 0 -> /etc/ocsinventory
 1 -> /usr/local/etc/ocsinventory
 2 -> /etc/ocsinventory-agent
?>  0
Do you want to create the directory /etc/ocsinventory?
Please enter 'y' or 'n'?> [y] 
Should the old unix_agent settings be imported ?
Please enter 'y' or 'n'?> [y] 
[info] The config file will be written in /etc/ocsinventory/ocsinventory-agent.cfg,

輸入您的 OCS Inventory 伺服器的 FQDN

What is the address of your ocs server?> your_ocs_inventory_fqdn
Do you need credential for the server? (You probably don't)
Please enter 'y' or 'n'?> [n] 
Do you want to apply an administrative tag on this machine
Please enter 'y' or 'n'?> [y] n

是否要設定排程運行代理程式

Do yo want to install the cron task in /etc/cron.d
Please enter 'y' or 'n'?> [y]

預設為下午 1 點 53 分執行

cat /etc/cron.d/ocsinventory-agent
PATH=/usr/sbin:/usr/bin:/sbin:/bin
53 13 * * * root /usr/bin/ocsinventory-agent --lazy > /dev/null 2>&1

設定代理程式的檔案儲存位置

Where do you want the agent to store its files? (You probably don't need to change it)?> [/var/lib/ocsinventory-agent] 
Do you want to create the /var/lib/ocsinventory-agent directory?
Please enter 'y' or 'n'?> [y] 
Should I remove the old unix_agent
Please enter 'y' or 'n'?> [n] 

開啟除錯模式,設定日誌檔案路徑。

Do you want to activate debug configuration option ?
Please enter 'y' or 'n'?> [y] 
Do you want to use OCS Inventory NG UNix Unified agent log file ?
Please enter 'y' or 'n'?> [y] 
Specify log file path you want to use?>  /var/log/ocsinventory-agent.log

啟用 SSL 驗證,設定 CA 憑證路徑。

Do you want disable SSL CA verification configuration option (not recommended) ?
Please enter 'y' or 'n'?> [n] 
Do you want to set CA certificates file path ?
Please enter 'y' or 'n'?> [y] 
Specify CA certificates file path?>  /home/administrator/cacert.pem

是否使用遠端部屬與 SNMP 掃描功能

Do you want to use OCS-Inventory software deployment feature?
Please enter 'y' or 'n'?> [y] 
Do you want to use OCS-Inventory SNMP scans feature?
Please enter 'y' or 'n'?> [y] 

立即發送盤點數據

Do you want to send an inventory of this machine?
Please enter 'y' or 'n'?> [y] 
Setting OCS Inventory NG server address...
Looking for OCS Invetory NG Unix Unified agent installation...
ocsinventory agent presents: /usr/bin/ocsinventory-agent
Setting crontab...
Creating /var/lib/ocsinventory-agent directory...
Creating /etc/ocsinventory directory...
Writing OCS Inventory NG Unix Unified agent configuration
Creating /var/lib/ocsinventory-agent/http:__your_ocs_inventory_fqdn_ocsinventory directory...
Activating modules if needed...
Launching OCS Inventory NG Unix Unified agent...
   -> Success!

看到 Success 出現,代表代理程式安裝完成並開始運行了。

安裝過程中若有輸入錯誤,再自行調整代理程式組態設定。

sudo vi /etc/ocsinventory/ocsinventory-agent.cfg
basevardir=/var/lib/ocsinventory-agent
debug=1
ca=/home/administrator/cacert.pem
logfile=/var/log/ocsinventory-agent.log
server=http://your_ocs_inventory_fqdn/ocsinventory

點選電腦名稱進入,可以看到更詳細的資訊。

Hardware 會幫您列出所有硬體資訊

Software 會幫您列出所有軟體的發行者、名稱與版本

使用 Source 安裝代理程式(推薦)
若想要手動安裝也是可以的,請依照自己的版本下載 Linux 的代理程式。

下載完畢後進行解壓縮

wget https://github.com/OCSInventory-NG/UnixAgent/releases/download/v2.9.1/Ocsinventory-Unix-Agent-2.9.1.tar.gz
sudo tar -xvzf Ocsinventory-Unix-Agent-2.9.1.tar.gz

使用腳本 Makefile.PL 檢查 perl 配置並生成 Makefile

cd Ocsinventory-Unix-Agent-2.9.1
sudo perl Makefile.PL

編譯它們

sudo make
sudo make install

安裝代理程式,並回答下列問題。

Manifying 1 pod document
Manifying 6 pod documents
Appending installation info to /usr/local/lib/x86_64-linux-gnu/perl/5.30.0/perllocal.pod
[ ! -f run-postinst ] || /usr/bin/perl postinst.pl
Do you want to configure the agent?
Please enter 'y' or 'n'?> [y] 
Where do you want to write the configuration file?
 0 -> /etc/ocsinventory
 1 -> /usr/local/etc/ocsinventory
 2 -> /etc/ocsinventory-agent
?>  0
Do you want to create the directory /etc/ocsinventory?
Please enter 'y' or 'n'?> [y] 
Should the old unix_agent settings be imported?
Please enter 'y' or 'n'?> [y] 
[info] The config file will be written in /etc/ocsinventory/ocsinventory-agent.cfg,
What is the address of your ocs server?>  your_ocs_inventory_fqdn
Do you need credential for the server? (You probably don't)
Please enter 'y' or 'n'?> [n] 
Do you want to apply an administrative tag on this machine?
Please enter 'y' or 'n'?> [y] n
Do yo want to install the cron task in /etc/cron.d?
Please enter 'y' or 'n'?> [y] 
Where do you want the agent to store its files? (You probably don't need to change it)?> [/var/lib/ocsinventory-agent] 
Do you want to create the /var/lib/ocsinventory-agent directory?

Please enter 'y' or 'n'?> [y] 
Should I remove the old unix_agent?
Please enter 'y' or 'n'?> [n] 
Do you want to activate debug configuration option?
Please enter 'y' or 'n'?> [y] 
Do you want to use OCS Inventory NG UNix Unified agent log file?
Please enter 'y' or 'n'?> [y] 
Specify log file path you want to use?>  /var/log/ocsinventory-agent.log
Do you want disable SSL CA verification configuration option (not recommended)?
Please enter 'y' or 'n'?> [n] 
Do you want to set CA certificates file path?
Please enter 'y' or 'n'?> [y] 
Specify CA certificates file path?>  /home/administrator/cacert.pem
Do you want disable software inventory?
Please enter 'y' or 'n'?> [n] 
Do you want to use OCS-Inventory software deployment feature?
Please enter 'y' or 'n'?> [y] 
Do you want to use OCS-Inventory SNMP scans feature?
Please enter 'y' or 'n'?> [y] 
Do you want to send an inventory of this machine?
Please enter 'y' or 'n'?> [y] 
Setting OCS Inventory NG server address...
Looking for OCS Invetory NG Unix Unified agent installation...
ocsinventory agent presents: /usr/local/bin/ocsinventory-agent
Setting crontab...
Creating /var/lib/ocsinventory-agent directory...
Creating /etc/ocsinventory directory...
Writing OCS Inventory NG Unix Unified agent configuration
Creating /var/lib/ocsinventory-agent/http:__your_ocs_inventory_fqdn_ocsinventory directory...
Creating /var/lib/ocsinventory-agent/http:__your_ocs_inventory_fqdn_ocsinventory/snmp directory...
Copying SNMP MIBs XML files...
Activating modules if needed...
Launching OCS Inventory NG Unix Unified agent...
   -> Success!
New settings written! Thank you for using OCS Inventory

代理程式組態設定如下

sudo cat /etc/ocsinventory/ocsinventory-agent.cfg
debug=1
server=https://your_ocs_inventory_fqdn/ocsinventory
snmptimeout=3
basevardir=/var/lib/ocsinventory-agent
nosoftware=0
logfile=/var/log/ocsinventory-agent.log
snmpretry=2
ca=/home/administrator/cacert.pem
snmp=1

今天的分享就到這邊,下一篇我們來教大家如何在 MacOS 安裝 OCS Inventory 代理程式,敬請期待。

參考文件

  1. https://wiki.ocsinventory-ng.org/03.Basic-documentation/Setting-up-the-UNIX-agent-using-repository-on-client-computers
  2. https://wiki.ocsinventory-ng.org/03.Basic-documentation/Setting-up-the-UNIX-agent-manually-on-client-computers

上一篇
如何在 OCS Inventory 使用自定義套件
下一篇
如何在 MacOS 安裝 OCS Inventory 代理程式
系列文
OCS Inventory:開源資產管理解決方案30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言