CentOS6离线安装Zabbix4.0

Posted HAOZ未

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS6离线安装Zabbix4.0相关的知识,希望对你有一定的参考价值。

 上一期完成了本地yum源的配置,接下来就是Zabbix依赖的各个模块的安装以及Zabbix服务的安装操作了。总的来说这几期的文章中不单是Zabbix的安装指导,其中还包含了像yum源的本地仓库配置、Apache、mysqlphp服务的安装等等技巧,一文多益呢



、安装Apache

1.检查yum

[root@localhost yum.repos.d]# yum list httpd

2.安装

[root@localhost yum.repos.d]# yum install httpd

3.检查安装

[root@localhost yum.repos.d]# yum list installed |grep httpd[root@localhost yum.repos.d]# httpd -vServerversion: Apache/2.2.15 (Unix)Serverbuilt: Jun 19 2018 15:45:13

4.安装httpd开发工具包

[root@localhost yum.repos.d]# yum install httpd-devel[root@localhost /]# find / -type f -name "apxs"/usr/sbin/apxs

"/usr/sbin/apxs"在源码编译安装php的时候会用到



九、安装PHP(Zabbix的web管理界面要求PHP版本5.4.0以上,但是CentOS6.X系统最高5.3.x,所以需要升级PHP版本

1.安装依赖的库

[root@localhost /]# yum install gcc gcc-c++ php-mcrypt libmcryptlibmcrypt-devel mhash mhash-devel libevent libevent-devel libjpeg-devellibpng-devel freetype-devel openssl openssl-devel readline-devel libxml2-devel bzip2-devel curl curl-devel openldap openldap-devel

2.解压源码包

[root@localhost php]# tar zxvf php-5.6.25.tar.gz

3.配置编译环境

[root@localhost php-5.6.25]# ./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc --enable-inline-optimization--disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd--with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash--with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl--enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets--with-curl --with-zlib --enable-zip --with-bz2 --with-gd --with-freetype-dir--with-jpeg-dir --with-png-dir --with-readline --with-ldap--with-apxs2=/usr/sbin/apxsbuf

我这边安装过程遇到部分报错:

configure:error: mcrypt.h not found. Please reinstall libmcrypt.

解决方案:

[root@localhost php]# wget https://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
[root@localhost php]# cd libmcrypt-2.5.7[root@localhost libmcrypt-2.5.7]# ./configure --prefix=/usr/local[root@localhostlibmcrypt-2.5.7]# make[root@localhostlibmcrypt-2.5.7]# make install
configure:error: Don't know how to define struct flock on this system, set --enable-opcache=no

分析解决步骤:

[root@localhost php-5.6.25]# cat /etc/ld.so.confincludeld.so.conf.d/*.conf[root@localhost php-5.6.25]# vi /etc/ld.so.confincludeld.so.conf.d/*.conf/usr/local/lib/usr/local/lib64[root@localhost php-5.6.25]# ldconfigconfigure:error: Cannot find ldap libraries in /usr/lib.[root@localhost php-5.6.25]# ll /usr/lib64/libldap*lrwxrwxrwx.1 root root 10 Mar 14 19:05 /usr/lib64/libldap-2.4.so.2 -> libldap.solrwxrwxrwx.1 root root 12 Mar 14 19:05 /usr/lib64/libldap_r-2.4.so.2 -> libldap_r.solrwxrwxrwx.1 root root 30 Mar 14 19:05 /usr/lib64/libldap_r.so ->/lib64/libldap_r-2.4.so.2.10.3lrwxrwxrwx.1 root root 28 Mar 14 19:05 /usr/lib64/libldap.so ->/lib64/libldap-2.4.so.2.10.3[root@localhost lib64]# cp -frp /usr/lib64/libldap* /usr/lib/


4.编译:make & make install

[root@localhost php-5.6.25]# make[root@localhost php-5.6.25]# make test[root@localhost php-5.6.25]# make install

 

5.配置PHP服务

php.ini是php运行核心配置文件,php-fpm.conf是php-fpm进程服务的配置文件。

[root@localhost php-5.6.25]# cp php.ini-production /usr/local/php/etc/php.ini[root@localhost php-5.6.25]# cp /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

将php和php-fpm拷贝到/usr/local/bin:

[root@localhost php-5.6.25]# cp /usr/local/php/bin/php /usr/local/bin/php[root@localhost php-5.6.25]# cp /usr/local/php/sbin/php-fpm /usr/local/bin/php-fpm

设置php-fpm开机自动启动,将init.d.php-fpm放在启动里面:

[root@localhost php-5.6.25]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm[root@localhost php-5.6.25]# chmod +x /etc/init.d/php-fpm[root@localhost php-5.6.25]# chkconfig --add php-fpm[root@localhost php-5.6.25]# chkconfig php-fpm on [root@localhost php-5.6.25]# service php-fpm startStartingphp-fpm done[root@localhost php-5.6.25]# ps -ef|grep phproot 30991 1 0 20:53 ? 00:00:00 php-fpm: master process(/usr/local/php/etc/php-fpm.conf) nobody 30992 30991 0 20:53 ? 00:00:00 php-fpm:pool www nobody 30993 30991 0 20:53 ? 00:00:00 php-fpm:pool www root 30995 1256 0 20:53 pts/0 00:00:00 grep php[root@localhostphp-5.6.25]# netstat -nltp|grep 9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 30991/php-fpm 


、关闭防火墙及SELinux

1.查看防火墙状态

[root@localhost ~]# service iptables status

2.关闭防火墙

[root@localhost ~]# service iptables stop

3.禁止防火墙开机启动

[root@localhost ~]# chkconfig iptables off

4.关闭selinux,SELINUX=enforcing改为SELINUX=disabled

[root@localhost ~]# vi /etc/selinux/config # Thisfile controls the state of SELinux on the system.#SELINUX= can take one of these three values:# enforcing - SELinux security policy isenforced.# permissive - SELinux prints warningsinstead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=disabled#SELINUXTYPE= can take one of three two values:# targeted - Targeted processes areprotected,# minimum - Modification of targeted policy.Only selected processes are protected.# mls - Multi Level Security protection.SELINUXTYPE=targeted

5.selinux禁用掉

[root@localhost ~]# setenforce 0

 

十一、配置Apache+PHP

cp/etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak.bak

修改默认端口

[root@localhost conf]# sed -i 's/^Listen 80/Listen 9018/g' /etc/httpd/conf/httpd.conf

修改ServerName为当前IP,例如

[root@localhost conf]# sed -i 's/^#ServerName www.example.com:80/ServerName192.168.1.120:9018/g' /etc/httpd/conf/httpd.conf

添加支持类型

vi /etc/httpd/conf/httpd.confAddType application/x-httpd-php .php

启动apache,开机自启

[root@localhost ~]# service httpd start[root@localhost ~]# chkconfig --add httpd[root@localhost ~]# chkconfig httpd on

验证apache:

[root@localhost ~]# curl http://192.168.1.120:9018

验证php:

[root@localhost html]# cd /var/www/html[root@localhost html]# vi a.php<?phpecho"Hello World!";?>[root@localhost html]# vi phpinfo.php<?phpphpinfo();?>

通过浏览器访问测试:

http://192.168.1.120:9018/phpinfo.php


十二、MySQL安装

1.检查yum

[root@localhost ~]#yum list |grep mysql-community-server

2.安装

[root@localhost ~]#yum install -y mysql-community-server

3.修改配置:这里主要配置端口号、数据目录、socket、pid-file参数,其他部分参数优化仅供参考

[root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak[root@localhost ~]# mkdir -p /data/mysql[root@localhost ~]# vi /etc/my.cnf# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html[client]port=3601socket=/data/mysql/mysql.sockdefault-character-set=utf8
[mysqld]## Remove leading # and set to the amount of RAM for the most important data# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# innodb_buffer_pool_size = 128M## Remove leading # to turn on a very important data integrity option: logging# changes to the binary log between backups.# log_bin## Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2Mport=3601datadir=/data/mysqlsocket=/data/mysql/mysql.sockdefault-storage-engine=INNODBcharacter-set-server=utf8collation-server=utf8_general_cipid-file=/data/mysql/mysql.pid
explicit_defaults_for_timestamp=true #关闭警告[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.skip_name_resolvelog_bin_trust_function_creators = 1event_scheduler=ONgroup_concat_max_len = 200000
lower_case_table_names=1federated
skip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 256Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mmax_connections = 3000max_connect_errors = 10000lower_case_table_names=1character_set_server = utf8innodb_buffer_pool_size = 12G
log_slow_admin_statements=1 #记录那些慢的optimize table,analyze table和alter table语句log_slow_slave_statements=1 #记录由Slave所产生的慢查询slow_launch_time=5long_query_time=5slow_query_log=1 #慢查询开关,用于优化查询语句slow_query_log_file=/var/log/mysql.slow.loglog-queries-not-using-indexes
# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0
# Recommended in standard MySQL setupsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]log-error=/var/log/mysqld.log#pid-file=/var/run/mysqld/mysqld.pidpid-file=/data/mysql/mysql.pid

4.启动

[root@localhost ~]# service mysqld start

5.设置开机自启

[root@localhost ~]# chkconfig --add mysqld[root@localhost ~]# chkconfig mysqld on

 

6.登陆,首次登陆密码为空,直接回车即可

[root@localhost ~]#mysql -uroot -pEnter password:

7.设置root密码

mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');mysql>SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('password'); mysql>use mysql;mysql>select user,host,password from user;+------+-----------------------+-------------------------------------------+|user | host |password |+------+-----------------------+-------------------------------------------+|root | localhost |*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 ||root | localhost.localdomain | ||root | 127.0.0.1 |*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 ||root | ::1 | || | localhost | || | localhost.localdomain | |+------+-----------------------+-------------------------------------------+6rows in set (0.00 sec)

8.添加局域网访问

mysql>update user set host = '%' where user = 'root' and host = 'localhost';Query OK,1 row affected (0.00 sec)Rowsmatched: 1 Changed: 1 Warnings: 0
mysql>flush privileges;Query OK,0 rows affected (0.00 sec)

9.再将localhost的访问添加回来

mysql> INSERTINTO `mysql`.`user`(`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`,`Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`,`Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`,`Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`,`Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`,`Repl_client_priv`, `Create_view_priv`, `Show_view_priv`,`Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`,`Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`,`x509_issuer`, `x509_subject`, `max_questions`, `max_updates`,`max_connections`, `max_user_connections`, `plugin`, `authentication_string`,`password_expired`) select 'localhost', `User`, `Password`, `Select_priv`,`Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`,`Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`,`References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`,`Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`,`Repl_client_priv`, `Create_view_priv`, `Show_view_priv`,`Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`,`Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`,`x509_issuer`, `x509_subject`, `max_questions`, `max_updates`,`max_connections`, `max_user_connections`, `plugin`, `authentication_string`,`password_expired` from `mysql`.`user` where user = 'root' and host = '%';Query OK, 1 rowaffected (0.01 sec)Records: 1 Duplicates: 0 Warnings: 0mysql> flushprivileges;

10.查看端口号

mysql> showglobal variables like 'port';

 

11.重启

[root@localhost ~]#service mysqld restart

 

12.软连接mysql.sock,Zabbix web服务使用的是/var/lib/mysql目录下的sock文件连接的。

[root@localhost ~]#cd /var/lib/mysql[root@localhost mysql]# ln -sf /data/mysql/mysql.sock mysql.sock

13.修改php配置,指定mysql端口,sock文件

[root@localhost ~]#vi /usr/local/php/etc/php.inimysqli.default_port= 3601mysqli.default_socket= /var/lib/mysql/mysql.sock[root@localhost ~]#/etc/init.d/php-fpm restart[root@localhost ~]#service httpd restart

 

看来两期是搞不定了,莫慌,下期就开始安装Zabbix Server啦!


觉得本文有帮助?请分享给更多的人

                                                                                       在看是不是在这个位置

以上是关于CentOS6离线安装Zabbix4.0的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6.5源码安装zabbix4.0

centos7 yum安装zabbix4.0

centos6离线安装docker

zabbix4.0编译安装

zabbix监控,Zabbix4.0安装配置,Linux监控

zabbix4.0.1 安装部署