Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6548168
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: LINUX

2017-06-22 10:25:06

环境:
OS:CentOS 7
nginx:1.12

1.下载
下载地址:

我这里下载的是
nginx-1.12.0.tar.gz

2. 安装所需环境
gcc 安装
yum install gcc-c++

PCRE pcre-devel 安装
yum install -y pcre pcre-devel

zlib 安装
yum install -y zlib zlib-devel

OpenSSL 安装
yum install -y openssl openssl-devel


4. 解压安装
[root@hxl03 opt]# tar -zxvf nginx-1.12.0.tar.gz
[root@hxl03 opt]# mv nginx-1.12.0 nginx112
[root@hxl03 opt]# cd nginx112
我们这里使用的是tcp第四次协议,需要安装stream模块
[root@hxl03 nginx112]# ./configure --with-stream --with-stream_ssl_module
[root@hxl03 nginx112]# make
[root@hxl03 nginx112]# make install

5. 启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
查询nginx进程:
ps aux|grep nginx

6.配置nginx
配置文件如下,我这里使用的是第四层TCP协议,配置的是stream,第七层协议(HTTP),需要配置http模块.
[root@hxl03 conf]# more nginx.conf
[root@hxl03 conf]# more nginx.conf
worker_processes auto;
##error_log logs/error.stream.log info;
events {
    worker_connections  1024;
}
stream {


    log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';


    access_log /usr/local/nginx/logs/tcp-access.log proxy ;
    open_log_file_cache off;


    upstream galera {
        hash $remote_addr consistent;
        server 192.168.56.11:3306;
        server 192.168.56.12:3306;
        server 192.168.56.13:3306;
    }
    server {
        listen 23306;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass galera;
    }
}


7.验证
通过nginx登录集群的方法:
./mysql  -h nginx服务器ip –u用户 –p密码 –P端口号
Host01登录:
[root@host01 bin]# ./mysql -h 192.168.56.13 -uroot -pmysql -P23306
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.0.31-MariaDB-wsrep MariaDB Server, wsrep_25.19.rc3fc46e


Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]>


Host02登录:
[root@host02 bin]# ./mysql -h 192.168.56.13 -uroot -pmysql -P23306
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.0.31-MariaDB-wsrep MariaDB Server, wsrep_25.19.rc3fc46e


Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]>




Host03登录:
[root@hxl03 bin]# ./mysql -h 192.168.56.13 -uroot -pmysql -P23306
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.0.31-MariaDB-wsrep MariaDB Server, wsrep_25.19.rc3fc46e


Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]>


-- The End --


阅读(2375) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~