先把防火墙和selinux关闭: sytemctl stop firewalld
setenforce 0
1.yum安装依赖:
yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make gd gd2 gd-devel gd2-devel libxslt libxslt-devel libaio libaio-devel
安装zabbix之前需要先搭建 lnmp 或 lamp
一、Nginx
1.下载Nginx源代码:
wget http://nginx.org/download/nginx-1.13.5.tar.gz groupadd www useradd -r -g www www
2.解压安装
tar -zxf nginx-1.13.5.tar.gz cd nginx-1.13.5.tar.gz ./configure --user=www --group=www --prefix=/usr/local/nginx make && make install
3.启动Nginx服务:/usr/local/nginx/sbin/nginx &
cd /usr/local/nginx/sbin/ ./nginx ./nginx -s stop (停止) ./nginx -s quit ./nginx -s reload (平滑重启)
4.访问网页 : http://ip (若是没有关闭防火墙或selinux会报错)
二.mysql
1.安装mysql (下载安装包):
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
2.创建mysql用户和组:
groupadd mysql
useradd -r -g mysql mysql
3.解压安装包并创建date目录 :
tar -zxf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz # mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql cd /usr/local/mysql mkdir data logs echo "" > logs/error.log
4.初始化MySQL: ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --port=3306
(初始化之后会生成一个随机的root账号的密码,如下(如果初始化的时候有指定log-error的路径,则在log-error中查看密码,或者使用 --initialize-insecure 不生成随机密码)
5.授权:
cd /usr/local chown -R mysql:mysql mysql
6.启动MySQL服务:
/usr/local/mysql/bin/mysqld_safe --user=mysql &
7.数据库配
# vim /etc/my.cnf [client] port=3306 socket=/tmp/mysql.sock default-character-set=utf8 [mysql] no-auto-rehash default-character-set=utf8 [mysqld] user = mysql port = 3306 basedir = /usr/local/mysql datadir = /usr/local/mysql/data socket = /tmp/mysql.sock pid-file = mysql3306.pid log-error=/usr/local/mysql/logs/error.log skip_name_resolve = 1 open_files_limit = 65535 back_log = 1024 max_connections = 1500 max_connect_errors = 1000000 table_open_cache = 1024 table_definition_cache = 1024 table_open_cache_instances = 64 thread_stack = 512K external-locking = FALSE max_allowed_packet = 32M sort_buffer_size = 16M join_buffer_size = 16M thread_cache_size = 2250 query_cache_size = 0 query_cache_type = 0 interactive_timeout = 600 wait_timeout = 600 tmp_table_size = 96M max_heap_table_size = 96M ###***slowqueryparameters long_query_time = 0.1 slow_query_log = 1 slow_query_log_file = /usr/local/mysql/logs/slow.log ###***binlogparameters log-bin=mysql-bin binlog_cache_size=4M max_binlog_cache_size=8M max_binlog_size=1024M binlog_format=MIXED expire_logs_days=7 ###***master-slavereplicationparameters server-id=3306 #slave-skip-errors=all [mysqldump] quick max_allowed_packet=32M
8、拷贝服务文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
9、重启MySQL服务
/etc/init.d/mysqld restart
10、配置环境变量
# vi /etc/profile #最后一行添加以下两行: export MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME/bin #保存退出 source /etc/profile
11.修改root密码
https://www.cnblogs.com/jekaysnow/p/8849533.html Centos7.4 修改MySQL5.7 root 密码
12、设置开机自启
chkconfig --add mysqld
chkconfig mysqld on
安装PHP
1、安装依赖库——libmcrypt
wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
ln -sf /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -sf /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ldconfig
2、安装依赖库——mhash
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
https://pan.baidu.com/s/1TDM7z2EbulwJ0OjmAnxDhw 提取码:cb92
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install
ln -sf /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -sf /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -sf /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -sf /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -sf /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ldconfig
3、安装依赖库——mcrypt ( 这依赖我没安装,可以做后面的操作,若是有强迫症,直接yum安装)
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ ./configure make && make install
4、下载PHP安装包
wget -O php-7.1.10.tar.gz http://hk1.php.net/get/php-7.1.10.tar.gz/from/this/mirror
5、解压安装包
tar -zxf php-7.1.10.tar.gz
cd php-7.1.10
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www
--with-mysqli --with-pdo-mysql --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 --enable-opcache --with-xsl
或者
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www
--with-mysqli --with-pdo-mysql --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 --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 --with-libdir=lib64
make && make install
6、修改配置文件
cp php.ini-development /usr/local/php/etc/php.ini
cp ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
7、php-fpm随系统自启动
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
8、启动PHP
/usr/local/php/sbin/php-fpm
9、设置PHP的环境变量
vim /etc/profile
export PHP_HOME=/usr/local/php
export PATH=$PATH:$PHP_HOME/bin
重启生效
source /etc/profile
10、设置开启自启动
cd /etc/init.d/chmod 744 php-fpm chkconfig --add php-fpm chkconfig php-fpm on
四、zabbix
1、下载源码包
wget -O zabbix-3.4.2.tar.gz http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.2/zabbix-3.4.2.tar.gz/download
2、安装依赖库
yum -y install net-snmp-devel libxml2-devel libcurl-deve libevent libevent-devel
3、解压并编译
tar -zxf zabbix-3.4.2.tar.gz
cd zabbix-3.4.2
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
4、安装
make && make install
5、创建zabbix用户和用户组
groupadd zabbix
useradd -r -g zabbix zabbix
cd /usr/local && chown -R zabbix:zabbix zabbix
6、创建zabbix数据库,并导入表结构
# mysql -uroot -p
mysql> create database if not exists zabbix default character set utf8 collate utf8_general_ci;
mysql> use zabbix;
mysql> source /tmp/zabbix-3.4.2/database/mysql/schema.sql;
mysql> source /tmp/zabbix-3.4.2/database/mysql/images.sql;
mysql> source /tmp/zabbix-3.4.2/database/mysql/data.sql;
7、创建日志目录
# cd /usr/local/zabbix
# mkdir logs
# chown zabbix:zabbix logs
8、修改zabbix_server.conf
# vim ./etc/zabbix_server.conf
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/tmp/mysql.sock
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
9、修改zabbix_agent.conf
# vim ./etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.con
10、启动zabbix_server 和 zabiix_agent服务
# /usr/local/zabbix/sbin/zabbix_server
# /usr/local/zabbix/sbin/zabbix_agent
PS:如果再启动的时候报错:error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
解决方法:
# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib/
# ldconfig
然后再次启动服务
11、拷贝WEB应用程序,/data/html为nginx或者Apache的运行PHP程序的目录
# mv /tmp/zabbix-3.4.2/frontends/php/ /data/html/zabbix
# chown -R www:www /data/html/zabbix
12、访问zabbix:http://ip/zabbix/index.php,初始化安装的默认账号:Admin,密码:zabbix
有可能出现的错误(仅供参考):
遇到问题----connect() failed (111: Connection refused) while connecting to upstream解决
https://www.aliyun.com/jiaocheng/124488.html
设置ngnix下的文件在浏览器端直接下载而不是被浏览器默认打开
https://blog.csdn.net/abld99/article/details/51850577
nginx 访问 .php文件变成下载
nginx 访问 .php文件变成下载
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)错误原因
https://blog.csdn.net/leyangjun/article/details/48129751
apache中php的测试文件
https://jingyan.baidu.com/article/86fae346fa692f3c48121a71.html
https://blog.csdn.net/shawearn1027/article/details/51170844
zabbix-server 启动不成功,日志文件中出现"[Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)
"则
方法:mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix' with grant option; Query OK, 0 rows affected, 2 warnings (0.14 sec) mysql> flush privileges; Query OK, 0 rows affected (0.85 sec)
2018/11/21 16:33:38 [error] 41177#0: *16 open() "/usr/local/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.0.188, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.0.145"
location = /favicon.ico {
log_not_found off;
access_log off;
}