设为首页 收藏本站
查看: 1162|回复: 0

[经验分享] Ubuntu14.04下zabbix2.4.5 源码编译安装

[复制链接]

尚未签到

发表于 2015-9-9 13:12:45 | 显示全部楼层 |阅读模式
  安装环境:
  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,登陆后一定要修改。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-111518-1-1.html 上篇帖子: zabbix_windowsagent_cpu 下篇帖子: zabbix_sender自定义监控
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表