Rootop 服务器运维与web架构

2019-08-21
发表者 Venus
fluentd发送日志到kafka失败 Failed to connect to localhost:9092: Connection refused已关闭评论

fluentd发送日志到kafka失败 Failed to connect to localhost:9092: Connection refused

# td-agent配置的broker地址

[root@abc td-agent]# cat /etc/td-agent/td-agent.conf
略
# 指定kafka地址及端口
brokers 192.168.10.74:9092
略

原本以为这样配置后,fluentd接收到的日志会直接发送到kafka。
(手动启动生产者,消费者,插入内容发现是可以消费的。)

# 但是看fluentd日志发现问题:

[root@abc td-agent]# tail -f /var/log/td-agent/td-agent.log
2019-08-21 14:30:05 +0800 [info]: #0 Fetching cluster metadata from kafka://192.168.10.74:9092
2019-08-21 14:30:05 +0800 [info]: #0 Discovered cluster metadata; nodes: localhost:9092 (node_id=0)

第一步从指定的地址获取集群metadata信息,第二步查找节点,发现地址是localhost:9092,一直没找到这个localhost地址是从哪里配置的。
然后fluentd发送日志到这个地址总是失败。
# 看下昨天排查问题时的日志:

2019-08-20 19:35:31 +0000 [info]: #0 New topics added to target list: test
2019-08-20 19:35:31 +0000 [info]: #0 Fetching cluster metadata from kafka://192.168.10.74:9092
2019-08-20 19:35:31 +0000 [info]: #0 Discovered cluster metadata; nodes: localhost:9092 (node_id=0)
2019-08-20 19:35:31 +0000 [info]: #0 Sending 7 messages to localhost:9092 (node_id=0)
2019-08-20 19:35:31 +0000 [error]: #0 [produce] Failed to connect to localhost:9092: Connection refused - connect(2) for [::1]:9092
2019-08-20 19:35:31 +0000 [error]: #0 Could not connect to broker localhost:9092 (node_id=0): Connection refused - connect(2) for [::1]:9092
2019-08-20 19:35:31 +0000 [warn]: #0 Failed to send all messages; attempting retry 1 of 2 after 1s
2019-08-20 19:35:31.833125548 +0000 fluent.info: {"message":"New topics added to target list: test"}
2019-08-20 19:35:31.833243919 +0000 fluent.info: {"message":"Fetching cluster metadata from kafka://192.168.10.74:9092"}
2019-08-20 19:35:31.836307791 +0000 fluent.info: {"message":"Discovered cluster metadata; nodes: localhost:9092 (node_id=0)"}
2019-08-20 19:35:31.836867642 +0000 fluent.info: {"message":"Sending 7 messages to localhost:9092 (node_id=0)"}

# 觉得这个地址还是需要在kafka配置文件配置,终于找到一个参数。

[root@abc config]# vi /usr/local/kafka/config/server.properties
listeners=PLAINTEXT://192.168.10.74:9092

保存退出。

去zookeeper命令行里删除一个key。

[root@abc bin]# ./zookeeper-shell.sh localhost:2181
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is disabled

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
get /brokers/ids/0 # 查看 
{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://192.168.10.74:9092"],"jmx_port":-1,"host":"192.168.10.74","timestamp":"1566369132247","port":9092,"version":4}
cZxid = 0x2c7
ctime = Wed Aug 21 14:32:12 CST 2019
mZxid = 0x2c7
mtime = Wed Aug 21 14:32:12 CST 2019
pZxid = 0x2c7
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x100055b01b60002
dataLength = 196
numChildren = 0
rmr /brokers/ids/0 # 删除

(我之前endpoints和host的值都是localhost,所以要删除,让kafka重新写入)

# 获取键值
get /brokers/ids/0
# 删除键
rmr /brokers/ids/0

重启zookeeper,重启kafka。

再查看fluentd日志,这次获取的nodes地址对了。

2019-08-21 14:32:38.014038626 +0800 fluent.info: {"message":"Fetching cluster metadata from kafka://192.168.10.74:9092"}
2019-08-21 14:32:38.018237952 +0800 fluent.info: {"message":"Discovered cluster metadata; nodes: 192.168.10.74:9092 (node_id=0)"}

消息终于发送到kafka了,而且开启一个消费者也能看到内容了。

2019-08-13
发表者 Venus
docker swarm 清理非Up状态容器已关闭评论

docker swarm 清理非Up状态容器

[root@m ~]# docker service update ··· # 更新服务

更新服务镜像后,发现旧的容器没有删除,变为Exited(Exited、Shutdown等)状态,查资料也没有说多久会删除。
(放了两个周也没自动清理),可能旧容器会一直存在,有其它用处。
有文章称保留是为了服务回滚操作。反正看着没啥用,就找删除方法。
在docker版本1.13之后可以用命令清理。

# 查看相关清理命令

[root@m ~]# docker system --help

Usage:	docker system COMMAND

Manage Docker

Commands:
  df          Show docker disk usage
  events      Get real time events from the server
  info        Display system-wide information
  prune       Remove unused data

# 清理命令相关参数

[root@m ~]# docker system prune --help

Usage:	docker system prune [OPTIONS]

Remove unused data

Options:
  -a, --all             Remove all unused images not just dangling ones
      --filter filter   Provide filter values (e.g. 'label=<key>=<value>')
  -f, --force           Do not prompt for confirmation
      --volumes         Prune volumes

通过 -a 参数可以清理未使用的镜像,-f 强制删除,不提示确认。

# 清理旧容器及不用的镜像

[root@m ~]# docker system prune -a -f

可以添加到任务计划里定时清理,或者是更新完服务测试后没问题通过脚本批量清理。

2019-08-06
发表者 Venus
jenkins删除历史构建已关闭评论

jenkins删除历史构建

原文:https://www.cnblogs.com/shaobin0604/p/9680621.html
找到 系统管理 – 脚本命令行

def jobName = "Some_Job_Name"
def maxNumber = 64

Jenkins.instance.getItemByFullName(jobName).builds.findAll {
  it.number <= maxNumber
}.each {
  it.delete()
}

jobName 是项目名称
maxNumber 是删除多少个

2019-07-31
发表者 Venus
php提示File not found.已关闭评论

php提示File not found.

server {
    listen       80;
    server_name  localhost;

    access_log  /etc/nginx/conf.d/access.log  main;
    error_log   /etc/nginx/conf.d/error.log;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        root           /home/php;
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}

当nginx匹配到扩展名是php后,交由php-fpm处理,fpm会去 root 定义的目录下执行相应的php脚本。

fastcgi_param 默认配置:

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 
默认是去 /scripts 目录下找对应的请求文件,就会报错提示:File not found.

改为:

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

就会去读 root 参数定义的目录

nginx中多个location段中可以配置不同的 root 参数。

另外一次遇到这个错误是nginx运行用户和php-fpm运行用户不一致导致的,但是在后来搭建测试环境没有再复现这个问题,若遇到修改上面路径不生效,可以看一下两者用户是否一致。

注意浏览器报的错误信息很模糊,需要结合访问日志去排查问题。

注意:nginx是告诉php-fpm请求文件的路径,而不是把代码文件读出来交给php-fpm。

当nginx和php-fpm不在同一台机器(比如docker中),就需要同时建立相同的路径。