共计 7284 个字符,预计需要花费 19 分钟才能阅读完成。
安装环境:
Ubuntu14.04 LTS MySQL 5.6 php-fpm nginx 1.8.0
第一部分,php+mysql+nginx 组件安装
1、系统更新
sudo apt-get update && sudo apt-get upgrade
2、安装 php-fpm
zabbix 的 web 前端是用 php 写成的,需要 php 来运行
sudo apt-get install php-fpm (当然也可以源码编译 php)
3、源码编译 mysql5.6
1. 安装环境:Mysql-5.6.23.tar.gz
2. 安装必备的工具
sudo apt-get install make bison g++ build-essential libncurses5-dev cmake
3. 添加组合用户 设置安装目录权限
sudo groupadd mysql
sudo useradd –g mysql mysql –s /bin/false #创建用户 mysql 并加入到 mysql 组,不允许 mysql 用户直接登录系统
sudo mkdir –p /usr/local/mysql #创建 Mysql 安装目录
sudo mkdir -p /usr/local/mysql/data
sudo mkdir -p /usr/local/mysql/log
sudo chown -R mysql:mysql /usr/local/mysql/data
sudo chown -R mysql:mysql /usr/local/mysql
4. 编译安装 mysql
4.1 获取源码包
cd /usr/local/src
sudo wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.23.tar.gz
4.2 解压 mysql 源码包
sudo tar –zxvf mysql-5.6.23.tar.gz
5. 编译配置
cd mysql-5.6.23
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_USER=mysql -DWITH_DEBUG=0
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
sudo make -j4 #- j 数字 表示以多核心运行
sudo make install
6. 相关配置
6.1 配置开机启动
sudo chmod +w /usr/local/mysql
sudo cp ./support-files/my-default.cnf /etc/my.cnf
sudo cp ./support-files/mysql.server /etc/init.d/mysqld
sudo chmod 755 /etc/init.d/mysqld
6.2 常用命令软连接,设置环境变量
sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
6.3 初始化数据库
sudo /usr/local/mysql/scripts/mysql_install_db –defaults-file=/etc/my.cnf –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –user=mysql
7. 启动 mysql 服务试一试
sudo /etc/init.d/mysqld start
8. 启动成功后创建 root 用户的密码
mysqladmin -u root password
9. 成功后使用一下
mysql -uroot -p
4、安装 nginx
sudo apt-get install nginx (当然也可以源码编译 nginx)
nginx 配置文件设置
在 /etc/ngnix/site-available/default:
复制代码
# You may add here your
# server {
# …
# }
# statements for each of your virtual hosts to this file
##
# You should look at the following URL’s in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
server {
listen 80 default_server;
# listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/zabbix/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name zabbix.example.com.cn;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# index index.html index.htm;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
#
# root html;
# index index.html index.htm;
#
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
#
# ssl_session_timeout 5m;
#
# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers “HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES”;
# ssl_prefer_server_ciphers on;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
example@ubuntu:/etc/nginx/sites-available$
第二部分,Zabbix 编译安装和 Web 前面配置
1、zabbix 编译安装的依赖包
# 安装编译套件
sudo apt-get install build-essential
# 安装 php 前端需要的包
sudo apt-get install libmysqlclient15-dev php5-gd php5-mysql
# 安装 zabbix 需要的包,snmp\curl\ssl\fping
sudo apt-get install snmp libsnmp-dev snmpd libcurl4-openssl-dev fping
2、创建 zabbix 用户和 zabbix 组
sudo groupadd zabbix
sudo useradd -r -s /usr/sbin/nologin -g zabbix zabbix
3、下载 zabbix 源码包,并解压
wget http://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix/zabbix_2.4.5.orig.tar.gz
sudo tar -zxvf zabbix_2.4.5.orig.tar.gz -C /usr/local/src/
cd /usr/local/src/zabbix-2.4.5/database
4、数据库初始化
mysql -uroot -p -e”create database zabbix;”
mysql -uroot -p -e”grant all privileges on zabbix.* to zabbix@localhost identified by ‘zabbix’;”
mysql -D zabbix -uzabbix -pzabbix < schema.sql
mysql -D zabbix -uzabbix -pzabbix < image.sql
mysql -D zabbix -uzabbix -pzabbix < data.sql
5、zabbix 编译安装
cd ..
./configure –prefix=/usr/local/zabbix –enable-server –enable-agent –enable-proxy –with-mysql –with-net-snmp –with-libcurl
sudo make &&sudo make install
#–with-net-snmp 是启用 SNMP 协议
#–with-libcurl 是监控 web 网站用的
#–enable-server 只可在服务端上使用
# 其它还有 IPMI 等,参阅./configure –help
ps:报错 configure: error: MySQL library not found 缺 libmysqlclient15-dev
6、设置 zabbix 配置文件目录
sudo mkdir /etc/zabbix
cp conf/zabbix_* /etc/zabbix/
sudo chown -R zabbix:zabbix /etc/zabbix/
7、修改配置文件
sudo vim /et/zabbix/zabbix_server.conf
DBUser DBPassword 这两个关键字,替换为前面 mysqlDB 中设置的用户和密码
8、设置 zabbix 开机启动
sudo cp misc/init.d/debian/zabbix-server /etc/init.d
sudo cp misc/init.d/debian/zabbix-agent /etc/init.d
cd !$
sudo chmod 755 zabbix-*
sudo update-rc.d zabbix-server defaults
sudo update-rc.d zabbix-agent defaults
9、zabbix web 界面安装设置
sudo mkdir /usr/share/nginx/html/zabbix/
cd /usr/src/zabbix-2.4.5/frontends/
sudo cp -r php/* /usr/share/nginx/html/zabbix
在浏览器中打开 http://zabbix.example.com.cn/zabbix 开始 web 界面的 setup
1) zabbix 会检查 php 的设置
标红的是默认需要修改的参数,php 的设置文件为 /etc/php5/cgi/php.ini
sudo restart php-fpm restart
2) zabbix 会检查 mysql 的设置
zabbix_server.conf 与 my.cnf 中有关 mysql 的 pid sock 等文件的配置路径要一致
my.cnf socket = /tmp/mysql.sock
zabbix_server.conf DBSocket = /tmp/mysql.sock
ps:如果还是报错 /var/run/mysqld/mysqld.sock 连接不上
也许 sudo ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock 是一种解决办法
3) 最后,要手动将生成的设置文件 zabbix.conf.php 上传到 /usr/share/nginx/html/zabbix/conf,zabbix 默认用户是 admin, 密码是 zabbix, 登陆后一定要修改。
一些 Zabbix 相关教程集合 :
安装部署分布式监控系统 Zabbix 2.06 http://www.linuxidc.com/Linux/2013-07/86942.htm
《安装部署分布式监控系统 Zabbix 2.06》http://www.linuxidc.com/Linux/2013-07/86942.htm
CentOS 6.3 下 Zabbix 安装部署 http://www.linuxidc.com/Linux/2013-05/83786.htm
Zabbix 分布式监控系统实践 http://www.linuxidc.com/Linux/2013-06/85758.htm
CentOS 6.3 下 Zabbix 监控 apache server-status http://www.linuxidc.com/Linux/2013-05/84740.htm
CentOS 6.3 下 Zabbix 监控 MySQL 数据库参数 http://www.linuxidc.com/Linux/2013-05/84800.htm
64 位 CentOS 6.2 下安装 Zabbix 2.0.6 http://www.linuxidc.com/Linux/2014-11/109541.htm
ZABBIX 的详细介绍 :请点这里
ZABBIX 的下载地址 :请点这里
更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-05/117657.htm