Zabbix 服务端安装与配置LNMP(学习笔记一)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 1、关闭SELINUX和防火墙:sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/selinux/configgetenforce 0service iptables stopservice ...

1、关闭SELINUX和防火墙:

sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/selinux/config

getenforce 0

service iptables stop

service firewalld stop

2、安装相关组件:

yum -y install wget libtool expat-devel pcre-devel zlib-devel openssl openssl-devel pcre

yum -y install gcc gcc-c++ glibc automake autoconf libtool make

yum -y install libmcrypt-devel mhash-devel libxslt-devel 

yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel 

yum -y install zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel 

yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel 

yum -y install krb5 krb5-devel libidn libidn-devel openssl openssl-devel

3、安装pcre:

cd /usr/local/src

wget http://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz/download -O pcre-8.39.tar.gz --no-check-certificate

tar -zxvf pcre-8.39.tar.gz

cd pcre-8.39

./configure

make && make install

4、安装zlib:

cd /usr/local/src

  wget http://zlib.net/zlib-1.2.11.tar.gz

  tar -zxvf zlib-1.2.11.tar.gz

  cd zlib-1.2.11

  ./configure

  make && make install

5、安装openssl:

cd /usr/local/src

wget https://www.openssl.org/source/openssl-1.1.0b.tar.gz

tar -zxvf openssl-1.1.0b.tar.gz

cd openssl-1.1.0b

./config

make && make install

6、安装nginx:

cd /usr/local/src

wget http://nginx.org/download/nginx-1.10.2.tar.gz

tar -zxvf nginx-1.10.2.tar.gz

cd nginx-1.10.2

groupadd -r nginx

useradd -r -g nginx nginx

./configure \

  --prefix=/usr/local/nginx \

  --sbin-path=/usr/local/nginx/sbin/nginx \

  --conf-path=/usr/local/nginx/nginx.conf \

  --pid-path=/usr/local/nginx/nginx.pid \

  --user=nginx \

  --group=nginx \

  --with-http_ssl_module \

  --with-http_flv_module \

--with-http_mp4_module  \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/tmp/nginx/client/ \

--http-proxy-temp-path=/var/tmp/nginx/proxy/ \

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

--http-scgi-temp-path=/var/tmp/nginx/scgi \

--with-pcre=/usr/local/src/pcre-8.39 \

--with-zlib=/usr/local/src/zlib-1.2.11 \

--with-openssl=/usr/local/src/openssl-1.1.0b \

;

make && make install

netstat -ano|grep 80

mkdir -p /var/tmp/nginx/client

/usr/local/nginx/sbin/nginx

7、搭建MYSQL:

useradd -s /sbin/nologin -M mysql

cd /usr/local/src

wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql-5.7.17

ln -s /usr/local/mysql-5.7.17 /usr/local/mysql

8、配置MYSQL:

#创建数据库文件目录

mkdir -p /data/mysql

chown -R mysql.mysql /data/

#配置启动脚本文件,并加入系统服务,自启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

#配置mysql配置文件

cat > /etc/my.cnf << EOF

[client]

port = 3306

socket = /tmp/mysql.sock

default-character-set = utf8

[mysqld]

port = 3306

socket = /tmp/mysql.sock

basedir = /usr/local/mysql

datadir = /data/mysql

pid-file = /data/mysql/mysql.pid

user = mysql

bind-address = 0.0.0.0

server-id = 1

init-connect = 'SET NAMES utf8'

character-set-server = utf8

#skip-name-resolve

#skip-networking

back_log = 300

max_connections = 1000

max_connect_errors = 6000

open_files_limit = 65535

table_open_cache = 128

max_allowed_packet = 4M

binlog_cache_size = 1M

max_heap_table_size = 8M

tmp_table_size = 16M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 8M

key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1

query_cache_size = 8M

query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin

binlog_format = mixed

expire_logs_days = 30

log_error = /data/mysql/mysql-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /data/mysql/mysql-slow.log

performance_schema = 0

explicit_defaults_for_timestamp

#lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB

#default-storage-engine = MyISAM

innodb_file_per_table = 1

innodb_open_files = 500

innodb_buffer_pool_size = 64M

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_thread_concurrency = 0

innodb_purge_threads = 1

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 2M

innodb_log_file_size = 32M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M

myisam_sort_buffer_size = 8M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

interactive_timeout = 28800

wait_timeout = 28800

