重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
file /sbin/init #查看32/64位机器
创新互联建站专注于企业全网整合营销推广、网站重做改版、河北网站定制设计、自适应品牌网站建设、H5场景定制、商城建设、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为河北等各大城市提供网站开发制作服务。
uname -r#查看linxu版本
yum -y install gcc gcc-c++ autoconf httpd php MySQL lrzsz mysql-server php-mysql httpd-
manual mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-mbstring php-ldap php-pear php-
xmlrpc php-bcmath mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-
devel php-fpm pcre openssl openssl-devel libjpeg* php-imap php php-mysql php-gd libjpeg*
php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath
php-mhash libmcrypt libmcrypt-devel php-fpm php-pecl*
#配置nginx
*这里绑定了两个端口,一般只要80就行了。
*vim /etc/nginx/conf.d/default.conf
server {
listen 80 default_server;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
*vim /etc/nginx/conf.d/zabbix.conf
server {
listen 10.17.26.176:8080;
listen 10.17.26.176:80;
server_name 10.17.26.176;
location / {
root html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
}
/usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
chkconfig nginx on
/etc/init.d/nginx start
=======================================================================
#配置php
cp /etc/php.ini php.ini.bak
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini
sed -i "s#max_execution_time = 30#max_execution_time = 300#g" /etc/php.ini
sed -i "s#post_max_size = 8M#post_max_size = 32M#g" /etc/php.ini
sed -i "s#max_input_time = 60#max_input_time = 300#g" /etc/php.ini
sed -i "s#memory_limit = 128M#memory_limit = 128M#g" /etc/php.ini
sed -i "/;mbstring.func_overload = 0/ambstring.func_overload = 2\n" /etc/php.ini
sed -i 's/^user =.*/user = nginx/g' /etc/php-fpm.d/www.conf
sed -i 's/^group =.*/group = nginx/g' /etc/php-fpm.d/www.conf
chkconfig nginx on
/etc/init.d/php-fpm start
===============================================================================
#配置mysql
mysql#进入mysql
*用户为zabbix_uesr 密码为 zabbix(之后为zabbix登陆用户名和密码)
insert into mysql.user(Host,User,Password) values("localhost","zabbix_user",password
("zabbix"));
flush privileges;#刷新权限
mysql -u root
*创建数据库名字为zabbix
*为了支持中文,数据库字符集采用utf8,在定义添加设备的时候可以使用中文名称
*授权zabbix系统访问Mysql数据库的用户和密码,zabbixdb.*指的是访问zabbixdb库内的所有表
create database zabbix character set utf8;
grant all privileges on zabbix.* to zabbix_user@localhost identified by 'zabbix';
flush privileges;
chkconfig mysqld on
service mysqld start
===========================================================
#配置zabbix
groupadd zabbix -g 1001
useradd -g zabbix -u 1001 -m zabbix
cat /etc/group | grep zabbix
cat /etc/passwd | grep zabbix
tar -zxvf zabbix-2.0.18.tar.gz
cd ./zabbix-2.0.18
./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --
with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl
make
make install
configure: error: Not found mysqlclient library
cd /usr/lib64/mysql/
ln -s libmysqlclient.so.16.0.0 libmysqlclient.so
ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so
configure: error: Invalid NET-SNMP directory - unable to find net-snmp-config
wget ftp://fr2.rpmfind.net/linux/opensuse/update/12.3/x86_64/net-snmp-devel-5.7.2-
3.12.1.x86_64.rpm
yum -y install net-snmp-devel
cat /etc/services | grep zabbix
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
cd /root/zabbix-2.0.18
mysql -uzabbix_user -pzabbix zabbix < ./database/mysql/schema.sql
mysql -uzabbix_user -pzabbix zabbix < ./database/mysql/p_w_picpaths.sql
mysql -uzabbix_user -pzabbix zabbix < ./database/mysql/data.sql
*创建zabbix的的日志文件和连接
chown zabbix.zabbix /tmp
ln -s /usr/local/zabbix/etc /etc/zabbix
ln -s /usr/local/zabbix/bin/* /usr/bin/
ln -s /usr/local/zabbix/sbin/* /usr/sbin/
*拷贝与配置zabbix启动文件
cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
chmod 755 /etc/init.d/zabbix_*
sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/init.d/zabbix_server
sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/init.d/zabbix_agentd
chkconfig zabbix_server on #添加开机启动
chkconfig zabbix_agentd on #添加开机启动
*配置zabbix_server.conf服务端文件
sed -i "s/DBName\=zabbix/DBName\=zabbix/g" /etc/zabbix/etc/zabbix_server.conf
sed -i "s/DBUser\=root/DBUser\=zabbix_uesr/g" /etc/zabbix/etc/zabbix_server.conf
sed -i "/# DBPassword=/aDBPassword=zabbix\n" /etc/zabbix/etc/zabbix_server.conf
sed -i "s#tmp/zabbix_server.log#var/log/zabbix/zabbix_server.log#g"
/etc/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
*配置 zabbix_agentd.conf 文件
sed -i "s/Server\=127.0.0.1/Server\=127.0.0.1,10.17.26.176/g"
/etc/zabbix/etc/zabbix_agentd.conf
sed -i "s/ServerActive\=127.0.0.1/ServerActive\=10.17.26.176:10051/g"
/etc/zabbix/etc/zabbix_agentd.conf
#sed -i "s#tmp/zabbix_agentd.log#var/log/zabbix/zabbix_agentd.log#g"
/etc/zabbix/etc/zabbix_agentd.conf
sed -i "s/UnsafeUserParameters=0/UnsafeUserParameters=1\n"
/etc/zabbix/etc/zabbix_agentd.conf
#sed -i "s/Server\=127.0.0.1,10.17.26.176/Server\=127.0.0.1/g"
/etc/zabbix/etc/zabbix_agent.conf
#sed -i "s/ServerActive\10.17.26.176:10051=/ServerActive\=127.0.0.1/g"
/etc/zabbix/etc/zabbix_agent.conf
cd /root/zabbix-2.0.18
cp -r ./frontends/php/* /usr/share/nginx/html/
chown -R nginx.nginx /usr/share/nginx/html/
*php指向数据库(zabbix和数据库在一台机器上的不用配置)
vim /usr/share/nginx/html/zabbix/conf/zabbix.conf.php
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '10.17.1.43';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'root';
$DB['PASSWORD'] = 'yihaodian';
/etc/init.d/nginx restart
/etc/init.d/zabbix_server restart
/etc/init.d/zabbix_agentd restart
/etc/init.d/php-fpm restart
#导入其他机器备份数据库
链接其他的zabbix数据库,把上面的备份导一份进去,然后再把里面缺失的表,用该库的建表语句建一下
表
mysql -h20.17.1.43 -uXXX -pXXX zabbix
ssh 10.17.26.8
zcat /data/backup/zabbix_jq_20160614_*z | mysql -h20.17.1.43 -uroot -pyihaodian zabbix
(zcat aaa.gz | mysql -h20.17.1.43 -uroot -pyihaodian zabbix)
diff 其他数据库 和 新数据库 查看要建哪些表
events sessions
trends trends_uint history_text history_uint history_str
show create table history;
CREATE TABLE `trends` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`num` int(11) NOT NULL DEFAULT '0',
`value_min` double(16,4) NOT NULL DEFAULT '0.0000',
`value_avg` double(16,4) NOT NULL DEFAULT '0.0000',
`value_max` double(16,4) NOT NULL DEFAULT '0.0000',
PRIMARY KEY (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `trends_uint` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`num` int(11) NOT NULL DEFAULT '0',
`value_min` bigint(20) unsigned NOT NULL DEFAULT '0',
`value_avg` bigint(20) unsigned NOT NULL DEFAULT '0',
`value_max` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `history_text` (
`id` bigint(20) unsigned NOT NULL,
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` text NOT NULL,
`ns` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `history_text_2` (`itemid`,`id`),
KEY `history_text_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `sessions` (
`sessionid` varchar(32) NOT NULL DEFAULT '',
`userid` bigint(20) unsigned NOT NULL,
`lastaccess` int(11) NOT NULL DEFAULT '0',
`status` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`sessionid`),
KEY `sessions_1` (`userid`,`status`),
CONSTRAINT `c_sessions_1` FOREIGN KEY (`userid`) REFERENCES `users` (`userid`) ON DELETE
CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `history_uint` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` bigint(20) unsigned NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
KEY `history_uint_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `history_str` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` varchar(255) NOT NULL DEFAULT '',
`ns` int(11) NOT NULL DEFAULT '0',
KEY `history_str_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `events` (
`eventid` bigint(20) unsigned NOT NULL,
`source` int(11) NOT NULL DEFAULT '0',
`object` int(11) NOT NULL DEFAULT '0',
`objectid` bigint(20) unsigned NOT NULL DEFAULT '0',
`clock` int(11) NOT NULL DEFAULT '0',
`value` int(11) NOT NULL DEFAULT '0',
`acknowledged` int(11) NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
`value_changed` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`eventid`),
KEY `events_1` (`object`,`objectid`,`eventid`),
KEY `events_2` (`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql> set foreign_key_checks=off;
Query OK, 0 rows affected (0.00 sec)
mysql> drop table events;
Query OK, 0 rows affected (0.00 sec)
mysql> set foreign_key_checks=on;
Query OK, 0 rows affected (0.00 sec)
导好后把那些hosts先disable掉
update hosts set status=1 where status=0;
重启zabbix server
#install_zabbix218
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
mv yihaodian.repo yihaodian.repo.bak
yum -y install net-snmp-devel
yum -y install mysql
yum -y install mysqld
yum -y install mysql-server
yum -y install mysql-devel
yum -y install curl-devel
cd /root/
mkdir software
cd software/
wget 'http://liquidtelecom.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.18/zabbix-2.0.18.tar.gz'
tar zxvf zabbix-2.0.18.tar.gz
cd /root/software/zabbix-2.0.18
./configure --prefix=/usr/local/zabbix-2.0.18 --enable-server --enable-proxy --enable-agent --enable-java --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl
make install
cd /usr/local/
ln -s zabbix-2.0.18 zabbix
cd /root/software/
yum -y install php
yum -y install php-fpm
yum -y install gd
yum -y install gd-devel
yum -y install php-gd
yum -y install openssl
wget 'http://nginx.org/download/nginx-1.10.1.tar.gz'
wget 'ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz'
tar zxvf pcre-8.38.tar.gz
tar zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
./configure --prefix=/usr/local/nginx-1.10.1 --with-pcre=../pcre-8.38/
make
make install
cd /usr/local/
ln -s nginx-1.10.1 nginx
vim /etc/sysctl.conf
sysctl -p
cd /root/software/
wget 'http://www.fping.org/dist/fping-3.13.tar.gz'
tar zxvf fping-3.13.tar.gz
cd fping-3.13
./configure
make install
rsync -av /usr/local/sbin/fping /usr/sbin/
chmod u+s /usr/sbin/fping
yum -y install telnet
yum -y install nc
yum -y install nmap
yum -y install tcpdump
cd /usr/local/zabbix/etc/
rsync -av zabbix_server.conf zabbix_server.conf-orig
rsync -av deploy@10.4.4.232:/usr/local/zabbix/etc/zabbix_server.conf .
rsync -av deploy@10.4.4.232:/usr/local/zabbix/share/zabbix/externalscripts/ /usr/local/zabbix/share/zabbix/externalscripts/
rsync -av deploy@10.4.4.232:/etc/zabbix/ /etc/zabbix/
cd
rsync -av deploy@10.4.4.232:/root/*.sh .
rsync -av deploy@10.4.4.232:/root/*.pl .
rsync -av deploy@10.4.4.232:/root/*.json .
cd /usr/local/nginx
mv conf conf.orig
rsync -av deploy@10.4.4.231:/usr/local/nginx/conf .
rsync -av deploy@10.4.4.231:/usr/local/php/etc/php-fpm.conf /root/
cd /etc/
cp /root/php-fpm.conf .
cd /usr/local/nginx/conf/vhosts/
mkdir /data/httpd -p
###############下面这条主要修改了里面的ip为本机的ip#############
vim zabbix.conf
rsync -av deploy@10.4.4.231:/data/httpd/ /data/httpd/
rsync -av deploy@10.4.4.232:/etc/init.d/zabbix_server /etc/init.d/
sh /root/set_zabbix_db_config.sh
rm -f /etc/zabbix/zabbix_server.conf
ln -s /usr/local/zabbix/etc/zabbix_server.conf /etc/zabbix/
/etc/init.d/zabbix_server start
mkdir /home/logs
chown nobody.nobody -R /home/logs
/usr/local/nginx/sbin/nginx
groupadd www
useradd -g www www
id www
/usr/local/nginx/sbin/nginx
cd /data/httpd/zabbix
yum -y install cups-php.x86_64 graphviz-php.x86_64 php.x86_64 php-bcmath.x86_64 php-cli.x86_64 php-common.x86_64 php-dba.x86_64 php-devel.x86_64 php-embedded.x86_64 php-fpm.x86_64 php-gd.x86_64 php-imap.x86_64 php-intl.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mysql.x86_64 php-odbc.x86_64 php-pdo.x86_64 php-pear.noarch php-pecl-apc.x86_64 php-pgsql.x86_64 php-process.x86_64 php-pspell.x86_64 php-recode.x86_64 php-snmp.x86_64 php-soap.x86_64 php-tidy.x86_64 php-xml.x86_64 php-xmlrpc.x86_64 php-zts.x86_64 rrdtool-php.x86_64 uuid-php.x86_64 php-enchant.x86_64 php-pecl-apc-devel.i686 php-pecl-apc-devel.x86_64 php-pecl-memcache.x86_64
/etc/init.d/php-fpm start
chkconfig --add zabbix_server
chkconfig --level 2345 zabbix_server on
chkconfig --add php-fpm
chkconfig --level 2345 php-fpm on
chkconfig --list
###################加入nginx开机启动#############
vim /etc/rc.local