- Install the Ansible batch management system. (No, SSH remote command loop is also possible)
- Create a new table in a common database, using the information you want to collect as a column name, and provide the ability to insert with the shell.
- Bulk Install the required toolkit, Smartmontools, Dmidecode, MySQL, you can use the ansible command: Ansible all_host-s-M yum-a "Name=mysql"
- Write the script locally.
- Get the default ip:default_ip=$ (Ifconfig|head-n 2|tail-n 1|cut-d ":"-F 2|cut-d ""-F 1)
- Get the name of the product, if it is a simplified version of the Linux system, you need to first install the Dmidecode Toolkit: product_name=$ (Dmidecode-t1|grep name|cut-d ""-F 3)
- Get the serial number of the product: serial_number=$ (Dmidecode-t1|grep serial|cut-d ""-F 3)
- Gets the number of CPUs: cpu_count=$ (dmidecode|grep cpu|grep version|wc-l)
- Get the name of the CPU: cpu_name=$ (dmidecode|grep cpu|grep version|cut-d ""-f 2-|uniq)
- Get memory capacity, with the free command is also very good, just no unit: mem_total=$ (cat/proc/meminfo|head-n 1|tr-s [: space:]|cut-d '-F 2-)
- Get Hard disk storage capacity: disk_size=$ (fdisk-l|grep "DISK/DEV/SDA" |grep-v gpt|cut-d ""-F 3-|cut-d ","-F 1)
- Get the hard drive model and install the Smartmontools Toolkit before using the SMARTCTL command: disk_name=$ (smartctl-a/dev/sda|grep "Product:" |awk ' {print $} ')
- Get Hard Drive Serial number: disk_serial_number=$ (smartctl-a/dev/sda|grep "Serial No.:" |awk ' {print $} ')
- Define SQL INSERT statement: sql= "INSERT into Hctt_machine_info (Default_ip,product_name,serial_number,cpu_count,cpu_name,mem_total, Disk_name,disk_serial_number,disk_size) \
VALUES (' $default _ip ', ' $product _name ', ' $serial _number ', ' $cpu _count ', ' $cpu _name ', ' $mem _total ', ' $disk _name ', ' $ Disk_serial_number ', ' $disk _size ') "
- command to write login database and insert operation: MYSQL-H * * * *-uroot-p****-D hctt_sysop-e "$sql"
- The local script is complete.
- Execute local script remotely using Ansible's script module: ansible-s-M script-a "****/dardware.sh"
- Connect the database with Navicat and export it to an Excel table.
- Some information about the exported discovery is empty.
- command to check this machine, it is indeed a null value.
- Investigation. An error was found.
- View the details of the interface: sudo smartctl-d scsi-a/dev/sda
- The array card needs to be installed special tools MegaRAID view.
- Download: Ftp://download2.boulder.ibm.com/ecc/sar/CMA/XSA/ibm_utl_sraidmr_megacli-8.00.48_linux_32-64.zip. (If the connection is not available, or if it is slow, you can find me)
- Installation.
#unzip Ibm_utl_sraidmr_megacli-8.00.48_linux_32-64.zip
#cd Linux
# RPM-IVH lib_utils-1.00-09.noarch.rpm megacli-8.00.48-1.i386.rpm #记得两个安装包的顺序, otherwise it will go wrong.
- How to use: */megacli64 -ldinfo -lall -aall
- If you do not know the Megarain command path, you can find the executable file.
sudo find/-name MegaCli64
- Here are some other online information queries that are collected.
#/opt/megaraid/megacli/megacli64-ldinfo-lall-Aall RAID Level #/opt/megaraid/megacli/megacli64-adpallinfo-Aall RAID Card information #/opt/megaraid/megacli/megacli64-pdlist-Aall viewing hard disk information #/opt/megaraid/megacli/megacli64-adpbbucmd-Aall View battery Information #/opt/megaraid/megacli/megacli64-fwtermlog-dsply-aall View RAID card logs #/opt/megaraid/megacli/megacli64-Adpcount "Display adapter number" #/opt/megaraid/megacli/megacli64-Adpgettime–aall "Show Adapter Time" #/opt/megaraid/megacli/megacli64-adpallinfo-Aall "Show All Adapter Information" #/opt/megaraid/megacli/megacli64-ldinfo-lall-Aall "Show all Logical Disk group Information" #/opt/megaraid/megacli/megacli64-pdlist-Aall "Show All Physical Information" #/opt/megaraid/megacli/megacli64-adpbbucmd-getbbustatus-aall |grep' Charger status ' "View charging status" #/opt/megaraid/megacli/megacli64-adpbbucmd-getbbustatus-Aall "Show Bbu status information" #/opt/megaraid/megacli/megacli64-adpbbucmd-getbbucapacityinfo-Aall "Show Bbu Capacity Information" #/opt/megaraid/megacli/megacli64-adpbbucmd-getbbudesigninfo-aall "Show Bbu Design Parameters" #/opt/megaraid/megacli/megacli64-adpbbucmd-getbbuproperties-aall "Show Current Bbu Properties" #/opt/megaraid/megacli/megacli64-cfgdsply-Aall "Show raid card model, RAID settings, disk related information"3changes in the status of the tape, from the drawing to the disk. Device| normal| damage| rebuild|normalvirtual Drive| optimal| degraded| degraded|optimalphysical Drive| online| Failed–> unconfigured| rebuild|Online4. viewing disk cache Policies #/opt/megaraid/megacli/megacli64-ldgetprop-cache-l0-a0or#/OPT/MEGARAID/MEGACLI/MEGACLI64-LDGETPROP-CACHE-L1-a0or#/opt/megaraid/megacli/megacli64-ldgetprop-cache-lall-a0ro#/opt/megaraid/megacli/megacli64-ldgetprop-cache-lall-aallro#/opt/megaraid/megacli/megacli64-ldgetprop-dskcache-lall-Aall5. Set disk cache policy cache policy explanation: WT (write Throughwb (write back) NORA (No read ahead) RA (read ahead) ADRA (Adaptive read ahead) Cacheddir ECT Example: #/opt/megaraid/megacli/megacli64-ldsetprop wt| wb| nora| ra| Adra-l0-a0or#/opt/megaraid/megacli/megacli64-ldsetprop-cached|-direct-l0-a0orenable/Disable Disk cache#/opt/megaraid/megacli/megacli64-ldsetprop-endskcache|-disdskcache-l0-A06. Create a RAID5 array, by the physical disk2,3,4The array's hot spare is the physical disk5#/OPT/MEGARAID/MEGACLI/MEGACLI64-CFGLDADD-R5 [1:2,1:3,1:4] WB direct-hsp[1:5] -A07. Creating an array without specifying HOT spares #/OPT/MEGARAID/MEGACLI/MEGACLI64-CFGLDADD-R5 [1:2,1:3,1:4] WB Direct-A08. Delete Array #/OPT/MEGARAID/MEGACLI/MEGACLI64-CFGLDDEL-L1-A09. Add a disk online #/opt/megaraid/megacli/megacli64-ldrecon-start-r5-add-physdrv[1:4]-L1-A0Tenafter the array is created, there is a process to initialize the synchronization block to see its progress. #/opt/megaraid/megacli/megacli64-ldinit-showprog-lall-Aall or display in dynamic visual text interface #/opt/megaraid/megacli/megacli64-ldinit-progdsply-lall-Aall One. Viewing array background Initialization Progress #/opt/megaraid/megacli/megacli64-ldbi-showprog-lall-Aall or display in dynamic visual text interface #/opt/megaraid/megacli/megacli64-ldbi-progdsply-lall-Aall A. Specifies that section5block disks as global Hot Spares #/opt/megaraid/megacli/megacli64-pdhsp-set [-enclaffinity] [-nonrevertible]-physdrv[1:5] -A0 -. Specify a dedicated hot spare for an array #/opt/megaraid/megacli/megacli64-pdhsp-set [-dedicated [-array1]] [-enclaffinity] [-nonrevertible]-PhysDrv[1:5] -A0 -. Delete Global Hot Spares #/opt/megaraid/megacli/megacli64-pdhsp-rmv-physdrv[1:5] -A0 the. Put a physical disk off the line/Online #/opt/megaraid/megacli/megacli64-pdoffline-physdrv [1:4] -a0#/opt/megaraid/megacli/megacli64-pdonline-physdrv [1:4] -A0 -. View Physical Disk rebuild Progress #/opt/megaraid/megacli/megacli64-pdrbld-showprog-physdrv [1:5] -A0 or display in dynamic visual text interface #/opt/megaraid/megacli/megacli64-pdrbld-progdsply-physdrv [1:5] -A0 changes in the status of the tape, from the drawing to the disc: Device| normal| damage| rebuild|normalvirtual Drive| optimal| degraded| degraded|optimalphysical Drive| online| Failed–> unconfigured| rebuild| Online
- Fill in the blanks and you can export them.
Shell script collects the hardware information of Linux Server in batches fast implementation