---
# System prepended metadata

title: NewRelicチートシート

---

# NewRelicチートシート

```shell=

# infra
$ sudo apt update
$ curl -s https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg | sudo apt-key add - && \
echo "license_key: 51137e5bd503aa52b21769afa178e6ccdd49NRAL" | sudo tee -a /etc/newrelic-infra.yml && \
printf "deb [arch=amd64] https://download.newrelic.com/infrastructure_agent/linux/apt bionic main" | sudo tee -a /etc/apt/sources.list.d/newrelic-infra.list && \
sudo apt-get update && \
sudo apt-get install newrelic-infra -y
$ sudo apt update

### mysql
$ sudo mysql -e "CREATE USER 'newrelic'@'localhost' IDENTIFIED BY 'newrelic'";
$ LICENSE_KEY=51137e5bd503aa52b21769afa178e6ccdd49NRAL bash -c "$(curl -sSL https://download.newrelic.com/npi/release/install-npi-linux-redhat-x64.sh)"
$ sudo apt install openjdk-11-jdk
$ cd ~/newrelic-npi
$ ./npi set distro ubuntu
$ sudo ./npi install nrmysql
# 設定ファイルはこん感じで設定、複数サーバの追加はリストに追加でOK
{
  "agents": [
    {
      "name"    : "isucon10",
      "host"    : "127.0.0.1",
      "metrics" : "status,newrelic",
      "user"    : "newrelic",
      "passwd"  : "newrelic"
    }
  ]
}
$ sudo systemctl restart newrelic-infra
# テスト動作
$ sudo ./npi start com.newrelic.plugins.mysql.instance --foreground
# バックグラウンド動作
$ sudo ./npi add-service com.newrelic.plugins.mysql.instance --start
```
