一、安装常用依赖包
(本文永久地址:http://woymk.blog.51cto.com/10000269/1953012)
yum install -y make gcc gcc-c++ perl zlib-devel libaio libpng libpng-devel libjpeg-devel pcre-devel
yum install -y libXpm-devel openssl openssl-devel libxml2-devel bzip2-devel.x86_64 libjpeg-turbo-devel
yum install -y freetype freetype-devel libtool cmake ncurses-devel bison re2c curl-devel wget
rpm -ivh "http://mirrors.sohu.com/fedora-epel/epel-release-latest-6.noarch.rpm"
yum install -y libmcrypt-devel re2c
二、安装nginx
cd /usr/local/src
wget http://mirrors.sohu.com/nginx/nginx-1.12.0.tar.gz
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module --with-http_ssl_module
make && make install
vi /etc/init.d/nginx
把下面nginx启动脚本保存为 /etc/init.d/nginx,
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx" prog=$(basename $nginx) sysconfig="/etc/sysconfig/$prog" lockfile="/var/lock/subsys/nginx" pidfile="/var/run/${prog}.pid" NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f $sysconfig ] && . $sysconfig start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc -p $pidfile $prog retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest_q || return 6 stop start } reload() { configtest_q || return 6 echo -n $"Reloading $prog: " killproc -p $pidfile $prog -HUP echo } configtest() { $nginx -t -c $NGINX_CONF_FILE } configtest_q() { $nginx -t -q -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } # Upgrade the binary with no downtime. upgrade() { local oldbin_pidfile="${pidfile}.oldbin" configtest_q || return 6 echo -n $"Upgrading $prog: " killproc -p $pidfile $prog -USR2 retval=$? sleep 1 if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then killproc -p $oldbin_pidfile $prog -QUIT success $"$prog online upgrade" echo return 0 else failure $"$prog online upgrade" echo return 1 fi } # Tell nginx to reopen logs reopen_logs() { configtest_q || return 6 echo -n $"Reopening $prog logs: " killproc -p $pidfile $prog -USR1 retval=$? echo return $retval } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest|reopen_logs) $1 ;; force-reload|upgrade) rh_status_q || exit 7 upgrade ;; reload) rh_status_q || exit 7 $1 ;; status|status_q) rh_$1 ;; condrestart|try-restart) rh_status_q || exit 7 restart ;; *) echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}" exit 2 esac
找到下面三行
nginx="/usr/sbin/nginx"
pidfile="/var/run/${prog}.pid"
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
修改为:
nginx="/usr/local/nginx/sbin/nginx"
pidfile="/usr/local/nginx/logs/${prog}.pid"
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
保存后,执行
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
/etc/init.d/nginx start
三、安装php
安装依赖包
yum install openldap openldap-devel -y
cd /usr/local/src
wget http://mirrors.sohu.com/php/php-5.5.38.tar.gz
tar zxvf php-5.5.38.tar.gz
cd php-5.5.38
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-dir --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath --with-ldap
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/src/php-5.5.38/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp -v /usr/local/php/etc/{php-fpm.conf.default,php-fpm.conf}
vi /usr/local/php/etc/php.ini
找到
;date.timezone =
改为
date.timezone = Asia/Chongqing
保存后,执行
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
四、安装mysql
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36.tar.gz
tar zxvf mysql-5.6.36.tar.gz
cd mysql-5.6.36
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
建立mysql用户
useradd -s /sbin/nologin mysql
初始化数据库,创建系统自带的数据库和表
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vi /etc/init.d/mysqld
修改datadir
basedir=/usr/local/mysql
datadir=/data/mysql
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
mysql修改密码
/usr/local/mysql/bin/mysqladmin -uroot password "1234"
PATH=$PATH:/usr/local/mysql/bin
创建zabbix数据库、用户名和密码:
mysql -uroot -p -e "create database zabbix default charset utf8"
mysql -uroot -p -e "grant all privileges on zabbix.* to zabbix@'localhost' identified by '1234'";
五、安装zabbix server
官网下载地址 https://www.zabbix.com/download
这里下载的是: zabbix-3.0.10.tar
安装依赖包
yum install net-snmp-devel -y
cd /usr/local/src
tar zxvf zabbix-3.0.10.tar.gz
cd zabbix-3.0.10
./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make && make install
创建zabbix用户
useradd -s /sbin/nologin zabbix
导入3个sql文件:(密码这里设的是1234)
mysql -uroot -p zabbix < database/mysql/schema.sql
mysql -uroot -p zabbix < database/mysql/p_w_picpaths.sql
mysql -uroot -p zabbix < database/mysql/data.sql
创建网站目录
mkdir /data/web/zabbix -p
将前端文件拷贝到web目录下
cp -rp frontends/php/* /data/web/zabbix/
配置nginx
cd /usr/local/nginx/conf/
mkdir extra
cd extra/
vi zabbix.conf
加入以下内容,并保存:
server { listen 80; server_name www.test.com; access_log /data/logs/zabbix/www.test.com.access.log main; index index.html index.php index.html; root /data/web/zabbix; location /{ try_files $uri $uri/ /index.php?$args; } location ~ ^(.+.php)(.*)$ { fastcgi_split_path_info ^(.+.php)(.*)$; include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param PATH_INFO $fastcgi_path_info; } }
cd ..
vi nginx
加入以下内容,并保存:
user nobody; worker_processes 1; #error_log logs/error.log warning; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; 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"'; access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; include extra/*.conf; }
vi /usr/local/zabbix/etc/zabbix_server.conf
修改如下内容并保存:
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=1234
启动zabbix server
/usr/local/zabbix/sbin/zabbix_server
如果显示:
error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
执行:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
查看启动的服务和端口号
netstat -lnpt
六、网页安装zabbix
浏览器访问
http://ip/
(如果无法显示,检查iptables和selinx是否关闭)
点下一步
vi /usr/local/php/etc/php.ini
跟据错误提示修改,保存后重启php-fpm
service php-fpm restart
继续点下一步
填写完点下一步
填写完点下一步
继续点下一步
这里的报错是因为nginx用户没有写入权限,按图中提示手动修改或者直接修改目录权限:
cd /data/web/zabbix/
chown nobody:nobody conf
改完后刷新网页
点Finish,接下来登陆zabbix,默认管理员账号为 admin:zabbix
登陆后的画面:
设置中文显示:
点右上角的小图标,显示如下网页,在Language项修改
点Update
已经显示成中文了。
zabbix出现中文乱码的解决方法
zabbix在显示中文时有的地方会出现乱码,这是因为没有中文字库的缘故,只需把windows里的字库复制过去即可。windows的字体文件c:\windows\fonts目录下,比如华文仿宋字体文件名是STFANGSO.ttf。
把字体文件上传到系统里(可以使用PSFTP、FileZilla等文件传输工具上传),将原字体文件直接覆盖
mv STFANGSO.ttf /data/web/zabbix/fonts/DejaVuSans.ttf
或者
把字体文件复制/data/web/zabbix/fonts/目录
vi /data/web/zabbix/include/defines.inc.php
找到
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans');
修改成上传的中文字体文件名。