天天看點

CENTOS7+LNMP+zabbix3.2.6安裝配置

1、安裝MySQL

1.1、安裝MySQL

rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

yum -y install mysql-server

1.2、修改MySQL的配置檔案

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 

<code>NOTE: RUNNING </code><code>ALL</code> <code>PARTS </code><code>OF</code> <code>THIS SCRIPT </code><code>IS</code> <code>RECOMMENDED </code><code>FOR</code> <code>ALL</code> <code>MySQL</code>

<code>      </code><code>SERVERS </code><code>IN</code> <code>PRODUCTION USE!  PLEASE </code><code>READ</code> <code>EACH STEP CAREFULLY!</code>

<code>In</code> <code>order</code> <code>to</code> <code>log </code><code>into</code> <code>MySQL </code><code>to</code> <code>secure it, we</code><code>'ll need the current</code>

<code>password for the root user.  If you'</code><code>ve just installed MySQL, </code><code>and</code>

<code>you haven</code><code>'t set the root password yet, the password will be blank,</code>

<code>so you should just press enter here.</code>

<code>Enter current password for root (enter for none): </code>

<code>OK, successfully used password, moving on...</code>

<code>Setting the root password ensures that nobody can log into the MySQL</code>

<code>root user without the proper authorisation.</code>

<code>Set root password? [Y/n] Y</code>

<code>New password: </code>

<code>Re-enter new password: </code>

<code>Password updated successfully!</code>

<code>Reloading privilege tables..</code>

<code> </code><code>... Success!</code>

<code>By default, a MySQL installation has an anonymous user, allowing anyone</code>

<code>to log into MySQL without having to have a user account created for</code>

<code>them.  This is intended only for testing, and to make the installation</code>

<code>go a bit smoother.  You should remove them before moving into a</code>

<code>production environment.</code>

<code>Remove anonymous users? [Y/n] Y</code>

<code>Normally, root should only be allowed to connect from '</code><code>localhost</code><code>'.  This</code>

<code>ensures that someone cannot guess at the root password from the network.</code>

<code>Disallow root login remotely? [Y/n] n</code>

<code>By default, MySQL comes with a database named '</code><code>test</code><code>' that anyone can</code>

<code>access.  This is also intended only for testing, and should be removed</code>

<code>before moving into a production environment.</code>

<code>Remove test database and access to it? [Y/n] Y</code>

<code> </code><code>- Dropping test database...</code>

<code>ERROR 1008 (HY000) at line 1: Can'</code><code>t </code><code>drop</code> <code>database</code> <code>'test'</code><code>; </code><code>database</code> <code>doesn</code><code>'t exist</code>

<code> </code><code>... Failed!  Not critical, keep moving...</code>

<code> </code><code>- Removing privileges on test database...</code>

<code>Reloading the privilege tables will ensure that all changes made so far</code>

<code>will take effect immediately.</code>

<code>Reload privilege tables now? [Y/n] Y</code>

<code>All done!  If you'</code><code>ve completed </code><code>all</code> <code>of</code> <code>the above steps, your MySQL</code>

<code>installation should now be secure.</code>

<code>Thanks </code><code>for</code> <code>using MySQL!</code>

<code>Cleaning up...</code>

1.5、建立Zabbix資料庫

mysql -uroot -pkingdee

mysql&gt; create database zabbix character set utf8 collate utf8_bin;

Query OK, 1 row affected (0.04 sec)

mysql&gt; grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';

Query OK, 0 rows affected (0.01 sec)

mysql&gt; FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

mysql&gt; 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

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

<code>Installing shared extensions:     /usr/local/php-5.5.38/lib/php/extensions/no-debug-non-zts-20121212/</code>

<code>Installing PHP CLI binary:        /usr/local/php-5.5.38/bin/</code>

<code>Installing PHP CLI man page:      /usr/local/php-5.5.38/php/man/man1/</code>

