1.首先安装依赖包:
yum install pcre pcre-devel gcc-c++ gcc zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel zlib openssl openssl-devel gcc gcc-c++ make lrzsz cmake ncurses-devel libaio-devel bzip2-devel -y
2.编译安装nginx
[root@zabbix tool]# useradd nginx -s /sbin/nologin -M
[root@zabbix tool]# tar -xf nginx-1.6.3.tar.gz && cd nginx-1.6.3
[root@zabbix nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.6.3 --with-http_stub_status_module --with-http_ssl_module
[root@zabbix nginx-1.6.3]# make && make install
[root@zabbix nginx-1.6.3]# ln -s /usr/local/nginx-1.6.3 /usr/local/nginx
#检查语法
[root@zabbix nginx-1.6.3]# /usr/local/nginx/sbin/nginx -t
启动命令
[root@zabbix nginx-1.6.3]# /usr/local/nginx/sbin/nginx
[root@zabbix nginx-1.6.3]# lsof -i:80
selinux
[root@zabbix nginx-1.6.3]# setenforce 0
[root@zabbix nginx-1.6.3]# sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config
iptables
[root@zabbix nginx-1.6.3]# iptables -F
[root@zabbix nginx-1.6.3]# iptables -X
[root@zabbix nginx-1.6.3]# service iptables save
[root@zabbix nginx-1.6.3]# service iptables restart
zabbix不配虚拟主机直接修改nginx.conf
[root@zabbix nginx-1.6.3]# cat /usr/local/nginx/conf/nginx.conf
worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } access_log logs/access.log main; #nginx记录日志的默认参数配置 } }
解释nginx.conf
error_log logs/error.log; 打开日志 这是日志记录 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
编写nginx访问日志:
编写nginx访问日志轮询切割: [root@zabbix scripts]# cat /home/scripts/cut_nginx_log.sh #!/bin/sh Dataformat=`date +%Y-%m-%d-%H:%M:%S` Basedir="/usr/local/nginx" Nginxlogdir="$Basedir/logs" Logname="access_www" [ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1 [ -f ${Logname}.log ] || exit 1 /bin/mv ${Logname}.log ${Dataformat}_${Logname}.log $Basedir/sbin/nginx -s reload
[root@zabbix scripts]# crontab -l */1 * * * * /bin/sh /home/scripts/cut_nginx_log.sh > /dev/null 2 >&1 [root@zabbix scripts]# cat rm_nginxlog_tenage.sh #删除10天前的nginxlog备份日志 #!/bin/bash find /usr/local/nginx/logs/ -mtime +10 -name '[0-9]*' -exec rm -rf {} ; 以上为nginx安装 这边的测试时间为 */1 * * * * 每分钟切割日志一次
nginx启动脚本的编写:
[root@zabbix ~]# cat /etc/init.d/nginx
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVA
[root@zabbix nginx-1.6.3]# chmod +x /etc/init.d/nginx
[root@zabbix nginx-1.6.3]# chkconfig --add /etc/init.d/nginx
[root@zabbix nginx-1.6.3]# chkconfig nginx on
===================================================================================
mysql安装脚本
#!/bin/bash groupadd mysql useradd -s /sbin/nologin -g mysql -M mysql tar zxf mysql-5.6.13.tar.gz cd mysql-5.6.13 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci make && make install cd ../ chown -R mysql.mysql /usr/local/mysql/ cd /usr/local/mysql #scripts/mysql_install_db --datadir=/usr/local/mysql/data --user=mysql scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql cd /usr/local/mysql/ cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf sed -i '/# log_bin/aport = 3306' /etc/my.cnf sed -i '/# log_bin/asocket = /tmp/mysql.sock' /etc/my.cnf sed -i '/# log_bin/adatadir =/usr/local/mysql/data' /etc/my.cnf sed -i '/# log_bin/abasedir =/usr/local/mysql' /etc/my.cnf echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile source /etc/profile service mysqld start mkdir -p /usr/local/mysql/bin/mysqladmin -u root password '123456' cat > /tmp/mysql_sec_script<<EOF use mysql; update user set password=password('123456') where user='root'; drop database if exists test; drop user ""@"localhost"; drop user ""@"hostname"; drop user "root"@"hostname"; drop user "root"@"::1"; flush privileges; EOF var=`hostname` sed -i "s/hostname/$var/g" /tmp/mysql_sec_script /usr/local/mysql/bin/mysql -u root -p'123456' -h localhost < /tmp/mysql_sec_script rm -f /tmp/mysql_sec_script service mysqld restart
添加zabbix用户,zabbix库
create database zabbix default charset utf8;
use mysql
GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'xxx';
flush privileges;
===========================================
PHP安装
============================================
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
[root@zabbix tool]# tar -xf php-5.5.38.tar.gz
[root@zabbix tool]# cd php-5.5.38
./configure --prefix=/usr/local/php-5.5.38 --with-config-file-path=/usr/local/php-5.5.38/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
#make
#make install
#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@zabbix local]# ln -s /usr/local/php-5.5.38/ /usr/local/php
[root@zabbix php-5.5.38]# pwd
/root/tool/php-5.5.38
[root@zabbix php-5.5.38]# cp php.ini-production /usr/local/php-5.5.38/etc/php.ini
[root@zabbix php-5.5.38]# cp /usr/local/php-5.5.38/etc/php-fpm.conf.default /usr/local/php-5.5.38/etc/php-fpm.conf
[root@zabbix php-5.5.38]# /usr/local/php-5.5.38/sbin/php-fpm
[root@zabbix php-5.5.38]# lsof -i:9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 29366 root 7u IPv4 160434 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 29367 nobody 0u IPv4 160434 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 29368 nobody 0u IPv4 160434 0t0 TCP localhost:cslistener (LISTEN)
[root@zabbix php-5.5.38]# vim /usr/local/php-5.5.38/etc/php.ini
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone PRC
打开pid = run
/php-fpm
.pid
vim /usr/local/php-5.5.38/etc/php-fpm.conf
pid = run/php-fpm.pid
编写php启动脚本
#!/bin/bash # php-fpm startup script for the php-fpm # php-fpm version:5.5.38 # chkconfig: - 85 15 # description: php-fpm is very good # processname: php-fpm # pidfile: /var/run/php-fpm.pid # config: /usr/local/php/etc/php-fpm.conf php_command=/usr/local/php/sbin/php-fpm php_config=/usr/local/php/etc/php-fpm.conf php_pid=/usr/local/php/var/run/php-fpm.pid RETVAL=0 prog="php-fpm" #start function php_fpm_start() { /usr/local/php/sbin/php-fpm } start(){ if [ -e $php_pid ] then echo "php-fpm already start..." exit 1 fi php_fpm_start } stop(){ if [ -e $php_pid ] then parent_pid=`cat $php_pid` all_pid=`ps -ef | grep php-fpm | awk '{if('$parent_pid' == $3){print $2}}'` for pid in $all_pid do kill $pid done kill $parent_pid fi exit 1 } restart(){ stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|status}" exit 1 esac exit $RETVAL
## 添加执行权限
chmod a+x /etc/init.d/php-fpm
## 加入服务
chkconfig --add php-fpm
## 开机自启
chkconfig php-fpm on
======================================================
zabbix安装:
yum install net-snmp-devel libxml2-devel libcurl-devel -y
[root@zabbix tool]# tar -xf zabbix-2.4.4.tar.gz && cd zabbix-2.4.4
[root@zabbix tool]# ./configure --prefix=/usr/local/zabbix-2.4.4/ --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
[root@zabbix tool]# make
[root@zabbix tool]# make install
#vim /etc/services
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
[root@zabbix conf]# pwd
/root/tool/zabbix-2.4.4/conf
#groupadd zabbix
#useradd -g zabbix -m zabbix
#mkdir -p /etc/zabbix
[root@zabbix zabbix-2.4.4]# /usr/local/mysql/bin/mysql -uroot -p123456 zabbix < /root/tool/zabbix-2.4.4/database/mysql/schema.sql
[root@zabbix zabbix-2.4.4]# /usr/local/mysql/bin/mysql -uroot -p123456 zabbix < /root/tool/zabbix-2.4.4/database/mysql/images.sql
[root@zabbix zabbix-2.4.4]# /usr/local/mysql/bin/mysql -uroot -p123456 zabbix < /root/tool/zabbix-2.4.4/database/mysql/data.sql
配置zabbix:
[root@zabbix sbin]# ln -s /usr/local/zabbix-2.4.4/etc/zabbix_server.conf /etc/zabbix/zabbix_server.conf
[root@zabbix sbin]# ln -s /usr/local/zabbix-2.4.4/etc/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf
[root@zabbix sbin]# vim /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
LogFile=/tmp/zabbix_server.log
[root@zabbix html]# cat /usr/local/nginx/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; root /usr/local/nginx/html; #修改nginx默认目录 index index.php index.html index.htm; #添加nginx支持php索引 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #修改为$document_root$fastcgi_script_name; include fastcgi_params; } } }
[root@zabbix1 frontends]# pwd
/root/tool/zabbix-2.4.4/frontends
[root@zabbix1 zabbix-2.4.4]# cd frontends/
[root@zabbix1 frontends]# ls
php
[root@zabbix1 frontends]# cp -rf php/ /usr/local/nginx/html/
[root@zabbix1 frontends]# cd /usr/local/nginx/html/
[root@zabbix1 html]# mv php zabbix
[root@zabbix1 html]# chown -R zabbix:zabbix zabbix
[root@zabbix zabbix]# cp /root/tool/zabbix-2.4.4/misc/init.d/fedora/core/zabbix_* /etc/init.d/
[root@zabbix zabbix]# chmod +x /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix-2.4.4
[root@zabbix zabbix]# chmod +x /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix-2.4.4
[root@zabbix html]# chkconfig --add zabbix_server
[root@zabbix html]# chkconfig --add zabbix_agentd
[root@zabbix html]# chkconfig --level 35 zabbix_server on
[root@zabbix html]# chkconfig --level 35 zabbix_agentd on
[root@zabbix html]# service zabbix_server start
安装gateway以便于配置jmx监测
进入zabbix安装包目录
yum -y install zabbix-java-gateway-3.4.4-2.el6.x86_64.rpm
/etc/init.d/zabbix-java-gateway start
chkconfig --level 345 zabbix-java-gateway on
修改中文乱码
windows拷贝一个中文字符
放在这个目录下面 /usr/local/nginx-1.6.3/html/zabbix/fonts
[root@zabbix1 fonts]# ls
DejaVuSans.ttf_bak simkai.ttf
vim /usr/local/nginx-1.6.3/html/zabbix/include/defines.inc.php
%s/DejaVuSans/simkai/g
打来网页:
http://192.168.32.133/zabbix