2016-06-26

wordpress on docker

wordpress on docker:
  1. environment:
    1. ubuntu 15.10
  2. install docker:
    1. apt-get update
    2. apt-get install docker.io
  3. pull docker:
    1. docker pull mysql
    2. docker pull wordpress
  4. docker run…
    1. 將資料目錄對應到 host server 目錄
  5. start mysql docker:
    docker run --name wordpressdb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=wordpress -e MYSQL_DATABASE=wordpress -v "$PWD/mysqldata/":/var/lib/mysql -d mysql
  6. start wordpress docker: docker run -e WORDPRESS_DB_PASSWROD=wordpress -d --name wordpress --link wordpressdb:mysql -p 192.168.56.101:8080:80 -v "$PWD/wordpress":/var/www/html wordpress
  7. execute docker without sudo: (applied after restarting.) (or logout?)
    sudo usermod -aG docker 



2015-07-10

Remove grub boot menu and ubuntu system from Win8 and ubuntu dual system

environment:
   win8 (x64) + ubuntu system

target:

  1. remove grub boot menu
  2. remove ubuntu system/partition

2015-06-24

MySql in ubuntu, and replication.


mysql install in Ubuntu:


  1. sudo apt-get update
  2. sudo apt-get install mysql-server
    1. modify for my.cnf (in /etc/mysql) :
      1. bind-address  = 10.1.1.1
    2. allow remote hosts to use root to login:
    1. mysql -u root -p
    1. mysql>use mysql;
    1. mysql>update user set host = '%' where user = 'root';
    1. mysql>flush privileges;
  3. replications:
    1. source db:
      • in my.cnf:
        • log-bin=C:/Program Files/MySQL/MySQL Server 5.0/log/replication.log
        • server-id=1
        • restart mysql
      • mysql --user=user --password=password
        • FLUSH TABLES WITH READ LOCK;
        • SHOW MASTER STATUS;
        • keep File, Position
      • mysqldump --user=user --password=password --all-databases --master-data | gzip > dbdump.db.gz
        • 備份部份 DB: mysqldump --databases db1 db2
      • after mysqldump, 
        • mysql>UNLOCK TABLES;
    2. slave db:
      • gunzip < dbdump.db.gz | mysql -p
        • or mysql --user=user --password=password < dbdump.db
      • mysql>STOP SLAVE;
        
        mysql>CHANGE MASTER TO 
        MASTER_HOST='host name',
        MASTER_PORT=3306,
        MASTER_USER='username',
        MASTER_PASSWORD='password',
        MASTER_LOG_FILE='logfile',
        MASTER_LOG_POS=recorded_log_position;
        
        mysql>START SLAVE;
      •  show slave status
    3. in Ubuntu, mysql table name 預設是區分大小寫:
      1. (in my.cnf) lower_case_table_names=1   不區分大小寫

others:
  1. ubuntu 時間設定:
    1. 如果有 ntp service: service ntp stop
    2. ntpdate xx.xx.xx.xx   (time server)

2015-06-07

First Python practice


  • 第一個 Python 練習
  • Environment:
    • windows 8
    • Python 3.4
    • IDE:
      • Visual Studio 2013 + Python Tool for Visual Studio (PTVS)
      • PyScripter
      • test other IDE:
        • Sublime Text
        • PyCharm: seems to need more resources to run it, like busy CPU.
  • Target:
    1. 跟 python 親近一點
    2. write function in another file
    3. read/write file (IO) with utf-8 encoding
    4. access MariaDB/MySQL database
    5. use GitHub: workingrichard/PythonFirst

2014-08-27

win8 + ubuntu 14 雙系統




environment: windows 8.1 + ubuntu 14.04 LTS 雙系統


  • 安裝:
    • 安裝好 windows 8 後,接著安裝 ubuntu。
      • 由於在 windows 中,C, D 都設成了 primary disk。
      • 壓縮 C 切出一個空的 partition。
      • 以致於 ubuntu 再切時,/ 可以設成 primary disk,但不能再新增 swap。很有可能是因為已經有了4個 primary disk 了。改將 / 設成 logic disk,就可以新增 swap 了。
      • 不過,很有可能因為上述,變成開機直接進入 windows 而沒有 boot menu 可以選擇進入 ubuntu。
    • 開機進入 windows 8 後,下載使用 EasyBCD 軟體:
      • Add New Entry: Linux/BSD, type: Grub 2, partition 選擇安裝的 ubuntu partition。儲存套用,重開機後,boot menu 就出現可以選擇 windows 或是 自定的名稱了。
    • 故障排除:
      • 安裝時,如果出現 "The installer encountered an unrecoverable error. A desktop session will now be run so that you may investigate the problem or try installing again." 這樣子的錯誤訊息,在一開始就無法安裝了。
        檢查了 iso MD5,試了 ubuntu 14.01 光碟、14.10 USB 開機安裝,都是這樣的錯誤訊息。網路上也有人認為關閉安裝的介紹(slide show)可以解決,但我都不行。(不過,linux Mint 是可以的)
        解法:不要啟動無線網路,也不要安裝時更新,直接就光碟內容安裝即可進行下去

  • 中文:
    • 字型:
    • ibus 中文輸入法的設定畫面:
      • > ibus-setup
      • ref: http://www.pinyinjoe.com/linux/ubuntu-12-chinese-setup.htm
        http://www.pinyinjoe.com/linux/ubuntu-10-chinese-input-pinyin-chewing.htm
      • http://wiki.linux.org.hk/w/Configure_IBus
    • 安裝 gnome classic version 後,language support icon 不見了:
      • sudo apt-get install language-selector-gnome
      • 改選 gcin 輸入法
      • 倉頡:可使用五四三倉頡。

2013-09-30

在 windows 裡架起 Cassandra

install Cassandra in windows system

在 windows 系統上,加起 cassandra,實作起來不難,簡單步驟為:
(1) 安裝 java (JRI)
(2) 下載 cassandra tar, 並解開。
(3) 設定新增兩個系統環境變數: JAVA_HOME , CASSANDRA_HOME
(4) 修改 cassandra 設定檔 cassandra.yaml , 設好 cassandra 目錄所在。
(5) 啟動 cassanda,完成。


2013-08-28

How to union multiple table in MySQL?

database: MySQL

如果有多個 table 要合併起來,如果有 foreign key 要對應,一般都是用上 join 的語法。
但是,table 之間沒有關係,純綷只是要將各 table 中的所有 record 集合起來,那麼,就可以用上 union 的語法了:

select agentid as id, agentname as name  from agent
union
select cid, name from category
union
select id, adid from admanagement;

result:
id name
--------------
1 agent1
2 agent2
1 ca1
2 ca2
1 ad1
2 ad2

也可以加上一個欄位(文字或數值),直接來區分屬於那個 table 的內容:


select agentid as id, agentname as name, "agent" as type from agent
union
select cid, name, "category" from category
union
select id, adid, "ad" from admanagement;

result:

id name type
-----------------------
1 agent1 agent
2 agent2 agent
1 ca1 category
2 ca2 category
1 ad1 ad
2 ad2 ad

後記: 當資料量大時,效能不知如何...



後來,再查時,發現使用 union all 的速度會快過使用 union,原因在於 union all 不會去除重複,而 union 語法時,MySQL 會試著去過濾重複的資料。因此,如果確定 table 之間不會有重複的資料,可以直接下 union all 試看看:

select agentid as id, agentname as name, "agent" as type from agent
union all
select cid, name, "category" from category
union all
select id, adid, "ad" from admanagement;