又犯了一個錯誤,MySQL的,
lower_case_table_names=1這個引數一定要在安裝完mysql後改為1.不然,以後有肯能會出現,
Error was: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Duplicate column name `groupl
參考 shell自動收集伺服器硬體系統資訊通過web頁面顯示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
有幾個地方要注意一下 1.php php 500 yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
php.ini 修改php.ini配置檔案,error_reporting = E_ALL & ~E_NOTICE 在php.ini中設定 date .timezone的值為PRC,設定好以後的為: date .timezone=PRC
2.mysql 1)mysql不要使用root 2)如果通過ansible執行的話,客戶端沒有安裝mysql客戶端,需要安裝 yum -y install mysql,還需要覆蓋my.cnf
cat /etc/my .cnf
[mysqld] datadir= /var/lib/mysql
socket= /var/lib/mysql/mysql .sock
user=mysql lower_case_table_names=1 default-character- set = utf8
character_set_server = utf8 default-storage-engine=InnoDB # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 max_allowed_packet=100M [mysqld_safe] log-error= /var/log/mysqld .log
pid- file = /var/run/mysqld/mysqld .pid
主要是字符集的問題 3)如果是編譯安裝mysql,那麼用 which mysql
3.建立資料庫 CREATE TABLE `systeminfo` ( ` id ` int(11) NOT NULL AUTO_INCREMENT,
`ip_info` varchar(50) NOT NULL,
`cpu_info` varchar(50) NOT NULL,
`disk_info` varchar(50) NOT NULL,
`mem_info` varchar(50) NOT NULL,
`service_info` varchar(200) NOT NULL,
PRIMARY KEY (` id `),
UNIQUE KEY `ip_info` (`ip_info`),
UNIQUE KEY `ip_info_2` (`ip_info`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 4.修改過後的指令碼 cat systeminfo.sh
#!/bin/bash #auto get system info echo -e " 33[34m 33[1m"
cat <<EOF
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++Welcome to use system Coolect++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ EOF ip_info=` ifconfig | awk `/inet addr/ {gsub(/:/," ");print $3}` | grep - v 127.0.0.1`
cpu_info1=` cat /proc/cpuinfo | grep "model name" | awk -F: `{print $2}` | sed `s/^//g` | awk `{print $1,$3,$4,$NF}` `
cpu_info2=` cat /proc/cpuinfo | grep "physical id" | sort | uniq -c| wc -l`
cpu_info3=` grep processor /proc/cpuinfo | wc -l`
serv_info=` hostname | tail -1`
disk_xinfo=` fdisk -l| grep "Disk" | grep - v "identifier" | awk `{print $2,$3,$4}` | sed `s/,//g` `
disk_info=` fdisk -l| grep "Disk" | grep - v "identifier" | awk `{print $2,$3,$4}` | sed `s/,//g` | grep - v mapper| awk -F ` ` `{print $2}` | awk `{sum += $1} END {print sum}` `
mem_info=` free -m| awk `/Mem/ {printf ("%.f `
services=(nginx gitlab ntpd tomcat mysql ldap nexus) for var in ${services[@]}
do num=` ps -ef| grep $var| grep - v grep | wc -l`
if [ $num -gt 1 ]; then
service_info=${var} " " ${service_info}
fi
done echo -e " 33[32m------------------------------------- 33[1m"
echo IPADDR:${ip_info}
echo HOSTNAME:$serv_info
echo CPU_INFO:${cpu_info1}X${cpu_info2}
echo Disk_INFO:$disk_info
echo MEM_INFO:$mem_info
echo service_info:$service_info
#echo -e -n " 33[36m You want to write the data to the databases? 33[1m";read ensure #if [ "$ensure" == "yes" -o "$ensure" == "y" -o "$ensure" == "Y" ];then echo "------------------------"
result=` which mysql`
if [ $? - ne 0 ]; then
yum -y install mysql
result=` which mysql`
fi $result -uxx -pxx -h xx -D xx -e "insert into systeminfo values(``,`${ip_info}`,`${cpu_info3}" 核 "`,`$disk_info" G "`,`$mem_info" G "`,`$service_info`);"
#else if [ $? - ne 0 ]; then
echo "what exit"
exit 1
fi 5.通過ansible呼叫hosts分組執行 ansible xx -m script -a `systeminfo.sh`
6.php環境搭建 php環境用yum搭建,比如yum -y install php php-fpm,啟動 /etc/init .d /php-fpm
nginx配置檔案 server { listen 80;
server_name xx;
access_log /opt/log/check .log;
error_log /opt/log/check .error;
root /opt/check ;
location / {
index index.php index.html index.htm;
allow xx /24 ;
deny all;
}
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
expires 30d; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht { deny all;
}
} 7.php頁面顯示 <html> < head >
<title>伺服器管理統計< /title >
< /head >
<body> <?php $con = mysql_connect( "xx" , "xx" , "xx" );
if (!$con)
{
die( `資料庫連線失敗: ` . mysql_error());
}
else
{
mysql_query( "SET NAMES UTF8" );
mysql_query( "set character_set_client=utf8" );
mysql_query( "set character_set_results=utf8" );
mysql_select_db( "xx" , $con);
$result = mysql_query( "SELECT * FROM systeminfo inet_aton(ip_info)" );
// 在表格中輸出顯示結果
echo "<table border= `1` >
< tr >
<th>主機IP< /th >
<th>主機名< /th >
<th>cup型號< /th >
<th>磁碟< /th >
<th>記憶體< /th >
<th>負載< /th >
<th>機房< /th >
< /tr >";
while ($row = mysql_fetch_array($result))
{
echo "<tr>" ;
echo "<td>" . $row[ `ip_info` ] . "</td>" ;
echo "<td>" . $row[ `serv_info` ] . "</td>" ;
echo "<td>" . $row[ `cpu_info` ] . "</td>" ;
echo "<td>" . $row[ `disk_info` ] . "</td>" ;
echo "<td>" . $row[ `mem_info` ] . "</td>" ;
echo "<td>" . $row[ `load_info` ] . "</td>" ;
echo "<td>" . $row[ `mark_info` ] . "</td>" ;
echo "</tr>" ;
}
echo "</table>" ;
} mysql_close($con); ?> < /body >
|