zabbix,php,nginx,mysql源码安装 神仙操作

2019/03/17 00:15
阅读数 17

→软件包

mkdir /soft/

cd /soft

♦下载以下软件包

nginx-1.14.2.tar.gz  

wget http://nginx.org/download/nginx-1.14.2.tar.gz 

mysql-boost-5.7.25.tar.gz

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz

boost_1_59_0.tar.gz

wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

php-7.1.27.tar.gz  

wget http://cn2.php.net/get/php-7.1.27.tar.gz/from/this/mirror

zabbix-4.0.5.tar.gz

wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.5/zabbix-4.0.5.tar.gz/download 

mv download zabbix-4.0.5.tar.gz

→解压

tar zxvf nginx-1.14.2.tar.gz 
tar zxvf mysql-boost-5.7.25.tar.gz 
tar zxvf boost_1_59_0.tar.gz 
tar zxvf php-7.1.27.tar.gz 
tar zxvf zabbix-4.0.5.tar.gz

→安装nginx

♦安装依赖

yum install -y  pcre* openssl*

 ♦预编译

[root@localhost nginx-1.14.2]# ./configure --prefix=/usr/local/nginx \
> --with-http_ssl_module \
> --with-http_stub_status_module \
> --with-pcre \

 ♦编译安装

[root@localhost nginx-1.14.2]# make && make install

 ♦创建网站目录

[root@localhost nginx-1.14.2]# mkdir /var/www/html -p

→安装PHP

♦安装依赖

[root@localhost nginx-1.14.2]# yum install -y gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel php-mysql php-bcmath

♦ 预编译

[root@localhost php-7.1.27]# ./configure --prefix=/usr/local/php \
> --with-config-file-path=/usr/local/php/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

 ♦编译安装

[root@localhost php-7.1.27]# make && make install

 ♦配置PHP

cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-7.1.27]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 ♦参数配置PHP(zabbix硬性要求)

 vim /usr/local/php/etc/php.ini

max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Shanghai

♦启动php-fpm

[root@localhost php-7.1.27]# mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost php-7.1.27]# /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini

 ♦确定php启动

[root@localhost php-7.1.27]# ss -lnt | grep 9000
LISTEN     0      128    127.0.0.1:9000                     *:*

♦配置nginx配置文件,供测试php,以及zabbix页面配置

[root@localhost php-7.1.27]# cat /usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        access_log  /usr/local/nginx/logs/host.access.log  main;
	root   /var/www/html;
        index  index.htm index.html index.php;
        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;
	}


        #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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 ♦检测一下,并启动

[root@localhost php-7.1.27]# /usr/local/nginx/sbin/nginx -t
[root@localhost php-7.1.27]# /usr/local/nginx/sbin/nginx

 ♦测试php页面

[root@localhost php-7.1.27]# cat /var/www/html/info.php
<?php
phpinfo();
?>

 ♦测试php

[root@localhost php-7.1.27]# curl 127.0.0.1/info.php

 →安装mysql数据库

♦安装前准备

[root@localhost soft]# rpm -qa | grep mariadb

[root@localhost soft]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

[root@localhost soft]# rpm -e --nodeps mariadb-5.5.60-1.el7_5.x86_64

[root@localhost soft]# rpm -e --nodeps mariadb-server-5.5.60-1.el7_5.x86_64

 ♦安装依赖

yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison

 ♦将解压的boost_1_59_0移动

mv boost_1_59_0 /usr/local/boost

 ♦新建MySQL用户和用户组,创建/data/mysql 目录存放mysql数据

[root@localhost soft]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
[root@localhost soft]# mkdir -pv /data/mysql

 ♦预编译

[root@node03 mysql-5.7.17]#
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock\
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BOOST=/usr/local/boost \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \

 ♦编译安装

[root@localhost mysql-5.7.25]# make && make install

♦目录授权

[root@localhost mysql-5.7.25]# chown -R root.mysql /usr/local/mysql/
[root@localhost mysql-5.7.25]# chown -R root.mysql /data/mysql/

 ♦初始化数据库

[root@localhost mysql-5.7.25]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

 ♦配置mysql配置文件

[root@localhost mysql-5.7.25]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
port=3306
socket=/data/mysql/mysql.sock

 ♦启动mysql服务

[root@localhost mysql-5.7.25]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@localhost mysql-5.7.25]# ss -lnt | grep 3306
LISTEN     0      80          :::3306                    :::*

 ♦连接数据库出现问题

