重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1. zabbix3.0实验环境
创新互联专注于维西企业网站建设,成都响应式网站建设,成都商城网站开发。维西网站建设公司,为维西等地区提供建站服务。全流程按需网站开发,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务Nginx:1.10.2 Mysql: 5.6.33 PHP:5.6.12 Zabbix:3.0.5 Zabbix_server_IP: 192.168.10.150(基于LNMP) Zabbix_client_IP: 192.168.10.1062. 准备环境LAMP
# 更换下载源 wget -O /etc/yum.repos.d/CentOS-Base.repo yum clean all yum makecache # 清理已经安装的包 rpm -e httpd mysql php yum remove -y httpd php mysql* # 下载NMP源码包 wget -P /tmp http://nginx.org/download/nginx-1.10.2.tar.gz wget -P /tmp http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.33.tar.gz wget -P /tmp http://mirrors.sohu.com/php/php-5.6.12.tar.gz # 下载编译环境的依赖包 yum install -y gcc gcc-c++ ncurses-devel3. 安装mysql
# 创建mysql用户和组,不允许登陆和不创建主目录(如果提示用户存在,修改命令为usermod) groupadd mysql useradd -s /sbin/nologin -g mysql -m mysql # 安装cmake(Mysql从5.5版本./configure配置方式已取消,所以需要安装cmake工具) # tar -zxvf cmake-2.18.2.2.tar.gz -C /opt cd /opt/cmake-2.18.2.2 ./configure make && make install # 使用cmake来编译安装mysql,如果提示缺少某包,安装某包后删除CMakeCache.txt重新运行cmake tar -zxvf /tmp/mysql-5.6.33.tar.gz -C /opt/ cd /opt/mysql-5.6.33 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_USER=mysql \ -DWITH_DEBUG=0 \ -DWITH_SSL=system make && make install # 修改/usr/local/mysql权限 chmod +w /usr/local/mysql chown -R mysql:mysql /usr/local/mysql # 拷贝配置文件 cp ./support-files/my-default.cnf /etc/my.cnf # 初始化数据库 /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql # 拷贝启动文件,设置开机启动 cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig mysqld on /etc/init.d/mysqld start echo 'export PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile # 默认登录不需要密码,需要设置个root密码 mysqladmin -uroot -p password 'Admin123' # 查看数据库里的用户 select user,host from mysql.user; # 删除没必要的用户 drop user root@'::1'; # 赋予账号远程访问的权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '你的密码' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '你的密码' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'zabbix' IDENTIFIED BY '你的密码' WITH GRANT OPTION; # 查看数据库版本 mysql -uroot -p"密码" -e "select version();"4. 安装php
# 下载php依赖包 yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-turbo-devel libpng-devel freetype-devel libmcrypt-devel # 解压php压缩包 tar -zxvf /tmp/php-5.6.12.tar.gz -C /opt cd /opt/php-5.6.12 ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --with-mcrypt \ --enable-ftp \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --without-pear \ --with-gettext \ --disable-fileinfo \ --enable-maintainer-zts make && make install # 修改fpm配置php-fpm.conf.default名称 mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # 复制php.ini配置文件 cp php.ini-production /usr/local/php/etc/php.ini # 复制启动脚本到init.d下 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x !$ # 添加启动项 chkconfig php-fpm on # 按照上面标准,给php创建用户和用户组 groupadd www useradd -s /sbin/nologin -g www -M www # 启动php-fpm service php-fpm start5. 安装nginx
# 安装nginx依赖包,一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩 yum install zlib-devel pcre-devel # 开始安装nginx tar -zxvf /tmp/nginx-1.10.2.tar.gz -C /opt cd /opt/nginx-1.10.2 ./configure --prefix=/usr/local/nginx \ --pid-path=/usr/local/nginx/nginx.pid \ --error-log-path=/usr/local/nginx/error.log \ --http-log-path=/usr/local/nginx/access.log \ --with-http_ssl_module --with-mail \ --with-mail_ssl_module --with-stream \ --with-threads make && make install # 编辑nginx配置文件 vim /usr/local/nginx/conf/nginx.conf 如果nginx无法解析php文件,访问为404.则将此段修改为如下 location ~ \.php$ { root /usr/local/nginx/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } # 编辑nginx启动脚本 vim /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/local/nginx/sbin/nginx" prog=$(basename $nginx) sysconfig="/etc/sysconfig/$prog" lockfile="/var/lock/subsys/nginx" pidfile="/usr/local/nginx/nginx.pid" NGINX_CONF_FILE="/usr/local/nginx/conf/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 chmod +x /etc/init.d/nginx service nginx start chkconfig nginx on # 测试访问php是否正常 vim /usr/local/nginx/www/phpinfo.php curl localhost/phpinfo.php -I6. 编译安装zabbix3.0.5
tar -zxvf /tmp/zabbix-3.0.5.tar.gz -C /opt cd /opt/zabbix-3.0.5 # 创建zabbix进程用户和组 groupadd zabbix useradd -s /sbin/nologin -g zabbix -M zabbix # 下载依赖包 yum install -y net-snmp-devel libssh3-devel # 开始安装zabbix ./configure --prefix=/usr/local/zabbix \ --enable-server --enable-agent \ --with-mysql --with-net-snmp \ --with-libcurl --with-libxml2 \ --with-ssh3 make && make install # 验证安装结果 /usr/local/zabbix/sbin/zabbix_server -V 检查到错误:error while loading shared libraries: libmysqlclient.so.18: ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 /usr/local/zabbix/sbin/zabbix_server -V /usr/local/zabbix/sbin/zabbix_agentd -V netstat -lnp|grep zabbix # 如果server端未启动,检查日志文件/tmp/zabbix_server.log # 修改/usr/local/zabbix/etc/zabbix_server.conf配置文件数据库连接 [root@zabbix_server ~]# egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DBHost=127.0.0.1 DBName=zabbix DBUser=zabbix DBSocket=/var/lib/mysql/mysql.sock DBPassword=Admin123 DBPort=3306 Timeout=4 LogSlowQueries=3000 # 配置zabbix数据库 mysql -uroot -p -e 'create database zabbix;' # 创建数据库授权用户,仅允许192.168.0.0网段登录 mysql -uroot -p -e "grant all privileges on zabbix.* to zabbix@'192.168.%' identified by 'Admin123';" mysql -uroot -p -e "grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'Admin123';" mysql -uroot -p -e "flush privileges;" # 导入zabbix数据库,文件在解压包下的database里 mysql -u zabbix -p -h 192.168.10.150 zabbix < database/mysql/schema.sql mysql -u zabbix -p -h 192.168.10.150 zabbix < database/mysql/p_w_picpaths.sql mysql -u zabbix -p -h 192.168.10.150 zabbix < database/mysql/data.sql # 查看zabbix是否有数据 mysql -u zabbix -p -h 192.168.10.150 -e "show tables from zabbix;" # # 添加启动脚本 cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server # 修改启动脚本 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 # 修改zabbix配置文件(/usr/local/zabbix/etc/zabbix_server.conf) # 添加到开机启动 chmod +x /etc/init.d/zabbix_server chmod +x /etc/init.d/zabbix_agentd chkconfig zabbix_server --level 35 on chkconfig zabbix_agentd --level 35 on # 拷贝网页到nginx目录下 cp -rfp frontends/php/* /usr/local/nginx/zabbix/ -R chown -R root:root /usr/local/nginx/zabbix # 修改nginx配置文件为如下(/usr/local/nginx/nginx.conf) server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { # root zabbix; root /usr/local/nginx/zabbix; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root /usr/local/nginx/zabbix; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } # 重新加载nginx(/etc/init.d/nginx reload)7. zabbix界面安装
界面检查配置出错
错误1:
Minimum required size of PHP post is 16M (configuration option "post_max_size").
Minimum required limit on execution time of PHP scripts is 300 (configuration option "max_execution_time").
Minimum required limit on input parse time for PHP scripts is 300 (configuration option "max_input_time").
Time zone for PHP is not set (configuration parameter "date.timezone").
PHP option "always_populate_raw_post_data" must be set to "-1"
这一步默认的php.ini一般都有错误:
修改/usr/local/php/etc/php.ini即可解决
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = "Asia/Shanghai"
always_populate_raw_post_data = -1
重启php-fpm即可
#/etc/init.d/php-fpm56 restart
错误2:
Install
Cannot create the configuration file.
Details
Unable to create the configuration file.
下载那个页面,然后上传到/usr/local/nginx/zabbix/conf下(网页有提升具体路径)
8. 配置中文支持
左上角倒数第二个图标---language---Chinese(zh_CN)
9. 配置图片中文支持
将/usr/local/nginx/zabbix/include/defines.inc.php
第45行改为
define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name
第93行改为
define('ZBX_FONT_NAME', 'simkai');
1)从windows控制面板->字体>选择一种中文字库例如“楷体”
2)将字体复制到/usr/local/nginx/zabbix/fonts下
3)最后在用户中设置
zabbix网页界面---管理--用户---admin--语言选择中文
注意:
如果有防火墙的话,添加几条语句
iptables -A INPUT -p tcp --dport 80 -d 192.168.10.150 -j ACCEPT iptables -A INPUT -P tcp --dport 10050 -d 192.168.10.150 -j ACCEPT iptables -A INPUT -P tcp --dport 10051 -d 192.168.10.150 -j ACCEPTzabbix就安装完成了
参考zabbix界面安装文档:http://blog.csdn.net/cy309173854/article/details/52608015
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。