第一部分:LNMP环境搭建

一、环境说明:

OS:   centos7.6_x64
nginx:nginx-1.16.0
php:   php-7.1.11
mysql:mysql-5.6.44

zabbix:zabbix-4.0.10

二、安装前准备:

2.1 准备yum源

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# yum -y install epel-release

2.2 安装依赖关系

# yum -y install gcc automake autoconf libtool make cmake gcc-c++ glibc pcre pcre-devel zlib zlib-devel openssl openssl-devel

3.3 创建目录

# mkdir /data
# mkdir /data/package
# mkdir –p /data/server
# mkdir –p /data/webapps
# mkdir –p /data/logs

二、nginx安装

2.1 建立用户

# groupadd -r nginx
# useradd -r -g nginx nginx

2.2 下载安装包

# wget http://nginx.org/download/nginx-1.16.0.tar.gz

2.3 编译安装

# tar –zxvf nginx-1.16.0.tar.gz
# cd nginx-1.16.0/
./configure --prefix=/data/server/nginx-1.16.0 \
--sbin-path=/data/server/nginx-1.16.0/sbin/nginx \
--conf-path=/data/server/nginx-1.16.0/nginx.conf \
--pid-path=/data/server/nginx-1.16.0/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-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-select_module \
--with-poll_module \
--error-log-path=/data/logs/nginx/error.log \
--http-log-path=/data/logs/nginx/access.log \
--with-pcre # make && make install

2.4 建立软链接
方便以后升级,建立软链接

# ln -sv /data/server/nginx-1.16.0 /data/server/nginx

2.5 为nginx提供SysV init启动脚本

新建文件/etc/rc.d/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: /data/server/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /data/server/nginx/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="/data/server/nginx/sbin/nginx"
prog=$(basename $nginx) NGINX_CONF_FILE="/data/server/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
} start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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 $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
sleep 1
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null 2>&1
} case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

2.6 为此脚本赋予执行权限

# chmod +x /etc/rc.d/init.d/nginx

2.7 添加至服务管理列表,并让其开机自动启动:

# chkconfig --add nginx
# chkconfig nginx on

2.8 启动nginx服务

# service nginx start

2.9 配置PATH环境变量

# echo 'export PATH=$PATH://data/server/nginx/sbin/' > /etc/profile.d/nginx.sh
# source /etc/profile.d/nginx.sh

2.10 配置nginx