[root@localhost mysql-5.7.25]# /usr/local/mysql/bin/mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql/mysql.sock-DENABLED_LOCAL_INFILE=1' (2)

 解决方法

[root@localhost mysql-5.7.25]# ln -s /data/mysql/mysql.sock /data/mysql/mysql.sock-DENABLED_LOCAL_INFILE=1

 ♦改mysql密码

[root@localhost mysql-5.7.25]# /usr/local/mysql/bin/mysql -u root -p
Enter password: 

mysql> alter user 'root'@'localhost' identified by 'WWW.1.com';
mysql> flush privileges;

 ♦设置源码mysql服务开机自启动

[root@localhost mysql-5.7.25]# vim /etc/rc.d/rc.local 
/usr/local/mysql/bin/mysqld_safe --user=mysql &

[root@localhost mysql-5.7.25]# chmod a+x /etc/rc.d/rc.local

 ♦复制mysql服务启动脚本

[root@localhost mysql-5.7.25]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.7.25]# chmod a+x /etc/init.d/mysqld
[root@localhost mysql-5.7.25]# chkconfig --add mysqld
[root@localhost mysql-5.7.25]# chkconfig --level 2345 mysqld on

 ♦测试启动脚本状态

[root@localhost mysql-5.7.25]# service mysqld status
 SUCCESS! MySQL running (20020)
[root@localhost mysql-5.7.25]# service mysqld stop
Shutting down MySQL.2019-03-16T17:02:05.231334Z mysqld_safe mysqld from pid file /data/mysql/localhost.localdomain.pid ended
 SUCCESS! 
[1]+  完成                  /usr/local/mysql/bin/mysqld_safe --user=mysql
[root@localhost mysql-5.7.25]# ss -lnt | grep 3306
[root@localhost mysql-5.7.25]# service mysqld start
Starting MySQL. SUCCESS! 
[root@localhost mysql-5.7.25]# ss -lnt | grep 3306
LISTEN     0      80          :::3306                    :::*

 安装zabbix

♦创建账号,为安全起见禁止登录

[root@localhost mysql]# groupadd zabbix
[root@localhost mysql]# useradd -g zabbix -s /sbin/nologin zabbix

 ♦预编译 

[root@localhost zabbix-4.0.5]# ./configure  --prefix=/usr/local/zabbix \
> --enable-server \
> --with-mysql \
>  --enable-agent

 ♦报错

configure: error: MySQL library not found

 解决

yum install mysql-devel -y

 ♦报错

configure: error: Unable to use libevent (libevent check failed)

 解决

yum install libevent-devel  -y

♦出现下面说明预编译成功

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

 ♦编译安装

make && make install

♦将php脚本复制到html目录下

[root@localhost zabbix-4.0.5]# cp -r frontends/php/* /var/www/html/

 ♦该权限

[root@localhost zabbix-4.0.5]# chmod -R 777 /var/www/html

 ♦登陆数据库并创建zabbix库,跟zabbix用户

mysql> create database zabbix character set utf8;
mysql> flush privileges;

 ♦按顺序导入zabbix自带的数据库

[root@localhost zabbix-4.0.5]# /usr/local/mysql/bin/mysql -uroot -pWWW.1.com zabbix < database/mysql/schema.sql
[root@localhost zabbix-4.0.5]# /usr/local/mysql/bin/mysql -uroot -pWWW.1.com zabbix < database/mysql/images.sql 
[root@localhost zabbix-4.0.5]# /usr/local/mysql/bin/mysql -uroot -pWWW.1.com zabbix < database/mysql/data.sql

 ♦配置zabbix

LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=root
DBPassword=WWW.1.com
DBSocket=/data/mysql/mysql.sock
DBPort=3306
Timeout=4
LogSlowQueries=3000

 ♦zabbix页面配置报错

 

解决方法

cd /soft/php-7.1.27/ext/mysqli
/usr/local/php/bin/phpize
./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make
make install
vim /usr/local/php/etc/php.ini 
extension=mysqli.so

killall php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini

 

[root@localhost bcmath]# /usr/local/php/bin/phize
[root@localhost bcmath]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@localhost bcmath]# make
[root@localhost bcmath]# make install
[root@localhost bcmath]# vim /usr/local/php/etc/php.ini 
extension=bcmath.so

[root@localhost bcmath]# killall php-fpm
[root@localhost bcmath]# /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部