NewRelic with MySQL Plugin

  1.  ## Install npi
  2.  
  3.  Document
  4.  
  5.      https://docs.newrelic.com/docs/plugins/plugins-new-relic/installing-plugins/installing-npi-compatible-plugin
  6.     
  7.  Debian / Ubuntu 32-bit
  8.  
  9.      LICENSE_KEY=<YOUR_KEY> bash -c "$(curl https://download.newrelic.com/npi/release/install-npi-linux-debian-x86.sh)"
  10.     
  11.  ## Install plugin (MySQL)
  12.  
  13.  Enter to npi
  14.  
  15.      cd /path/to/newrelic-npi
  16.     
  17.  Install
  18.  
  19.      ./npi install com.newrelic.plugins.mysql.instance
  20.     
  21.      Are you sure you want to continue? (y/n): y
  22.      Configure the plugin in a text editor before continuing? (y/n): y
  23.     
  24.          {
  25.              "agents": [
  26.                  {
  27.                    "name"    : "Localhost",
  28.                    "host"    : "localhost",
  29.                    "metrics" : "status,newrelic",
  30.                    "user"    : "<USERNAME>", // Create user by plugin/scripts/mysql_user.sql
  31.                    "passwd"  : "<PASSWORD>"  // Or using root if you think safe
  32.                  }
  33.              ]
  34.          }
  35.             
  36.     
  37.      Do you want to set this plugin as a background process? (y/n): y
  38.     
  39.  Check status
  40.  
  41.      /etc/init.d/newrelic_plugin_com.newrelic.plugins.mysql.instance status
  42.     
  43.  Start
  44.  
  45.      /etc/init.d/newrelic_plugin_com.newrelic.plugins.mysql.instance start
  46.     
  47.  Stop
  48.  
  49.      /etc/init.d/newrelic_plugin_com.newrelic.plugins.mysql.instance stop

NewRelic with Server and Laravel

  1.  ## newrelic servers
  2.  
  3.  Install
  4.  
  5.      echo deb http://apt.newrelic.com/debian/ newrelic non-free >> /etc/apt/sources.list.d/newrelic.list
  6.     
  7.      wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add -
  8.     
  9.      apt-get update
  10.      apt-get install newrelic-sysmond
  11.     
  12.      nrsysmond-config --set license_key=12XXXXXXXXXXXXXXXXXXXXXXX9c
  13.     
  14.      /etc/init.d/newrelic-sysmond start
  15.  
  16.  ## newrelic application (PHP)
  17.  
  18.  Make sure server already installed
  19.  
  20.      apt-get install newrelic-php5
  21.     
  22.      newrelic-install install
  23.     
  24.  ## server settings
  25.     
  26.  Nginx
  27.  
  28.      vim /etc/nginx/sites-enabled/default
  29.     
  30.          location ~ \.php$ {
  31.              fastcgi_split_path_info ^(.+\.php)(/.+)$;
  32.              fastcgi_pass unix:/var/run/php5-fpm.sock;
  33.              fastcgi_index index.php;
  34.              include fastcgi_params;
  35.             
  36.              # Add this
  37.              fastcgi_param PHP_VALUE "newrelic.appname=AppName";
  38.             
  39.              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  40.          }
  41.  
  42.  Project
  43.         
  44.      vim /path/to/laravel/project/bootstrap/start.php
  45.     
  46.          if (extension_loaded('newrelic')) {
  47.              newrelic_set_appname('YOUR APP NAME');
  48.          }
  49.         
  50.  Restart
  51.  
  52.      service nginx restart
  53.      service php5-fpm restart
  54.     
  55.  ## Reference
  56.  
  57.  - http://laravelista.com/how-to-install-new-relic-monitoring/

InnoDB: Failing assertion

Problem

InnoDB: Failing assertion: purge_sys->purge_trx_no <= purge_sys->rseg->last_trx_no

  1. ## Enter MySQL
  2. cd /root
  3.  
  4. ## Stop MySQL
  5. service mysql stop
  6.  
  7. ## Add configuration
  8. vim /etc/mysql/my.cnf
  9.  
  10.     [mysqld]
  11.     innodb_force_recovery = 4
  12.     
  13. ## Restart MySQL
  14. service mysql restart
  15.  
  16. ## Dump MySQL Data
  17. mysqldump -u root -p -A > dump.sql
  18.  
  19. ## Check which table is InnoDB
  20. mysql -uroot -p
  21.  
  22.     SELECT table_schema, table_name
  23.     FROM INFORMATION_SCHEMA.TABLES
  24.     WHERE engine = 'innodb';
  25.     
  26. ## Stop the MySQL again
  27. service mysql stop
  28.  
  29. ## Backup MySQL lib
  30. cp -Rf /var/lib/mysql /var/lib/mysql.bak
  31.  
  32. ## Drop the ib file
  33. rm /var/lib/mysql/ib*
  34.  
  35. ## Remove configuration
  36. vim /etc/mysql/my.cnf
  37.  
  38.     [mysqld]
  39.     # innodb_force_recovery = 4
  40.     
  41. ## Restart MySQL again
  42. service mysql restart
  43.  
  44. ## Restore the MySQL Data
  45. mysql -uroot -p < dump.sql
  46.  
  47. ## Try to restart MySQL ensure it is ok
  48. service mysql restart