<code>Installing PHP FPM binary:        /usr/local/php-5.5.38/sbin/</code>

<code>Installing PHP FPM config:        /usr/local/php-5.5.38/etc/</code>

<code>Installing PHP FPM man page:      /usr/local/php-5.5.38/php/man/man8/</code>

<code>Installing PHP FPM status page:      /usr/local/php-5.5.38/php/php/fpm/</code>

<code>Installing PHP CGI binary:        /usr/local/php-5.5.38/bin/</code>

<code>Installing PHP CGI man page:      /usr/local/php-5.5.38/php/man/man1/</code>

<code>Installing build environment:     /usr/local/php-5.5.38/lib/php/build/</code>

<code>Installing header files:          /usr/local/php-5.5.38/include/php/</code>

<code>Installing helper programs:       /usr/local/php-5.5.38/bin/</code>

<code>  </code><code>program: phpize</code>

<code>  </code><code>program: php-config</code>

<code>Installing man pages:             /usr/local/php-5.5.38/php/man/man1/</code>

<code>  </code><code>page: phpize.1</code>

<code>  </code><code>page: php-config.1</code>

<code>Installing PEAR environment:      /usr/local/php-5.5.38/lib/php/</code>

<code>[PEAR] Archive_Tar    - installed: 1.4.0</code>

<code>[PEAR] Console_Getopt - installed: 1.4.1</code>

<code>[PEAR] Structures_Graph- installed: 1.1.1</code>

<code>[PEAR] XML_Util       - installed: 1.3.0</code>

<code>[PEAR] PEAR           - installed: 1.10.1</code>

<code>Wrote PEAR system config file at: /usr/local/php-5.5.38/etc/pear.conf</code>

<code>You may want to add: /usr/local/php-5.5.38/lib/php to your php.ini include_path</code>

<code>/root/php-5.5.38/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.5.38/bin</code>

<code>ln -s -f phar.phar /usr/local/php-5.5.38/bin/phar</code>

<code>Installing PDO headers:          /usr/local/php-5.5.38/include/php/ext/pdo/</code>

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

其它安裝方法:(可選)

rpm安裝:

yum install nginx

啟動,停止

/usr/local/nginx/sbin/nginx  

/usr/local/nginx/sbin/nginx  -s stop

重置:當你有修改配置檔案的時候,隻需要reload一下即可

/usr/local/nginx/sbin/nginx -s reload

4、配置nginx php互通

在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

&lt;?php

phpinfo();

?&gt;

3. 通路測試

注: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模式

2、修改配置檔案需要重新開機機器:

修改/etc/selinux/config 檔案

将SELINUX=enforcing改為SELINUX=disabled

重新開機機器即可

5、安裝zabbix server

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

結果如下:

<code>Configuration:</code>

<code>  </code><code>Detected OS:           linux-gnu</code>

<code>  </code><code>Install path:          /usr/local</code>

<code>  </code><code>Compilation arch:      linux</code>

<code>  </code><code>Compiler:              gcc</code>

<code>  </code><code>Compiler flags:         -g -O2</code>

<code>  </code><code>Library-specific flags:</code>

<code>    </code><code>database:               -I/usr/include/mysql -g  -m64 -fPIC  -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing   </code>

<code>    </code><code>libXML2:               -I/usr/include/libxml2</code>

<code>    </code><code>Net-SNMP:               -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include</code>

<code>  </code><code>Enable server:         yes</code>

<code>  </code><code>Server details:</code>

<code>    </code><code>With database:         MySQL</code>

<code>    </code><code>WEB Monitoring:        cURL</code>

<code>    </code><code>Native Jabber:         no</code>

<code>    </code><code>SNMP:                  yes</code>

<code>    </code><code>IPMI:                  no</code>

<code>    </code><code>SSH:                   no</code>

<code>    </code><code>TLS:                   no</code>

<code>    </code><code>ODBC:                  no</code>