编辑nginx主配置文件,如下,
# vim /data/server/nginx/nginx.conf
user nginx nginx;
worker_processes 1; #error_log logs/error.log;
#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"'; sendfile on;
tcp_nopush on; keepalive_timeout 65; gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on; tcp_nodelay on; fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k; include /data/server/nginx/conf.d/*.conf; } # 建立目录
# mkdir /data/server/nginx/conf.d/
# mkdir -pv data/logs/nginx/{access,error}

# 建立一个虚拟主机
# vim /data/server/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
index index.html;
root /data/webapps;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /data/logs/nginx/access/default.log main;
error_log /data/logs/nginx/error/default.log; #伪静态规则
include /data/server/nginx/conf.d/rewrite/default.conf; } # 伪静态规则
# vim /data/server/nginx/conf.d/rewrite/default.conf
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
rewrite ^(.*)/data/(.*)\.(htm|php)$ 404.html last;
rewrite ^(.*)/attachment/(.*)\.(htm|php)$ 404.html last;
rewrite ^(.*)/html/(.*)\.(htm|php)$ 404.html last; # 测试页面
# echo 'test nginx' > /data/webapps/index.html # nginx -t
# service nginx restart

三、安装mysql

3.1 先检查是否安装了其它版本的mysql或mariadb

# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

3.2 建立mysql用户及组

# groupadd mysql
# useradd -r -g mysql mysql

3.3 下载并安装mysql

# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

# tar xf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

# mv mysql-5.6.44-linux-glibc2.12-x86_64 /data/server/mysql-5.6.44

# ln -sv /data/server/mysql-5.6.44 /data/server/mysql

# chown -R mysql.mysql /data/server/mysql*

3.4 配置环境变量

# echo "export PATH=$PATH:/data/server/mysql/bin" > /etc/profile.d/mysql.sh
# source /etc/profile.d/mysql.sh

3.5 编辑mysql配置文件,如下:

# vim /etc/my.cnf
[mysqld]
basedir=/data/server/mysql
datadir=/data/mysql
socket=/data/server/mysql/mysql.sock
log-error=/data/logs/mysql/error.log
pid-file=/data/logs/mysql/mysql.pid
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
max_connections=1000
max_connect_errors=10000
thread_cache_size=100
thread_stack=192K
ssl=false
max_allowed_packet=60M
max_heap_table_size=64M
max_length_for_sort_data=8M
net_buffer_length=65536
skip-name-resolve ##ip/localhost
skip-external-locking ##system lock [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [client]
socket=/data/server/mysql/mysql.sock [mysql]
socket=/data/server/mysql/mysql.sock

3.6 准备启动脚本

# cp /data/server/mysql/support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld # 修改basedir和datadir 和/etc/my.cnf保持一致
 …………

  basedir=/data/server/mysql
  datadir=/data/mysql

 …………

# 添加服务
# chkconfig --add mysqld

3.7 初始化mysql

# mysql_install_db --user=mysql --basedir=/data/server/mysql/ --datadir=/data/mysql

3.8 启动mysql并设置开机自启动

# service enable mysqld && service sttart mysqld

mysql> delete from mysql.user where user = '' or host = '::1';

3.8 为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:

输出mysql的man手册至man命令的查找路径:

编辑/etc/man.config,添加如下行即可:
# echo "/data/server/mysql/man" >> /etc/man_db.conf 输出mysql的头文件至系统头文件路径/usr/include: 这可以通过简单的创建链接实现:
# ln -sv /data/server/mysql/include /usr/include/mysql 输出mysql的库文件给系统库查找路径: # echo '/data/server/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 而后让系统重新载入系统库:
# ldconfig

四、安装php

4.1 下载php

# wget http://cn2.php.net/distributions/php-7.1.11.tar.gz

4.2 安装依赖扩展包

# yum -y install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel

4.3 编译安装php

# tar xf php-7.1.11.tar.gz
# cd /root/php-7.1.11
# ./configure --prefix=/data/server/php-7.1.11 \
--with-config-file-path=/data/server/php-7.1.11/etc \
--enable-fpm \
--with-mcrypt \
--enable-mbstring \
--enable-pdo \
--with-curl \
--disable-debug \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysqli=/data/server/mysql/bin/mysql_config \
--with-gd \
--with-jpeg-dir \
--with-freetype-dir \
--with-png-dir \
--enable-calendar \
--with-openssl \
--with-bcmath \
--with-gettext # make && make install
# ln -sv /data/server/php-7.1.11 /data/server/php

4.4 准备php配置文件

# cp php.ini-production /data/server/php/etc/php.ini

4.5 为php-fpm提供配置文件:

# cp /data/server/php/etc/php-fpm.conf.default /data/server/php/etc/php-fpm.conf

4.6 编辑php-fpm的配置文件:

# vim /data/server/php/etc/php-fpm.conf
取消pid的注释
……
[global] pid = run/php-fpm.pid
……
# cp /data/server/php/etc/php-fpm.d/www.conf.default /data/server/php/etc/php-fpm.d/www.conf

4.7 设置环境变量

# echo 'export PATH=$PATH:/data/server/php/sbin' > /etc/profile.d/php-fpm.sh
# echo 'export PATH=/data/server/php/bin:$PATH' >> /etc/profile.d/php-fpm.sh
# source /etc/profile.d/php-fpm.sh

4.8 为php-fpm提供Sysv init脚本,并将其添加至服务列表:

# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on 接下来就可以启动php-fpm了:
# systemctl start php-fpm

五、整合nginx和php5

5.1 编辑nginx.conf,启用如下选项:

# vi /data/server/nginx/nginx.conf
location ~ \.(php|php5)$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

5.2 编辑/data/server/nginx/fastcgi_params,将其内容更改为如下内容:

# cp fastcgi_params{,.bak}
# vim /data/server/nginx/fastcgi_params
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name; 并在所支持的主页面格式中添加php格式的主页,类似如下:
location / {
root html;
index index.php index.html index.htm;
}

5.3 完整的配置文件如下:

# cat /data/server/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
index index.php index.html index.htm;
root /data/webapps;
location ~ \.(php|php5)$ {
root /data/webapps;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /data/logs/nginx/access/default.log main;
error_log /data/logs/nginx/error/default.log;
}

而后重新载入nginx的配置文件:
# service nginx reload

5.4 在/data/webapps新建index.php的测试页面,测试php是否能正常工作及能否连接数据库:

mysql> create user 'test'@'localhost' identified by 'test123';
mysql> flush privileges; 接着就可以通过浏览器访问此测试页面了。
# vim /data/webapps/index.php
<?php
$servername = "localhost";
$username = "test";
$password = "test123"; // 创建连接
$conn = new mysqli($servername, $username, $password); // 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功";
?> <?php
phpinfo();
?>

六、安装php扩展,为php

xcache不支持php7.1了,使用php原生的opcache代替

# vim /data/server/php/etc/php.ini

zend_extension=opcache.so
[opcache]
;开启opcache
opcache.enable=1 ;CLI环境下,PHP启用OPcache
opcache.enable_cli=1 ;OPcache共享内存存储大小,单位MB
opcache.memory_consumption=128 ;PHP使用了一种叫做字符串驻留(string interning)的技术来改善性能。例如,如果你在代码中使用了1000次字符串“foobar”,在PHP内部只会在第一使用这个字符串的时候分配一个不可变的内存区域来存储这个字符串,其他的999次使用都会直接指向这个内存区域。这个选项则会把这个特性提升一个层次——默认情况下这个不可变的内存区域只会存在于单个php-fpm的进程中,如果设置了这个选项,那么它将会在所有的php-fpm进程中共享。在比较大的应用中,这可以非常有效地节约内存,提高应用的性能。
这个选项的值是以兆字节(megabytes)作为单位,如果把它设置为16,则表示16MB,默认是4MB
opcache.interned_strings_buffer=8 ;这个选项用于控制内存中最多可以缓存多少个PHP文件。这个选项必须得设置得足够大,大于你的项目中的所有PHP文件的总和。
设置值取值范围最小值是 200,最大值在 PHP 5.5.6 之前是 100000,PHP 5.5.6 及之后是 1000000。也就是说在200到1000000之间。
opcache.max_accelerated_files=4000 ;设置缓存的过期时间(单位是秒),为0的话每次都要检查
opcache.revalidate_freq=60 ;从字面上理解就是“允许更快速关闭”。它的作用是在单个请求结束时提供一种更快速的机制来调用代码中的析构器,从而加快PHP的响应速度和PHP进程资源的回收速度,这样应用程序可以更快速地响应下一个请求。把它设置为1就可以使用这个机制了。
opcache.fast_shutdown=1 ;如果启用(设置为1),OPcache会在opcache.revalidate_freq设置的秒数去检测文件的时间戳(timestamp)检查脚本是否更新。
如果这个选项被禁用(设置为0),opcache.revalidate_freq会被忽略,PHP文件永远不会被检查。这意味着如果你修改了你的代码,然后你把它更新到服务器上,再在浏览器上请求更新的代码对应的功能,你会看不到更新的效果
强烈建议你在生产环境中设置为0,更新代码后,再平滑重启PHP和web服务器。
opcache.validate_timestamps=0 ;开启Opcache File Cache(实验性), 通过开启这个, 我们可以让Opcache把opcode缓存缓存到外部文件中, 对于一些脚本, 会有很明显的性能提升.
这样PHP就会在/tmp目录下Cache一些Opcode的二进制导出文件, 可以跨PHP生命周期存在.
opcache.file_cache=/tmp

6.2 重新启动php-fpm

# service php-fpm restart

七、如何安装第三方php扩展模块

7.1 安装在源码包中带的扩展模块bcmatch

# cd /tmp/lnmp/php-7.1.11/ext/bcmath/

# /data/server/php/bin/phpize

# ./configure --with-php-config=/data/server/php/bin/php-config

# make && make install

安装完成的模块在下面的目录下
Installing shared extensions: /data/server/php-7.1.11/lib/php/extensions/no-debug-non-zts-20160303/

 # ls -lhrt /data/server/php-7.1.11/lib/php/extensions/no-debug-non-zts-20160303/
  total 5.2M
 -rwxr-xr-x 1 root root 3.3M Jul 16 14:11 opcache.a
 -rwxr-xr-x 1 root root 1.6M Jul 16 14:11 opcache.so
 -rwxr-xr-x 1 root root 357K Jul 16 16:56 bcmath.so
 -rwxr-xr-x 1 root root 52K Jul 16 20:07 gettext.so

7.2 编辑配置文件,启用

# vim /data/server/php-7.1.11/etc/php.ini
[bcmath] extension=bcmath.so

第二部分:zabbix安装

1、安装Zabbix Server

1.1 先安装依赖包

# yum -y install net-snmp gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel curl-devel

1.2 下载软件包

# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.10/zabbix-4.0.10.tar.gz/download

1.3 创建用户

# groupadd --system zabbix
# useradd --system -g zabbix -M -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

1.4 创建数据库

mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';

1.5 导入数据库

# cd database/mysql
# mysql -uzabbix -pzabbix zabbix < schema.sql
# stop here if you are creating database for Zabbix proxy
# mysql -uzabbix -pzabbix zabbix < images.sql
# mysql -uzabbix -pzabbix zabbix < data.sql

1.6 编译安装

# tar -zxvf zabbix-4.0.10.tar.gz
# ./configure --help
./configure --prefix=/data/server/zabbix-4.0.10 \
--enable-server \
--enable-agent \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2 # make install # ln -sv /data/server/zabbix-4.0.10 /data/server/zabbix

1.7 配置环境变量

# echo 'export PATH=$PATH:/data/server/zabbix/sbin' > /etc/profile.d/zabbix.sh
# source /etc/profile.d/zabbix.sh

1.8 编辑zabbix_server.conf

# vim /data/server/zabbix/etc/zabbix_server.conf
DBPassword=zabbix

1.9 安装zabbix
拷贝网页文件至web服务器目录下

# mkdir /data/webapps/zabbix
# cp -ap frontends/php/* /data/webapps/zabbix/

1.10 编辑php配置,以满足zabbix要求

# vim /data/server/php/etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300

1.11 准备zabbix server的启动脚本

# vim /etc/rc.d/init.d/zabbix_server 

#!/bin/sh
#
# zabbix server - this script starts and stops the zabbix server daemon
#
# chkconfig: - 85 15
# description: Zabbix Server is an Monitor server
# processname: zabbix
# config: /data/server/zabbix/etc/zabbix_server.conf
# pidfile: /tmp/zabbix_server.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 zabbix_server="/data/server/zabbix/sbin/zabbix_server"
prog=$(basename $zabbix_server)
ZABBIX_SERVER_CONF_FILE="/data/server/zabbix/etc/zabbix_server.conf"
lockfile=/var/lock/subsys/zabbix_server start() {
[ -x $zabbix_server ] || exit 5
[ -f $ZABBIX_SERVER_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $zabbix_server -c $ZABBIX_SERVER_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} restart() {
stop
sleep 1
start
} rh_status() {
status $prog
} case "$1" in
start)
rh_status && exit 0
$1
;;
stop)
rh_status || exit 0
$1
;;
restart)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac

1.12 启动zabbix_server

加入系统自启动
# chkconfig --add zabbix_server
# chkconfig zabbix_server on
# service zabbix_server start

2、安装zabbix agent

2.1 编译安装agent

# ./configure --prefix=/data/server/zabbix-4.0.10 \
--enable-agent \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2 # make install

2.2 编辑配置文件

# vim /data/server/zabbix/etc/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server

2.3 准备zabbix_agentd启动脚本

# vim /etc/rc.d/init.d/zabbix_agentd 

#!/bin/sh
#
# zabbix agent - this script starts and stops the zabbix agent daemon
#
# chkconfig: - 85 15
# description: Zabbix agentd is an Monitor agent
# processname: zabbix_agentd
# config: /data/server/zabbix/etc/zabbix_agentd.conf
# pidfile: /tmp/zabbix_agentd.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 zabbix_agentd="/data/server/zabbix/sbin/zabbix_agentd"
prog=$(basename $zabbix_agentd)
ZABBIX_AGENTD_CONF_FILE="/data/server/zabbix/etc/zabbix_agentd.conf"
lockfile=/var/lock/subsys/zabbix_agentd start() {
[ -x $zabbix_agentd ] || exit 5
[ -f $ZABBIX_AGENTD_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $zabbix_agentd -c $ZABBIX_AGENTD_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} restart() {
stop
sleep 1
start
} rh_status() {
status $prog
} case "$1" in
start)
rh_status && exit 0
$1
;;
stop)
rh_status || exit 0
$1
;;
restart)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac

2.4 启动zabbix_agent

加入系统自启动
# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentd on
# service zabbix_agentd start

参考链接:https://www.zabbix.com/documentation/4.0/manual/installation/install

zabbix学习(一)——LNMP环境搭建及zabbix安装的更多相关文章

  1. LNMP环境搭建之php安装,wordpress博客搭建

    LNMP环境搭建之php安装,wordpress博客搭建 一.介绍: 1.什么是CGI CGI全称是"通用网关接口"(Common Gateway Interface),HTTP服 ...

  2. LNMP环境搭建:Nginx安装、测试与域名配置

    Nginx作为一款优秀的Web Server软件同时也是一款优秀的负载均衡或前端反向代理.缓存服务软件 2.编译安装Nginx (1)安装Nginx依赖函数库pcre pcre为“perl兼容正则表达 ...

  3. JAVA基础学习——1.1 环境搭建 之jdk安装,环境变量配置 (系统Win10,64bit)

    大学里虽然老师教过JAVA,但我没学.后来工作了,断断续续的也碰到了JAVA的项目,都是拉过来就干的节奏.也没有好好系统的学习一下. 从今天开始系统学习整理一下JAVA,以后再碰到JAVA项目的时候, ...

  4. JAVA基础学习——1.2 环境搭建 之eclipse安装及中文化

    安装好jdk,配置好环境变量以后,下面就可以进行安装eclipse了. 闲话少说,eclipse下载地址:http://www.eclipse.org/downloads/ 不大用关注checksum ...

  5. LNMP环境搭建之php安装

    和LAMP安装PHP方法有差别,需要开启php-fpm服务 下载php cd /usr/local/src/ wget http://cn2.php.net/distributions/php-5.6 ...

  6. lnmp环境搭建后续-php安装

    安装PHP7: 下载# wget http://PHP.net/get/php-7.0.2.tar.gz/from/a/mirror 建议安装之前先看看安装帮助文件INSTALL 解压安装 # tar ...

  7. LNMP环境搭建——MySQL篇

    The world's most popular open source database 1.Install MySQL root@kallen:~# apt-get install mysql-s ...

  8. Hibernate学习之——Hibernate环境搭建

    之前在写关于安卓闹钟的教程,写了一半就没后一半了,其实自己也没做好,在校外实习,校内毕业实习又有任务,只能先放放了,等毕业实习结束之后,在继续安卓闹钟开发之旅,相信这个时间不会很久的.现在毕业实习用到 ...

  9. 一、Android学习第一天——环境搭建(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 一. Android学习第一天——环境搭建 Android 开发环境的搭建 ...

随机推荐

  1. 在FL Studio中制作和优化人声和弦(Vocal Chords)

    人声和弦在Future Bass.Melodic Dubstep等类型的电子音乐中被常用.与一般的和弦相同,其主要起到为主旋律做铺垫的效果,但是人声和弦加入了人声的因素,可以使得和弦更有趣,更有电子音 ...

  2. jenkins 中邮件发送

    1.安装插件 jenkins中安装邮件插件,选择Email Extension 2.开启smtp服务,每个客户端的设置不一样,下图是qq邮箱,仅供参考 3.设置邮件服务 3.1系统设置 3.2 在任务 ...

  3. LeetCode 004 Median of Two Sorted Arrays

    题目描述:Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. F ...

  4. 虚拟机下Ubuntu共享文件夹不能显示的一种解决方法

    原文链接:https://blog.csdn.net/huyangzhilin/article/details/70666937

  5. Happy Tree Friends——团队展示

    这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 团队名称 Happy Tree Friends 这个作业要求在哪里 团队作业第一次 这个作业的目标 团队合作 作业正文 正文 其 ...

  6. oracle 游标相关资料

    游标 概述:游标是系统为用户开设的一个数据缓冲区,存放 SQL 语句的执行结果. 我们可以把游标理解为 PL/SQL 中的结果集,把游标当中一个集合 1:在声明区声明游标 cursor 游标名称 is ...

  7. MyBatis 常见面试题总结

    1.#{}和${}的区别是什么? 注:这道题是面试官面试我同事的. 答: ${}是 Properties 文件中的变量占位符,它可以用于标签属性值和 sql 内部,属于静态文本替换,比如${drive ...

  8. 第15.44节、PyQt输入部件:QAbstractSlider派生类QScrollBar滚动条、QSlider滑动条、QDial刻度盘功能详解

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一.引言 Designer中的输入部件Horizo ...

  9. Python的富比较方法__eq__和__ne__之间的关联关系分析

    Python的富比较方法包括__lt__.__gt__.__le__.__ge__.__eq__和__ne__六个方法,分别表示:小于.大于.小于等于.大于等于.等于和不等于,对应的操作运算符为:&l ...

  10. PyQt(Python+Qt)学习随笔:QTreeWidgetItem项下子项的指示符展示原则childIndicatorPolicy

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 树型部件QTreeWidget中的QTreeWidgetItem项下可以有子项,如果存在子项,则父项 ...