Reference

– http://darkwizard-coding.blogspot.hk/2014/04/mysql-not-starting-corrupt-innodb.html

Vesta can not add additional FTP

執行 v-add-web-domain-ftp 出現錯誤

  1. /usr/local/vesta/bin/v-add-web-domain-ftp: line 21: /func/main.sh: No such file or directory
  2. /usr/local/vesta/bin/v-add-web-domain-ftp: line 22: /func/domain.sh: No such file or directory
  3. /usr/local/vesta/bin/v-add-web-domain-ftp: line 23: /conf/vesta.conf: No such file or directory
  4. /usr/local/vesta/bin/v-add-web-domain-ftp: line 34: check_args: command not found
  5. /usr/local/vesta/bin/v-add-web-domain-ftp: line 35: validate_format: command not found
  6. /usr/local/vesta/bin/v-add-web-domain-ftp: line 36: is_system_enabled: command not found
  7. /usr/local/vesta/bin/v-add-web-domain-ftp: line 37: is_object_valid: command not found
  8. /usr/local/vesta/bin/v-add-web-domain-ftp: line 38: is_object_unsuspended: command not found
  9. /usr/local/vesta/bin/v-add-web-domain-ftp: line 39: is_object_valid: command not found
  10. /usr/local/vesta/bin/v-add-web-domain-ftp: line 40: is_object_unsuspended: command not found
  11. Error: ftp user _ already exists
  12. /usr/local/vesta/bin/v-add-web-domain-ftp: line 44: log_event: command not found

解決方法 ($VESTA 重新設定為 /usr/local/vesta)

  1. source /etc/profile
  2. cd /usr/local/vesta/bin
  3. ./v-add-web-domain-ftp [username] [domain] [ftp_user] [ftp_password] [relateive_pah]

由 Debian 7 升級到 8

  1. # 換成 root 用戶
  2. su -
  3.  
  4. # 切到下載目錄 (非必要)
  5. cd /root/download
  6.  
  7. # 先更新目前的系統
  8. apt-get update
  9. apt-get upgrade
  10.  
  11. # 取代源的代號,並嘗試再升級系統
  12. sed -i 's/wheezy/jessie/g' /etc/apt/sources.list
  13. apt-get update
  14. apt-get upgrade (如出現 ssh 請移除,否則會重啟 ssh 導致彈出連線)
  15. apt-get dist-upgrade --fix-missing
  16.  
  17. # 如無意外就進行重啟
  18. reboot
  19.  
  20. # 查看版本
  21. lsb_release -a

一道小題

  1.  有一個 Array 如下
  2.  
  3.  $dict = ['a' , 'b' , 'c' , 'd' , 'e' ];
  4.  
  5.  目前有一個變數 $i 控制想輸出的 Array
  6.  
  7.  當 $i = a 時回傳 abcde
  8.  當 $i = b 時回傳 bcdea
  9.  當 $i = d 時回傳 deabc
  10.  
  11.  怎麼寫比較漂亮?
  12.  想知道是否就只能用迴圈跑?

# 想到的解法如下

## 方法一 (直覺.但很多計算)

1. 取出目前 $i 值的位置
2. 取兩種 array (1. 由這位置取到尾, 2.再取 0 到這值置)
3. 最後將這兩種合起來

  1.  <?php
  2.  $dict = ['a' , 'b' , 'c' , 'd' , 'e'];
  3.  
  4.  $position    = array_search('c', $dict);
  5.  $totalSize   = count($dict);
  6.  $findOut     = array_slice($dict, $position, $totalSize);
  7.  $findOutSize = count($findOut);
  8.  
  9.  if ($findOutSize < $totalSize) {
  10.      $appendSize = $totalSize - $findOutSize;
  11.      $appendDict = array_slice($dict, 0, $appendSize);
  12.  }else{
  13.      $appendDict = [];
  14.  }
  15.  
  16.  print_r(array_merge($findOut, $appendDict));

## 方法二 (用遞歸.不算直覺.但快很多)

  1.  <?php
  2.  function genResult(array $dict, $startChar) {
  3.      if ($dict[0] === $startChar) return $dict;
  4.  
  5.      array_push($dict, array_shift($dict));
  6.     
  7.      return genResult($dict, $startChar);
  8.  }
  9.  
  10.  print_r(genResult(['a' , 'b' , 'c' , 'd' , 'e'], 'c'));

Lumen 安裝使用 Elixir

小筆記.直接進入主題

# 進入專案

  1. cd /path/to/lumen/project

# 安裝 gulp 和 laravel elixir package

  1. npm install gulp --save-dev
  2. npm install laravel-elixir --save-dev

# 放置 gulpfile.js

  1. touch gulpfile.js

# 添加以下內容到 gulpfile.js

