安装环境:
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,登陆后一定要修改。