Skip to content

Instantly share code, notes, and snippets.

@congto
Last active August 1, 2019 07:33
Show Gist options
  • Save congto/37137d52b818bf95c64e0351f145ef66 to your computer and use it in GitHub Desktop.
Save congto/37137d52b818bf95c64e0351f145ef66 to your computer and use it in GitHub Desktop.
Thực hành với sed

Tải file mẫu về

wget https://gist.githubusercontent.com/congto/735a0dce8f4adc91d5886c12303b05f3/raw/6f5130fe7a83bcb8836476f544094b675b661570/filethuchanh.conf

Hoặc tự tạo file mẫu với nội dung dưới và lưu lại với tên file là filethuchanh.conf

# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
  ## The full HTTP or UDP URL for your InfluxDB instance.
  ##
  ## Multiple URLs can be specified for a single cluster, only ONE of the
  ## urls will be written to each interval.
  # urls = ["unix:///var/run/influxdb.sock"]
  # urls = ["udp://127.0.0.1:8089"]
  # urls = ["http://127.0.0.1:8086"]

  ## The target database for metrics; will be created as needed.
  ## For UDP url endpoint database needs to be configured on server side.
  # database = "telegraf"

  ## The value of this tag will be used to determine the database.  If this
  ## tag is not set the 'database' option is used as the default.
  # database_tag = ""

  ## If true, no CREATE DATABASE queries will be sent.  Set to true when using
  ## Telegraf with a user without permissions to create databases or when the
  ## database already exists.
  # skip_database_creation = false

  ## Name of existing retention policy to write to.  Empty string writes to
  ## the default retention pol
  
  # # Read metrics about network interface usage
# [[inputs.net]]
#   ## By default, telegraf gathers stats from any up interface (excluding loopback)
#   ## Setting interfaces will tell it to gather these explicit interfaces,
#   ## regardless of status.
#   ##
#   # interfaces = ["eth0"]
#   ##
#   ## On linux systems telegraf also collects protocol stats.
#   ## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
#   ##
#   # ignore_protocol_stats = false
#   ##
.  Only takes effect when using HTTP.
  # retention_policy = ""

  ## Write consistency (clusters only), can be: "any", "one", "quorum", "all".
  ## Only takes effect when using HTTP.
  # write_consistency = "any"

  ## Timeout for HTTP messages.
  # timeout = "5s"

  ## HTTP Basic Auth
  # username = "telegraf"
  # password = "metricsmetricsmetricsmetrics"

# # Read metrics about network interface usage
# [[inputs.net]]
#   ## By default, telegraf gathers stats from any up interface (excluding loopback)
#   ## Setting interfaces will tell it to gather these explicit interfaces,
#   ## regardless of status.
#   ##
#   # interfaces = ["eth0"]
#   ##
#   ## On linux systems telegraf also collects protocol stats.
#   ## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
#   ##
#   # ignore_protocol_stats = false
#   ##

Bài tập

Sửa dụng lệnh sed để thực hiện các yêu cầu sau:

  1. Thay thế dòng # urls = ["http://127.0.0.1:8086"] bằng dòng mới urls = ["http://192.168.69.69:8086"]
  2. Thay dòng # [[inputs.net]] bằng dòng [[inputs.net]]
  3. Thay dòng # username = "telegraf" bằng dòng username = "nguoidung@hocchudong.com"
  4. Thay dòng # password = "metricsmetricsmetricsmetrics bằng dòng password = "Matkhau@ok$#

Lời giải