<code>    </code><code>Linker flags:             -L/usr/lib64/mysql        -L/usr/lib64      -rdynamic  </code>

<code>    </code><code>Libraries:               -lmysqlclient      -lxml2    -lnetsnmp      -lcurl -lm -ldl  -lresolv </code>

<code>  </code><code>Enable proxy:          no</code>

<code>  </code><code>Enable agent:          yes</code>

<code>  </code><code>Agent details:</code>

<code>    </code><code>Linker flags:              -rdynamic  </code>

<code>    </code><code>Libraries:                 -lcurl -lm -ldl  -lresolv </code>

<code>  </code><code>Enable Java gateway:   no</code>

<code>  </code><code>LDAP support:          no</code>

<code>  </code><code>IPv6 support:          no</code>

<code>***********************************************************</code>

<code>*            Now run 'make install'                       *</code>

<code>*                                                         *</code>

<code>*            Thank you for using Zabbix!                  *</code>

<code>*              &lt;http://www.zabbix.com&gt;                    *</code>

導入表:

mysql -uzabbix -pzabbix zabbix &lt; database/mysql/schema.sql

mysql -uzabbix -pzabbix zabbix &lt; database/mysql/images.sql

mysql -uzabbix -pzabbix zabbix &lt; 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

/usr/local/nginx/sbin/nginx

啟動 PHP

6、其它相關設定及錯誤解決

做本機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

寫Nginx服務檔案:

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

寫PHP服務檔案:

先啟用PHP的PID檔案

vim /usr/local/php-5.5.38/etc/php-fpm.conf

pid =/run/php-fpm.pid

再寫PHP服務檔案

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

以後如何修改了服務檔案,需要使用systemctl daemon-reload  重新加載下服務。

如果少安裝了PHP的擴充,以bcmath為例:

先安裝

yum install php-bcmath

再參考下面方案添加擴充:

<a href="http://blog.csdn.net/u014642915/article/details/60868280" target="_blank">http://blog.csdn.net/u014642915/article/details/60868280</a>

PHP連接配接MySQL報錯"No such file or directory"的解決辦法

<a href="http://www.linuxidc.com/Linux/2012-12/76150.htm" target="_blank">http://www.linuxidc.com/Linux/2012-12/76150.htm</a>

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

安裝後設定伺服器:

<a href="https://s5.51cto.com/wyfs02/M01/9C/5F/wKiom1lvauqgYWkiAAEH7qBGtm8676.png-wh_500x0-wm_3-wmp_4-s_2595669686.png" target="_blank"></a>

<a href="https://s5.51cto.com/wyfs02/M01/9C/5F/wKioL1lvauvjIhG_AAF0uP4qPo4576.png-wh_500x0-wm_3-wmp_4-s_2877951532.png" target="_blank"></a>

<a href="https://s5.51cto.com/wyfs02/M02/9C/5F/wKiom1lvauzjeGa8AAER8jX7rAM233.png-wh_500x0-wm_3-wmp_4-s_2881784358.png" target="_blank"></a>

<a href="https://s3.51cto.com/wyfs02/M00/9C/5F/wKiom1lvauzjP4NwAAECDTYVdSM016.png-wh_500x0-wm_3-wmp_4-s_1264222168.png" target="_blank"></a>

<a href="https://s1.51cto.com/wyfs02/M00/9C/5F/wKioL1lvau3iTTBuAAE3CD-eUDA357.png-wh_500x0-wm_3-wmp_4-s_3739357911.png" target="_blank"></a>

<a href="https://s1.51cto.com/wyfs02/M01/9C/5F/wKiom1lvau6ycXbUAAETEK7_s_g022.png-wh_500x0-wm_3-wmp_4-s_580540025.png" target="_blank"></a>

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

本文轉自 sfih 51CTO部落格,原文連結:http://blog.51cto.com/dayday/1949113

上一篇: python sftp