1、安装MysqL
1.1、安装MysqL
rpm -ivh http://dev.MysqL.com/get/MysqL-community-release-el7-5.noarch.rpm
yum -y install MysqL-server
vim /etc/my.cnf
[MysqLd]
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
1.3、设置MysqL自动启动并启动MysqL(CENTOS 7):
# systemctl start MysqLd
# systemctl enable MysqLd
1.4、设置MysqL安全选项
MysqL_secure_installation
NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMysqL SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY! InordertologintoMysqLtosecureit,we'llneedthecurrent passwordfortherootuser.Ifyou'vejustinstalledMysqL,and youhaven'tsettherootpasswordyet,thepasswordwillbeblank,soyoushouldjustpressenterhere. Entercurrentpasswordforroot(enterfornone): OK,successfullyusedpassword,movingon... SettingtherootpasswordensuresthatnobodycanlogintotheMysqL rootuserwithouttheproperauthorisation. Setrootpassword?[Y/n]Y Newpassword: Re-enternewpassword: Passwordupdatedsuccessfully! Reloadingprivilegetables.. ...Success! Bydefault,aMysqLinstallationhasananonymoususer,allowinganyone tologintoMysqLwithouthavingtohaveauseraccountcreatedfor them.Thisisintendedonlyfortesting,andtomaketheinstallation goabitsmoother.Youshouldremovethembeforemovingintoa productionenvironment. Removeanonymoususers?[Y/n]Y ...Success! Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This ensuresthatsomeonecannotguessattherootpasswordfromthenetwork. Disallowrootloginremotely?[Y/n]n ...Success! Bydefault,MysqLcomeswithadatabasenamed'test'thatanyonecan access.Thisisalsointendedonlyfortesting,andshouldberemoved beforemovingintoaproductionenvironment. Removetestdatabaseandaccesstoit?[Y/n]Y -Droppingtestdatabase... ERROR1008(HY000)atline1:Can'tdropdatabase'test';databasedoesn'texist ...Failed!Notcritical,keepmoving... -Removingprivilegesontestdatabase... ...Success! Reloadingtheprivilegetableswillensurethatallchangesmadesofar willtakeeffectimmediately. Reloadprivilegetablesnow?[Y/n]Y ...Success! Alldone!Ifyou'vecompletedalloftheabovesteps,yourMysqL installationshouldnowbesecure. ThanksforusingMysqL! Cleaningup...
1.5、创建Zabbix数据库
MysqL -uroot -pkingdee
MysqL> create database zabbix character set utf8 collate utf8_bin;
Query OK,1 row affected (0.04 sec)
MysqL> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
MysqL> FLUSH PRIVILEGES;
MysqL> quit
Bye
2、安装PHP
2.1、安装PHP
先安装第三方组件:
yum -y groupinstall "Development Tools"
yum install libxml2* -y
yum install curl curl-devel
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64
yum install libjpeg-devel
wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
tar zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make install
再下载安装PHP 5.5.38:
wget http://PHP.net/distributions/PHP-5.5.38.tar.gz
tar zxvf PHP-5.5.38.tar.gz
./configure --prefix=/usr/local/PHP-5.5.38 --with-config-file-path=/usr/local/PHP-5.5.38/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-MysqL=MysqLnd --with-MysqLi=MysqLnd --with-MysqL=MysqLnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make
make install
Installingsharedextensions:/usr/local/PHP-5.5.38/lib/PHP/extensions/no-debug-non-zts-20121212/ InstallingPHPCLIbinary:/usr/local/PHP-5.5.38/bin/ InstallingPHPCLImanpage:/usr/local/PHP-5.5.38/PHP/man/man1/ InstallingPHPFPMbinary:/usr/local/PHP-5.5.38/sbin/ InstallingPHPFPMconfig:/usr/local/PHP-5.5.38/etc/ InstallingPHPFPMmanpage:/usr/local/PHP-5.5.38/PHP/man/man8/ InstallingPHPFPMstatuspage:/usr/local/PHP-5.5.38/PHP/PHP/fpm/ InstallingPHPCGIbinary:/usr/local/PHP-5.5.38/bin/ InstallingPHPCGImanpage:/usr/local/PHP-5.5.38/PHP/man/man1/ Installingbuildenvironment:/usr/local/PHP-5.5.38/lib/PHP/build/ Installingheaderfiles:/usr/local/PHP-5.5.38/include/PHP/ Installinghelperprograms:/usr/local/PHP-5.5.38/bin/ program:PHPize program:PHP-config Installingmanpages:/usr/local/PHP-5.5.38/PHP/man/man1/ page:PHPize.1 page:PHP-config.1 InstallingPEARenvironment:/usr/local/PHP-5.5.38/lib/PHP/ [PEAR]Archive_Tar-installed:1.4.0 [PEAR]Console_Getopt-installed:1.4.1 [PEAR]Structures_Graph-installed:1.1.1 [PEAR]XML_Util-installed:1.3.0 [PEAR]PEAR-installed:1.10.1 WrotePEARsystemconfigfileat:/usr/local/PHP-5.5.38/etc/pear.conf Youmaywanttoadd:/usr/local/PHP-5.5.38/lib/PHPtoyourPHP.iniinclude_path /root/PHP-5.5.38/build/shtoolinstall-cext/phar/phar.phar/usr/local/PHP-5.5.38/bin ln-s-fphar.phar/usr/local/PHP-5.5.38/bin/phar InstallingPDOheaders:/usr/local/PHP-5.5.38/include/PHP/ext/pdo/
cp PHP.ini-production /usr/local/PHP-5.5.38/etc/PHP.ini
cp /usr/local/PHP-5.5.38/etc/PHP-fpm.conf.default /usr/local/PHP-5.5.38/etc/PHP-fpm.conf
vim /usr/local/PHP-5.5.38/etc/PHP.ini
post_max_size=16M
max_execution_time=300
max_input_time=300
date.timezone=Asia/Shanghai
always_populate_raw_post_data=1
启动PHP
/usr/local/PHP-5.5.38/sbin/PHP-fpm
3、安装Nginx
yum install pcre*
yum install openssl*
mkdir -p /data/logs/Nginx/
mkdir -p /data/site/centos7/
编译安装:
wget http://Nginx.org/download/Nginx-1.13.3.tar.gz
tar zxvf Nginx-1.13.3.tar.gz
./configure --prefix=/usr/local/Nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre
make install
其它安装方法:(可选)
rpm安装:
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install Nginx
启动,停止
/usr/local/Nginx/sbin/Nginx -s stop
/usr/local/Nginx/sbin/Nginx -s reload
在Nginx.conf的http断中加上如下内容:(注意把原值注释掉)
vim /usr/local/Nginx/conf/Nginx.conf
server {
listen 80;
server_name centos7;
access_log /data/logs/Nginx/centos7.access.log;
index index.PHP index.html index.html;
root /data/site/centos7;
location /
{
try_files $uri $uri/ /index.PHP?$args;
}
location ~ .*\.(PHP)?$
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
建立测试文件
vim /data/site/centos7/info.PHP
<?PHP
PHPinfo();
?>
3. 访问测试
curl http://centos7/info.php test PHP
注:Nginx将会连接回环地址9000端口执行PHP文件,需要使用tcp/ip协议,速度比较慢.建议大家换成使用socket方式连接。将fastcgi_pass 127.0.0.1:9000;改成fastcgi_pass unix:/var/run/PHP5fpm.sock;
1、首行,在配置文件/usr/local/PHP-5.5.38/etc/PHP-fpm.conf文件中找到
listen = 127.0.0.1:9000
修改为:
listen = /var/run/PHP5fpm.sock
listen.mode=0666
然后,重启PHP-fpm
2、接着,配置Nginx
在/usr/local/Nginx/conf/Nginx.conf中找到
fastcgi_pass unix: /var/run/PHP5fpm.sock;
授权然后重启PHP:
chmod 777 /var/run/PHP5fpm.sock
重启Nginx:
注意,不关闭SELINUX可能导致无法启动HTTP服务,参考下面方案关闭:
1、临时关闭(不用重启机器):
setenforce 0 ##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可
5、安装zabbix server
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.6/zabbix-3.2.6.tar.gz
tar -zxvf zabbix-3.2.0.tar.gz
groupadd zabbix
useradd -g zabbix zabbix
yum install MysqL-devel
yum install net-snmp-devel
./configure --prefix=/usr/local/zabbix-3.2/ --enable-server --enable-agent --with-MysqL --with-net-snmp --with-libcurl --with-libxml2
结果如下:
Configuration: DetectedOS:linux-gnu Installpath:/usr/local Compilationarch:linux Compiler:gcc Compilerflags:-g-O2 Library-specificflags: database:-I/usr/include/MysqL-g-m64-fPIC-g-fabi-version=2-fno-omit-frame-pointer-fno-strict-aliasing libXML2:-I/usr/include/libxml2 Net-SNMP:-I/usr/local/include-I/usr/lib64/perl5/CORE-I.-I/usr/include Enableserver:yes Serverdetails: Withdatabase:MysqL WEBMonitoring:cURL NativeJabber:no SNMP:yes IPMI:no SSH:no TLS:no ODBC:no Linkerflags:-L/usr/lib64/MysqL-L/usr/lib64-rdynamic Libraries:-lMysqLclient-lxml2-lnetsnmp-lcurl-lm-ldl-lresolv Enableproxy:no Enableagent:yes Agentdetails: TLS:no Linkerflags:-rdynamic Libraries:-lcurl-lm-ldl-lresolv EnableJavagateway:no LDAPsupport:no IPv6support:no *********************************************************** *Nowrun'makeinstall'* ** *ThankyouforusingZabbix!* *<http://www.zabbix.com>* ***********************************************************
导入表:
MysqL -uzabbix -pzabbix zabbix < database/MysqL/schema.sql
MysqL -uzabbix -pzabbix zabbix < database/MysqL/images.sql
MysqL -uzabbix -pzabbix zabbix < database/MysqL/data.sql
上述导库请务必注意顺序,否则会出现错误:
ERROR 1146 (42S02) at line 2: Table 'zabbix.hosts' doesn't exist
配置 zabbix_server 配置文件:vim /usr/local/zabbix-3.2/etc/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
5.1 拷贝前端文件
mkdir /data/site/centos7/zabbix
cp -rp frontends/PHP/* /data/site/centos7/zabbix
启动 zabbix server
/usr/local/zabbix-3.2/sbin/zabbix_server
启动 Nginx
启动 PHP
/usr/local/PHP-5.5.38/sbin/PHP-fpm
做本机HOTS解析
vim /etc/hosts
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
写zabbix_server服务文件:
vim /lib/systemd/system/zabbix_server.service
[Unit]
Description= zabbix_server
After=network.target
[Service]
Type=forking
ExecStart= /usr/local/zabbix-3.2/sbin/zabbix_server
ExecReload=
ExecStop=
PrivateTmp=true
[Install]
WantedBy=multi-user.target
vim /lib/systemd/system/Nginx.service
Description=Nginx
ExecStart=/usr/local/Nginx/sbin/Nginx
ExecReload=/usr/local/Nginx/sbin/Nginx -r reload
ExecStop=/usr/local/Nginx/sbin/Nginx -s stop
vim /usr/local/PHP-5.5.38/etc/PHP-fpm.conf
pid =/run/PHP-fpm.pid
vim /lib/systemd/system/PHP.service
Description=PHP
ExecStart=/usr/local/PHP-5.5.38/sbin/PHP-fpm
ExecReload=/usr/local/PHP-5.5.38/sbin/PHP-fpm -USR2 `cat ‘run/PHP-fpm.pid’
ExecStop=/usr/local/PHP-5.5.38/sbin/PHP-fpm -INT `cat‘run/PHP-fpm.pid’
完成后,授权、启动服务、设置服务自动启动:
chmod 754 /lib/systemd/system/zabbix_server.service
chmod 754 /lib/systemd/system/Nginx.service
chmod 754 /lib/systemd/system/PHP.service
systemctl start zabbix_server
systemctl start PHP
systemctl start Nginx
systemctl enable PHP
systemctl enable Nginx
systemctl enable zabbix_server
以后如何修改了服务文件,需要使用systemctldaemon-reload 重新加载下服务。
如果少安装了PHP的扩展,以bcmath为例:
先安装
yum install PHP-bcmath
再参考下面方案添加扩展:
http://blog.csdn.net/u014642915/article/details/60868280
PHP连接MysqL报错"No such file or directory"的解决办法
http://www.linuxidc.com/Linux/2012-12/76150.htm
zabbix_server日志(默认位置)
cat /tmp/zabbix_server.log
很多时间权限会导致一些问题(比如Nginx安装向导要向网站中写入配置文件 /data/site/centos7/zabbix/conf/zabbix.conf.PHP),需要对CONF目录授权:
chmod -R 777 /data/site/centos7/zabbix/conf
安装后设置服务器:
7、安装Zabbix Agent
7.1、下载相关的软件包
wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.6-1.el7.x86_64.rpm
7.2、安装Zabbix Agent
yum localinstall zabbix-agent-3.2.6-1.el7.x86_64.rpm
7.3、修改Zabbix Agent配置
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.90.127
7.4、设置Zabbix Agent自动启动并启动Zabbix Agent
systemctl start zabbix-agent
systemctl enable zabbix-agent