无法使用MySQL代理

时间:2018-04-30 14:45:51

标签: fiware fiware-cygnus

我正在尝试设置并了解Cygnus。但我在安装过程中遇到了问题。

我按照以下步骤进行了操作。

  1. 使用Docker安装Cygnus(docker run -d -p 5050:5050 -p 8081:8081     fiware / cygnus-common)
  2. 执行版本命令(curl http://172.17.0.2:8081/v1/version),给出了以下响应 {"成功":"真""版本":" 1.8.0_SNAPSHOT.39b2aa4789c61fa92fe6edc905410f1ddeb33490"}

  3. 使用命令docker exec -it登录Cygnus容器  /斌/庆典

  4. 在中创建名为“agent_mysql.conf”的新文件 “/ opt / apache-flume / conf /”文件夹。

    下面给出的配置详情

  5. cygnus-ngsi.sources = http-source
    cygnus-ngsi.sinks = mysql-sink
    cygnus-ngsi.channels = mysql-channel
    
    cygnus-ngsi.sources.http-source.channels = mysql-channel
    cygnus-ngsi.sources.http-source.type = org.apache.flume.source.http.HTTPSource
    cygnus-ngsi.sources.http-source.port = 5050
    cygnus-ngsi.sources.http-source.handler = com.telefonica.iot.cygnus.handlers.NGSIRestHandler
    cygnus-ngsi.sources.http-source.handler.notification_target = /notify
    cygnus-ngsi.sources.http-source.handler.default_service = def_serv
    cygnus-ngsi.sources.http-source.handler.default_service_path = def_servpath
    cygnus-ngsi.sources.http-source.handler.events_ttl = 2
    cygnus-ngsi.sources.http-source.interceptors = ts gi
    cygnus-ngsi.sources.http-source.interceptors.ts.type = timestamp
    cygnus-ngsi.sources.http-source.interceptors.gi.type = com.telefonica.iot.cygnus.interceptors.NGSIGroupingInterceptor$Builder
    cygnus-ngsi.sources.http-source.interceptors.gi.grouping_rules_conf_file = /Applications/apache-flume-1.4.0-bin/conf/grouping_rules.conf
    
    # =============================================
    # mysql-channel configuration
    # channel type (must not be changed)
    cygnus-ngsi.channels.mysql-channel.type = memory
    # capacity of the channel
    cygnus-ngsi.channels.mysql-channel.capacity = 1000
    # amount of bytes that can be sent per transaction
    cygnus-ngsi.channels.mysql-channel.transactionCapacity = 100
    
    
    
    # channel name from where to read notification events
    cygnus-ngsi.sinks.mysql-sink.channel = mysql-channel
    # sink class, must not be changed
    cygnus-ngsi.sinks.mysql-sink.type = com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
    #com.telefonica.iot.cygnus.sinks.OrionMySQLSink
    # the FQDN/IP address where the MySQL server runs
    cygnus-ngsi.sinks.mysql-sink.mysql_host = localhost
    # the port where the MySQL server listes for incomming connections
    cygnus-ngsi.sinks.mysql-sink.mysql_port = 3306
    # a valid user in the MySQL server
    cygnus-ngsi.sinks.mysql-sink.mysql_username = root
    # password for the user above
    cygnus-ngsi.sinks.mysql-sink.mysql_password = <myPassword>
    # how the attributes are stored, either per row either per column (row, column)
    cygnus-ngsi.sinks.mysql-sink.attr_persistence = row
    
    1. 更改&#34; cygnus-entrypoint.sh&#34;文件在/(根)文件夹中,并通过删除现有文件添加以下命令。 $ {FLUME_HOME} / bin / cygnus-flume-ng agent --conf $ {CYGNUS_CONF_PATH} -f $ {CYGNUS_CONF_PATH} /agent_mysql.conf -n cygnus-ngsi -p $ {CYGNUS_API_PORT} -Dflume.root.logger = $ { CYGNUS_LOG_LEVEL},$ {CYGNUS_LOG_APPENDER} -Dfile.encoding = UTF-8
    2. 退出Docker容器并回到Ubuntu。
    3. 停止并重新启动Docker容器。
    4. 我在日志中遇到以下错误
    5. 请检查并让我知道我做错了什么?感谢您的帮助。

      日志

      n$AgentConfiguration[1016] : Processing:mysql-sink
      time=2018-04-30T14:24:00.807Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=validateConfiguration | msg=org.apache.flume.conf.FlumeConfiguration[140] : Post-validation flume configuration contains configuration for agents: [cygnus-ngsi]
      time=2018-04-30T14:24:00.808Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadChannels | msg=org.apache.flume.node.AbstractConfigurationProvider[150] : Creating channels
      time=2018-04-30T14:24:00.816Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=create | msg=org.apache.flume.channel.DefaultChannelFactory[40] : Creating instance of channel mysql-channel type memory
      time=2018-04-30T14:24:00.825Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadChannels | msg=org.apache.flume.node.AbstractConfigurationProvider[205] : Created channel mysql-channel
      time=2018-04-30T14:24:00.832Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=create | msg=org.apache.flume.source.DefaultSourceFactory[39] : Creating instance of source http-source, type org.apache.flume.source.http.HTTPSource
      time=2018-04-30T14:24:00.836Z | lvl=ERROR | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=configure | msg=org.apache.flume.source.http.HTTPSource[113] : Error while configuring HTTPSource. Exception follows.
      java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.handlers.NGSIRestHandler
              at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:264)
              at org.apache.flume.source.http.HTTPSource.configure(HTTPSource.java:102)
              at org.apache.flume.conf.Configurables.configure(Configurables.java:41)
              at org.apache.flume.node.AbstractConfigurationProvider.loadSources(AbstractConfigurationProvider.java:331)
              at org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:102)
              at org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable.run(PollingPropertiesFileConfigurationProvider.java:140)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
              at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
              at java.lang.Thread.run(Thread.java:748)
      time=2018-04-30T14:24:00.840Z | lvl=ERROR | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadSources | msg=org.apache.flume.node.AbstractConfigurationProvider[366] : Source http-source has been removed due to an error during configuration
      java.lang.RuntimeException: java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.handlers.NGSIRestHandler
              at com.google.common.base.Throwables.propagate(Throwables.java:156)
              at org.apache.flume.source.http.HTTPSource.configure(HTTPSource.java:114)
              at org.apache.flume.conf.Configurables.configure(Configurables.java:41)
              at org.apache.flume.node.AbstractConfigurationProvider.loadSources(AbstractConfigurationProvider.java:331)
              at org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:102)
              at org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable.run(PollingPropertiesFileConfigurationProvider.java:140)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
              at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
              at java.lang.Thread.run(Thread.java:748)
      Caused by: java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.handlers.NGSIRestHandler
              at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:264)
              at org.apache.flume.source.http.HTTPSource.configure(HTTPSource.java:102)
              ... 11 more
      time=2018-04-30T14:24:00.841Z | lvl=INFO | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=create | msg=org.apache.flume.sink.DefaultSinkFactory[40] : Creating instance of sink: mysql-sink, type: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
      time=2018-04-30T14:24:00.842Z | lvl=ERROR | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=run | msg=org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable[142] : Failed to load configuration data. Exception follows.
      org.apache.flume.FlumeException: Unable to load sink type: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink, class: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
              at org.apache.flume.sink.DefaultSinkFactory.getClass(DefaultSinkFactory.java:69)
              at org.apache.flume.sink.DefaultSinkFactory.create(DefaultSinkFactory.java:41)
              at org.apache.flume.node.AbstractConfigurationProvider.loadSinks(AbstractConfigurationProvider.java:415)
              at org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:103)
              at org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable.run(PollingPropertiesFileConfigurationProvider.java:140)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
              at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
              at java.lang.Thread.run(Thread.java:748)
      Caused by: java.lang.ClassNotFoundException: com.telefonica.iot.cygnus.sinks.NGSIMySQLSink
              at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:264)
              at org.apache.flume.sink.DefaultSinkFactory.getClass(DefaultSinkFactory.java:67)
              ... 11 more
      