DownLoad: gulpfile.js
  1.  var elixir = require('laravel-elixir'),
  2.      clean  = require('gulp-clean');
  3.  
  4.  // 設置 詳細可以打開 elixir 的 Config.js 參看
  5.  // elixir.config.sourcemaps = true;
  6.  // elixir.config.publicDir  = "public";
  7.  // elixir.config.assetsDir  = "resources/assets/";
  8.  // elixir.config.bowerDir   = "vendor/bower_components";
  9.  
  10.  // 自定義簡單的 task
  11.  gulp.task('clean', function () {
  12.      return gulp.src([
  13.          'public/foo',
  14.          'public/bar'
  15.      ])
  16.      .pipe(clean({ force: true }));
  17.  });
  18.  
  19.  // 自定義複雜的 task
  20.  elixir.extend("copySomething", function() {
  21.      gulp.task('copySomething', function() {
  22.          return gulp.src('resources/foo/bar/**/*').pipe(gulp.dest('public/foo/bar'));
  23.      });
  24.  
  25.      // 註冊到監控事件裡面,每次改動時指定檔案時都會觸發這個 task
  26.      this.registerWatcher('copySomething', "resources/foo/bar/**/*");
  27.  
  28.      return this.queueTask('copySomething');
  29.  });
  30.  
  31.  elixir(function(mix) {
  32.      mix.styles('app.css').scripts('app.js');
  33.  });

通過 Gandi API 查詢域名

直接記錄測試用的代碼.

package.json

DownLoad: package.json
  1.  {
  2.    "dependencies": {
  3.      "xmlrpc": "^1.3.0"
  4.    }
  5.  }

index.js

DownLoad: index.js
  1.  var xmlrpc = require('xmlrpc');
  2.  var apikey = '____YOUR____API___KEY___';
  3.  var words  = ['cut', 'daily', 'dance', 'danger', 'dark', 'date', 'day', 'dead', 'deal', 'death', 'decide', 'decision', 'declare', 'deep', 'defense', 'degree', 'demand', 'department', 'depend', 'dependent', 'describe', 'desire', 'destroy', 'detail', 'determine', 'develop', 'die', 'difference', 'different', 'difficult', 'difficulty', 'dinner', 'direct', 'direction', 'director', 'discover', 'discuss', 'discussion', '___YOUR___WORDS___ETC___'];
  4.  
  5.  var api = xmlrpc.createSecureClient({
  6.      host: 'rpc.ote.gandi.net', // 'rpc.gandi.net' for production
  7.      port: 443,
  8.      path: '/xmlrpc/'
  9.  });
  10.  
  11.  api.methodCall('version.info', [apikey], function (error, value) {
  12.      console.dir(value);
  13.  });
  14.  
  15.  function run(domain) {
  16.      var callback = function(error, value) {
  17.          console.log(new Date().toLocaleString());
  18.  
  19.          if (value[domain] == 'pending') {
  20.              setTimeout(function() {
  21.                  api.methodCall('domain.available', [apikey, [domain]], callback);
  22.              }, 700);
  23.          }else if (value[domain] == 'error_invalid') {
  24.              console.dir("Err - " + domain);
  25.          }else{
  26.              console.dir(value)
  27.          }
  28.      }
  29.  
  30.      api.methodCall('domain.available', [apikey, [domain]], callback)
  31.  }
  32.  
  33.  // Make sure the word length bigger than 2
  34.  // words = words.filter(function(word) {
  35.  //     return word.length > 2;
  36.  // });
  37.  
  38.  words.some(function(word) {
  39.      run(word + ".xyz");
  40.  });

Golang 創解文件和追加內容

朋友的問題.雖然這玩意只玩過一次.
但還是為這問題再去玩了一下.順道筆記一下

  1.  package main
  2.  
  3.  import (
  4.      "os"
  5.      "io/ioutil"
  6.  )
  7.  
  8.  const (
  9.      FILENAME = "test.txt"
  10.  )
  11.  
  12.  func createFile() {
  13.      file, err := os.Create(FILENAME)
  14.  
  15.      if err != nil {
  16.          panic(err)
  17.      }
  18.  
  19.      defer file.Close()
  20.  }
  21.  
  22.  func appendContent() {
  23.      file, openErr := os.OpenFile(FILENAME, os.O_APPEND | os.O_WRONLY, 0666)
  24.  
  25.      if openErr != nil {
  26.          panic(openErr)
  27.      }
  28.  
  29.      defer file.Close()
  30.  
  31.      _, writeErr := file.WriteString("This is a test content 1\n")
  32.  
  33.      if writeErr != nil {
  34.          panic(writeErr)
  35.      }
  36.  }
  37.  
  38.  func exampleForIOUtilWriteFile() {
  39.      ioutil.WriteFile(FILENAME, []byte("This is a test content 2\n"), os.ModeAppend)
  40.  }
  41.  
  42.  func main() {
  43.  
  44.      _, err := os.Stat(FILENAME)
  45.  
  46.      if os.IsNotExist(err) {
  47.          createFile()
  48.      }
  49.  
  50.      appendContent()
  51.      // exampleForIOUtilWriteFile()
  52.  }

© 2015 不記程式

Theme by Anders NorenUp ↑

Fork me on GitHub