Nginx 的 安装
1.安装PCRE库
[root@hadoop001 ~]# cd /usr/local/
[root@hadoop001 local]# tar -zxvf pcre-8.36.tar.gz
[root@hadoop001 local]# chown -R root.root pcre-8.36
[root@hadoop001 local]# cd pcre-8.36
[root@hadoop001 pcre-8.36]# ./configure
[root@hadoop001 pcre-8.36]# make && make install
2.安装zlib库
[root@hadoop001 local]# cd /usr/local/
[root@hadoop001 local]# tar -zxvf zlib-1.2.8.tar.gz
[root@hadoop001 local]# cd zlib-1.2.8
[root@hadoop001 zlib-1.2.8]# ./configure
[root@hadoop001 zlib-1.2.8]# make && make install
#3.安装ssl -- 不一定要安装,http 和 https 的区别
[root@hadoop001 local]# cd /usr/local/
[root@hadoop001 local]# tar -zxvf openssl-1.0.1j.tar.gz
[root@hadoop001 local]# cd openssl-1.0.1j
[root@hadoop001 openssl-1.0.1j]# ./config
[root@hadoop001 openssl-1.0.1j]# make && make install
4.安装nginx
[root@hadoop001 local]# cd nginx-1.8.0
[root@hadoop001 nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.36 --with-zlib=/usr/local/zlib-1.2.8
[root@hadoop001 nginx-1.8.0]# make && make install
停止httpd服务,启动Nginx:
[root@hadoop001 ~]# /usr/local/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@hadoop001 ~]# service httpd status
httpd (pid 2180) is running...
默认 nginx 的开启端口在 80 ,这里可以停止 http 协议
[root@hadoop001 ~]# service httpd stop
Stopping httpd: [ OK ]
或者:
修改nginx 的端口
在/usr/local/nginx/conf下
vi nginx.conf
server {
listen 888; // 修改端口
server_name 192.168.137.11; // 修改server name
启动:
[root@hadoop001 ~]# /usr/local/nginx/sbin/nginx
重启:
$ /usr/local/nginx/sbin/nginx -s reload
停止:
$ /usr/local/nginx/sbin/nginx -s stop
测试配置文件是否正常:
[root@hadoop001 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@hadoop001 ~]#
强制关闭:
$ pkill nginx
kill -9 $(pgrep -f nginx)
浏览器打开:
http://192.168.137.11:888/
查看日志:
[root@hadoop001 logs]# tail -F access.log
每次刷新浏览器,会查看到多了一条日志记录。
修改nginx.conf,修改以下参数,定义日志生成的格式,重启Nginx
[root@hadoop001 conf]# vi nginx.conf
log_format json '{"@timestamp":"$time_iso8601",
"@version":"1","host":"$server_addr",
"client":"$remote_addr", "size":"$body_bytes_sent,
"responsetime":"$request_time",
"domain":"$host","url":"$uri","status":"$status"}';
access_log logs/access_json.log json;
[root@hadoop001 conf]#/usr/local/nginx/sbin/nginx -s reload
重启后生成一个新的文件
[root@hadoop001 logs]# ll
total 12
-rw-r--r--. 1 root root 0 Dec 2 22:52 access_json.log
现在每次刷新网页就会在这个文件下产生记录。
我们可以用logstash 对这些日志进行收集,然后通过logstash 将日志重新匹配收集到 elasticsearch 中,通过es 进行存储记录和进行搜索。
然后通过可视化的一些组件,比如 kibana 或者 grafana 来进行展示。
从而,形成一个简易的 ELK 功能。
1.安装PCRE库
[root@hadoop001 ~]# cd /usr/local/
[root@hadoop001 local]# tar -zxvf pcre-8.36.tar.gz
[root@hadoop001 local]# chown -R root.root pcre-8.36
[root@hadoop001 local]# cd pcre-8.36
[root@hadoop001 pcre-8.36]# ./configure
[root@hadoop001 pcre-8.36]# make && make install
2.安装zlib库
[root@hadoop001 local]# cd /usr/local/
[root@hadoop001 local]# tar -zxvf zlib-1.2.8.tar.gz
[root@hadoop001 local]# cd zlib-1.2.8
[root@hadoop001 zlib-1.2.8]# ./configure
[root@hadoop001 zlib-1.2.8]# make && make install
#3.安装ssl -- 不一定要安装,http 和 https 的区别
[root@hadoop001 local]# cd /usr/local/
[root@hadoop001 local]# tar -zxvf openssl-1.0.1j.tar.gz
[root@hadoop001 local]# cd openssl-1.0.1j
[root@hadoop001 openssl-1.0.1j]# ./config
[root@hadoop001 openssl-1.0.1j]# make && make install
4.安装nginx
[root@hadoop001 local]# wget http://nginx.org/download/nginx-1.8.0.tar.gz
[root@hadoop001 local]# tar -zxvf nginx-1.8.0.tar.gz[root@hadoop001 local]# cd nginx-1.8.0
[root@hadoop001 nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.36 --with-zlib=/usr/local/zlib-1.2.8
[root@hadoop001 nginx-1.8.0]# make && make install
停止httpd服务,启动Nginx:
[root@hadoop001 ~]# /usr/local/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@hadoop001 ~]# service httpd status
httpd (pid 2180) is running...
默认 nginx 的开启端口在 80 ,这里可以停止 http 协议
[root@hadoop001 ~]# service httpd stop
Stopping httpd: [ OK ]
或者:
修改nginx 的端口
在/usr/local/nginx/conf下
vi nginx.conf
server {
listen 888; // 修改端口
server_name 192.168.137.11; // 修改server name
启动:
[root@hadoop001 ~]# /usr/local/nginx/sbin/nginx
重启:
$ /usr/local/nginx/sbin/nginx -s reload
停止:
$ /usr/local/nginx/sbin/nginx -s stop
测试配置文件是否正常:
[root@hadoop001 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@hadoop001 ~]#
强制关闭:
$ pkill nginx
kill -9 $(pgrep -f nginx)
浏览器打开:
http://192.168.137.11:888/
查看日志:
[root@hadoop001 logs]# tail -F access.log
每次刷新浏览器,会查看到多了一条日志记录。
修改nginx.conf,修改以下参数,定义日志生成的格式,重启Nginx
[root@hadoop001 conf]# vi nginx.conf
log_format json '{"@timestamp":"$time_iso8601",
"@version":"1","host":"$server_addr",
"client":"$remote_addr", "size":"$body_bytes_sent,
"responsetime":"$request_time",
"domain":"$host","url":"$uri","status":"$status"}';
access_log logs/access_json.log json;
[root@hadoop001 conf]#/usr/local/nginx/sbin/nginx -s reload
重启后生成一个新的文件
[root@hadoop001 logs]# ll
total 12
-rw-r--r--. 1 root root 0 Dec 2 22:52 access_json.log
现在每次刷新网页就会在这个文件下产生记录。
我们可以用logstash 对这些日志进行收集,然后通过logstash 将日志重新匹配收集到 elasticsearch 中,通过es 进行存储记录和进行搜索。
然后通过可视化的一些组件,比如 kibana 或者 grafana 来进行展示。
从而,形成一个简易的 ELK 功能。