一、安装httpd
1.安装
yum install httpd
2.启动
httpd
3.停止
httpd -k stop
5.开机自启
chkconfig httpd on
6.修改属主
chown -R apache:apache /var/www/html
二、ansible-cmdb 使用
1.ansible-cmd生成所有主机得facts信息
[root@big ~]# ansible all -m setup --tree out/
[root@big ~]# ansible-cmdb out/ > overview.html
Couldn't find /usr/local/bin/ansible-cmdb.py in . or /usr/local/bin/../lib/ansible-cmdb/ or /usr/local/bin/../lib/ansiblecmdb/ (cwd=/root)
[root@big ~]#
[root@big ~]# cp /ansible-cmdb-1.27/src/ansible-cmdb.py /an/usr/local/bin/
[root@big ~]# ansible-cmdb out/ > overview.html
2.将生成的facts信息生成web页面
[root@big ~]# ansible-cmdb out/ > overview.html
[root@big ~]# ll
total 114736
drwxr-xr-x 2 root root 4096 Jul 26 16:34 out
-rw-r--r-- 1 root root 102989 Jul 26 16:38 overview.html
[root@big ~]#
以资产列表得形式统计出ansible主机信息
[root@big ~]# ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus out/
Name OS IP Mem CPUs
-------------------------- --------------- ------------ --- ----
172.16.18.22 CentOS 7.5.1804 172.16.18.22 2g 2
172.16.18.23 CentOS 7.5.1804 172.16.18.23 2g 2
172.16.18.21 CentOS 7.5.1804 172.16.18.21 2g 2
3. web形式展示
overview.html cp到/var/www/html目录下
[root@big ~]# cp overview.html /var/www/html/
http://172.16.18.19/overview.html (172.16.18.19为部署ansible-cmdb的服务器ip)
4.输出sql文件,导入数据到mysql
[root@big ~]# ansible-cmdb -t sql out > cmdb.sql
[root@big ~]# ls -al cmdb.sql
-rw-r--r-- 1 root root 11567 Jul 27 08:58 cmdb.sql
[root@big ~]#
查看mariadb状态
[root@big ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2018-07-27 09:30:10 CST; 4min 10s ago
Process: 8703 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 8671 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 8702 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─8702 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─8985 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-...
Jul 27 09:30:08 big.local systemd[1]: Starting MariaDB database server...
Jul 27 09:30:08 big.local mariadb-prepare-db-dir[8671]: Database MariaDB is probably i....
Jul 27 09:30:08 big.local mariadb-prepare-db-dir[8671]: If this is not the case, make ....
Jul 27 09:30:09 big.local mysqld_safe[8702]: 180727 09:30:09 mysqld_safe Logging to '...'.
Jul 27 09:30:09 big.local mysqld_safe[8702]: 180727 09:30:09 mysqld_safe Starting mys...ql
Jul 27 09:30:10 big.local systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@big ~]#
导入cmdb.sql
[root@big ~]# mysql -uroot -p cmdb < cmdb.sql
Enter password:
[root@big ~]#
5.登陆数据库,查看数据
[root@big ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cmdb |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use cmdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [cmdb]> show tables;
+----------------+
| Tables_in_cmdb |
+----------------+
| hosts |
+----------------+
1 row in set (0.00 sec)
MariaDB [cmdb]> select * from hosts;
+----------------------------+----------+--------------+---------+------------+--------+-----------------------+---------------+----------------+-----------+-----------+-------------------------------------------+-------+------+------------+-----------+
| name | fqdn | main_ip | os_name | os_version | system | kernel | arch_hardware | arch_userspace | virt_type | virt_role | cpu_type | vcpus | ram | disk_total | disk_free |
+----------------------------+----------+--------------+---------+------------+--------+-----------------------+---------------+----------------+-----------+-----------+-------------------------------------------+-------+------+------------+-----------+
| 172.16.18.22 | hserver2 | 172.16.18.22 | CentOS | 7.5.1804 | Linux | 3.10.0-862.el7.x86_64 | x86_64 | x86_64 | VMware | guest | Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz | 2 | 1.8 | 27 | 24.2 |
| 172.16.18.23 | hserver3 | 172.16.18.23 | CentOS | 7.5.1804 | Linux | 3.10.0-862.el7.x86_64 | x86_64 | x86_64 | VMware | guest | Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz | 2 | 1.8 | 27 | 24.2 |
| 172.16.18.21 | hserver1 | 172.16.18.21 | CentOS | 7.5.1804 | Linux | 3.10.0-862.el7.x86_64 | x86_64 | x86_64 | VMware | guest | Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz | 2 | 1.8 | 27 | 22.9 |
+----------------------------+----------+--------------+---------+------------+--------+-----------------------+---------------+----------------+-----------+-----------+-------------------------------------------+-------+------+------------+-----------+
20 rows in set (0.00 sec)
MariaDB [cmdb]>
6. 导出csv
[root@big tmp]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use cmdb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [cmdb]> show tables;
+----------------+
| Tables_in_cmdb |
+----------------+
| hosts |
+----------------+
1 row in set (0.01 sec)
MariaDB [cmdb]> select * from hosts into outfile '/tmp/hosts.csv';
Query OK, 20 rows affected (0.00 sec)
MariaDB [cmdb]>
查看hosts.csv
[root@big tmp]# ll
total 4
-rw-rw-rw- 1 mysql mysql 1167 Jul 27 09:49 hosts.csv
[root@big tmp]#