2 个答案:

答案 0 :(得分:0)

最简单的情况是安装以这种方式连接MYSQL的天鹅座,使用“root”用户连接到天鹅座。

docker run -d --name cygnus_container_name --link mysql_showcases \
  -p 8081:8081 -p 5050:5050 \
  -e CYGNUS_MYSQL_HOST=mysql_host -e CYGNUS_MYSQL_PORT=3306 \
  -e CYGNUS_MYSQL_USER=root -e CYGNUS_MYSQL_PASS=root_password \
  fiware/cygnus-ngsi

如果您决定不使用root用户连接mysql,则需要更改用户和密码并手动创建数据库并授予用户权限,因为cygnus将无法创建数据库另一个用户。

答案 1 :(得分:0)

最后,我能够使用MySQL代理运行Cygnus。我正在使用Ubuntu。 (Linux ubuntucustomfiware 4.4.0-119-generic#143-Ubuntu SMP Mon Apr 2 16:08:24 UTC 2018 x86_64 x86_64 x86_64 GNU / Linux)

我按照以下步骤操作。

  1. 使用MySQL安装在主Ubuntu实例中而不是Docker容器中。
  2. 修改/etc/mysql/mysql.conf.d/mysqld.cnf并更改

      

    bind-address = 127.0.0.1

      

    bind-address = *

    1. 登录数据库并授予root用户所有权限,以便它可以从任何主机连接。
    2.   

      mysql -u root -p   

           

      上授予所有特权。通过'MyPassword'识别''%'@'%';

           

      FLUSH PRIVILEGES;

           

      出口;

      重启MySQL服务器

        

      service mysql restart

      1. 运行Cygnus-ngsi
      2.   

        docker run -d --name cygnus -p 8081:8081 -p 5050:5050 -e   CYGNUS_MYSQL_HOST = PublicIPOfMySQLServer -e CYGNUS_MYSQL_PORT = 3306 -e   CYGNUS_MYSQL_USER = root -e CYGNUS_MYSQL_PASS = MyPassword -e   CYGNUS_LOG_LEVEL ='调试'fiware / cygnus-ngsi

        1. 修改了代理文件,只保留mysql-sink。在以下更改后,停止/启动cygnus docker container。
        2.   

          docker exec -it cygnus / bin / bash

               

          vi /opt/apache-flume/conf/agent.conf

               

          cygnus-ngsi.sinks = mysql-sink

               

          cygnus-ngsi.channels = mysql-channel

               

          出口;

               

          docker stop cygnus

               

          docker start cygnus

          1. 现在发布MQTT数据以修改我的实体,并在MySQL DB中插入4行(每个属性占一行)
          2.   

            mosquitto_pub -h PublicIPOfMySQLServer -u UserName -P Password -t   / swm-reader-service1 / reader-device-id1 / attrs -m'{“tn”:“9888”,“pn”:   “878787”,“ri”:“888888”,“tdt”:“2018年5月10日星期一03:16 AM”}'

            感谢您的支持。

            此致

            克尚