[mysqldump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

EOF

9、初始化MYSQL数据库:

#初始化数据库:

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

#配合环境变量

echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile

. /etc/profile

#启动MySQL服务

/etc/init.d/mysqld start

#修改root密码

mysql -uroot

#mysql -uroot -pk8008.com -e "use mysql;update user set authentication_string=password('新密码') where user='root';"

update mysql.user set authentication_string=password("123456") where user='root';

10、PHP安装:

#安装第三方yum源

wget http://www.atomicorp.com/installers/atomic

sh ./atomic

#使用yum命令安装

yum -y install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel gd-devel curl-devel openssl-devel libxslt-devel* php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2 libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel

wget http://mirrors.sohu.com/php/php-5.6.30.tar.gz

tar zxvf php-5.6.30.tar.gz

cd php-5.6.30

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--enable-inline-optimization \

--enable-fpm \

--with-mysql=/usr/local/mysql \

--with-mysqli=/usr/local/mysql/bin/mysql_config \

--with-pdo-mysql=/usr/local/mysql \

--with-gettext \

--enable-mbstring \

--with-iconv=/usr/local/libiconv \

--with-mcrypt \

--with-mhash \

--enable-bcmath \

--enable-soap \

--with-libxml-dir \

--enable-sockets \

--with-curl \

--with-zlib \

--enable-zip \

--with-bz2 \

--with-gd \

--with-freetype-dir \

--with-jpeg-dir \

--with-iconv \

--with-png-dir


make

make install

cp php.ini-production /usr/local/php/etc/php.ini

11、安装zabbix:

#安装ZABBIX

wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz

yum install net-snmp-devel

tar zxvf zabbix-3.0.4.tar.gz

cd zabbix-3.0.4

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

make && make install

echo $?

12、导入zabbix数据库:

mysql

create database zabbix

grant all on zabbix.* to 'zabbixuser'@'localhost' identified by '123456';

flush privileges;

use zabbix;

source /usr/local/src/zabbix-3.0.4/database/mysql/schema.sql

source /usr/local/src/zabbix-3.0.4/database/mysql/images.sql

source /usr/local/src/zabbix-3.0.4/database/mysql/data.sql

13、修改zabbix配置文件:

#配置zabbix_server配置文件修改如下:

LogFile=/usr/local/zabbix/logs/zabbix_server.log

DBHost=127.0.0.1

DBName=zabbix

DBUser=zabbixuser

DBPassword=123456 #zabbixuser的密码

LogSlowQueries=3000

cp misc/init.d/fedora/core/* /etc/init.d/

chmod +x /etc/init.d/zabbix_server

chmod +x /etc/init.d/zabbix_agentd

sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_agentd

sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_server

useradd -s /sbin/nologin -M zabbix

mkdir /usr/local/zabbix/logs

chown -R zabbix.zabbix /usr/local/zabbix/

/etc/init.d/zabbix_agentd start

/etc/init.d/zabbix_server start

#######配置脚本存放目录

mkdir /usr/local/zabbix/alertscripts

vi /usr/local/zabbix/etc/zabbix_server.conf

AlertScriptsPath=/usr/local/zabbix/alertscripts

14、修改PHP.INI:

sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#g' /usr/local/php/etc/php.ini

sed -i 's#post_max_size = 8M#post_max_size = 16M#g' /usr/local/php/etc/php.ini

sed -i 's#max_execution_time = 30#max_execution_time = 300#g' /usr/local/php/etc/php.ini

sed -i 's#max_input_time = 60#max_input_time = 300#g' /usr/local/php/etc/php.ini

sed -i 's#;always_populate_raw_post_data = -1#always_populate_raw_post_data = -1#g' /usr/local/php/etc/php.ini

15、配置nginx:

user www www;

pid /usr/local/nginx/nginx.pid;

worker_processes auto;

worker_rlimit_nofile 100000;

events

        {

                use epoll;

                multi_accept on;

                worker_connections 51200;

        }

http {

server_tokens off;

sendfile on;

tcp_nopush on;

tcp_nodelay on;

access_log off;

error_log /var/log/nginx/error.log crit;

keepalive_timeout 10;

client_header_timeout 10;

client_body_timeout 10;

reset_timedout_connection on;

send_timeout 10;

limit_conn_zone $binary_remote_addr zone=addr:5m;

limit_conn addr 100;

include /usr/local/nginx/mime.types;

default_type text/html;

charset UTF-8;

gzip on;

gzip_disable "msie6";

gzip_proxied any;

gzip_min_length 1000;

gzip_comp_level 6;

gzip_disable <93>MSIE [1-6].(?!.*SV1)<94>;

open_file_cache max=100000 inactive=20s;

open_file_cache_valid 30s;

open_file_cache_min_uses 2;

open_file_cache_errors on;

include /usr/local/nginx/conf.d/*.conf;

server

{

    listen 9001;

    location ~ /nginx_status {

    stub_status on;

    access_log off;

  allow all;

    #deny all;

    }

}

server

{

    listen 80;

    server_name zabbix.com;

    server_name 你的本机IP;

    root /usr/local/nginx/html;

    location /zabbix{

        index    index.php index.html index.htm;

}

    location ~ \.php$ {

        include fastcgi_params;

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;

    }

}

}

}

16、启动登录:

cd /usr/local/php/etc

cp php-fpm.conf.default php-fpm.conf

/usr/local/php/sbin/php-fpm

cd /usr/local/src/zabbix-3.0.4

cp -ra frontends/php/ /usr/local/nginx/html/zabbix

chown -R www.www  /usr/local/nginx/html/zabbix

#zabbix登录

账号:admin

密码:zabbix

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
6月前
|
监控 关系型数据库 MySQL
Alibaba Cloud Linux基础入门(1)——配置zabbix
该文档是关于在Alibaba Cloud Linux上配置Zabbix的教程。首先,通过添加Zabbix仓库并安装相关软件包(如zabbix-server,web前端和agent)。然后,安装并启动MySQL数据库,执行`mysql_secure_installation`进行配置。接着,创建名为zabbix的数据库和用户,并导入Zabbix默认数据。最后,设置Zabbix服务开机自启动,并通过浏览器访问http://服务器IP/zabbix完成Web端配置,使用Admin/zabbix登录。
|
1月前
|
NoSQL 应用服务中间件 PHP
LNMP一键安装
LNMP一键安装
|
2月前
|
监控 Windows
Zabbix 5.0 LTS配置中文支持并解决字符乱码问题
文章介绍了如何在Zabbix 5.0 LTS中配置中文支持并解决字符乱码问题,包括在用户设置中选择中文语言和替换默认字体为Windows字体的步骤。
347 4
|
2月前
|
监控 前端开发 数据库连接
Zabbix 5.0 LTS的web界面安装及修改zabbix web管理员的默认密码
这篇文章是关于如何安装Zabbix 5.0 LTS的web界面以及如何修改Zabbix web管理员默认密码的教程。
169 1
|
6月前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
74 1
|
3月前
|
监控 关系型数据库 MySQL
如何在 Ubuntu 16.04 上安装和配置 Zabbix 以安全监控远程服务器
如何在 Ubuntu 16.04 上安装和配置 Zabbix 以安全监控远程服务器
36 0
|
3月前
|
关系型数据库 Linux 应用服务中间件
linux服务器下LNMP安装与配置方法
通过遵循上述步骤,你已经在Linux服务器上成功配置了LNMP环境。这只是初步设置,根据你的实际需求,可能需要进一步的调整与优化。记得经常检查每个组件的默认配置文件,并根据需要进行调整以优化性能和安全性。
72 0
|
4月前
|
域名解析 缓存 监控
安装zabbix时报错Could not resolve host: mirrors.huaweicloud.com;Unknown error解决办法
安装zabbix时报错Could not resolve host: mirrors.huaweicloud.com;Unknown error解决办法
|
4月前
|
监控 关系型数据库 应用服务中间件
Linux zabbix监控 软件的安装
Linux zabbix监控 软件的安装
|
6月前
|
监控 关系型数据库 MySQL
红帽 9 zabbix 安装流程
Zabbix是一个监控软件,用于确保企业服务架构的安全运行,具备灵活的告警机制和分布式监控能力。它由Server、Web页面、数据库、Proxy和Agent五个组件组成。工作流程中,Agent在目标设备上收集数据,Server存储和处理数据,Web页面提供监控信息。Zabbix支持主动和被动两种数据收集模式。在Redhat 9.2环境下,安装包括关闭防火墙、设置SELinux、安装MySQL、创建Zabbix数据库和用户、安装Zabbix RPM包及配置服务。完成安装后,通过Web界面使用Admin账号和预设密码zabbix登录。
163 2

推荐镜像

更多