發表文章

目前顯示的是有「centos7」標籤的文章

CENTOS7 安裝 NGINX 並請申請 Letsencrypt SSL憑證使用

圖片
CENTOS7 安裝 NGINX 並請申請 Letsencrypt SSL憑證使用 # 首先先看看網路上的教學安裝文章, 照著作把 nginx 安裝起來 https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7 # 然後安裝憑證, 這個 Letsencrypt 目前用程式安裝憑證 https://letsencrypt.org/ # 請依據制這裡的說明, 安裝程式及工具 https://certbot.eff.org/#centosrhel7-nginx # 先把 domain FQDN 對應 IP 設定好 # 執行憑證申請及安裝, 因為 Letsencrypt 有縣市 IP 及 Domain 所以申請盡可能一次就成功。 # 依據說明執行 [root@dev letsencrypt]# certbot --nginx Saving debug log to /var/log/letsencrypt/letsencrypt.log Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org Which names would you like to activate HTTPS for? ------------------------------------------------------------------------------- 1: api.jangmt.com 2: dev.jangmt.com ------------------------------------------------------------------------------- Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): 2 Obtaining a new certificate Perfor...

Redis-Server with PHP 的使用 in CentOS7

圖片
Redis-Server with PHP 的使用 in CentOS7 * Redis DB server 的用途 Redis 是一個 key-value 架構的 database , 且因為它工作在記憶體上面,所以速度非常的快。 可以用來當 DB cache 加速的功能或是需要快速反應的 DB * CentOS 7 的 Redis-server 安裝方式 # yum install redis -y  * 安裝參考 http://sharadchhetri.com/2014/10/04/install-redis-server-centos-7-rhel-7/ * 通常會搭配 php 等 client 端工具一起安裝, 這裡我是以 php56w 的版本安裝, 因為有比較多 lib 支援 # yum install php56w-pecl-redis * php56w 可以參考 webtatic 釋出的 yum repo 安裝參考 https://webtatic.com/packages/php56/ RHEL7 OR EPEL7  官方網站跑的版本有點慢,可以先參考這個版本。 * 啟動 # systemctl start redis.service * 預設開機啟動 # systemctl enable redis.service * 看狀態 # systemctl status redis.service * 測試 , 剛裝好的 redis-server 是沒有密碼的, 且只能 127.0.0.1 執行。 可以用 redis-cli client 端工具測試 PONG 是正確的回應。 [root@c7 ~]# redis-cli ping PONG * 所以我都會設定個密碼, 並且把 bind 打開讓所有人都可以連上來。 * 請找到下面兩行, 修改為你要的密碼及主機 ip # vim /etc/redis.conf bind 111.111.22.22 requirepass 123456 * 重新啟動 # systemctl restart redis.service * 驗證看看 port , 應該是 6379 # netstat -antlp | grep ...

Postgresql 上面的「尿布、啤酒、星期五」,不用寫程式下行 SQL 就搞定

圖片
MADlib + postgresql 9.4 in Linux CentOS 7 MADlib®: Big Data Machine Learning in SQL for Data Scientists 啤酒、尿布、星期五 MADlib 在 postgresql 上面以是以 postgres 函式的型態來實現對於數據資料的操作 ,你可以透過這個以 plpython 語言寫的函式,直接操作原始數據轉存到新的資料庫當中,這個函式庫支援很多機器學習的演算法,可以很方便的分析數據. 目前提供的有底下這些,看起來應該有陸續發展的可能,因為已經被放到 Apache 基金會的子項目計畫內了...XDXD 功能: Classification 分類 Regression 回歸 Clustering 集群 Topic Modeling 主題模型 Association Rule Mining 關聯性規則 Descriptive Statistics 描述性統計 Validation 驗證 more... http://madlib.net/product/ 官方網站 http://madlib.net/ 我使用來安裝的版本是 CentOS Linux 7 ,但是安裝這個 LIB 前請先選擇一套支援的資料庫系統,這裡我用的是 Postgresql 9.4 的版本,安裝請參考這一篇: http://blog.jangmt.com/2016/03/postgresql-94-in-centos-linux-7.html 下載 http://madlib.net/download/ 安裝 [root@c7 ~]#    yum install madlib-1.8-Linux.rpm  -y 檢查是否裝了,安裝好後他的路徑放在 /usr/local/madlib/ [root@c7 ~]# rpm -qa | grep madlib madlib-1.8-1.x86_64 我使用 Single Node 的模式,系統需求:( HAWQ >= 1.2, Greenplum >= 4.2 or PostgreSQL >= 9.2 ) 在安裝後,這特 MADlib ...

mysql 中文亂碼的避免及 php mysql pdo 宣告取用方式

圖片
Mariadb 和 Mysql 都會有亂碼, 只要它預設編碼還是在 latin 的時還是一直會發生. 所以改成 utf8 編碼是一個對於東亞語系的文字,會比較方便。 UTF8 的介紹請看 wiki https://zh.wikipedia.org/wiki/UTF-8 xxx_bin (區分大小寫) xxx_general_ci (不區分大小寫) Collation 每個字符集的排序規則 http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html 在 mysql 資料庫中有兩個編碼系統 UCS2 及 UTF8 utf8 使用 1~3 bytes ,帶有 65536 個組合的編碼 utf32 與 utf8mb4 是完整的的 unicode ,差異在 utf32 固定 4 bytes ,而 utf8mb4 則是彈性使用 1~4 bytes 。 utf8mb4 從 MySQL 5.5.3 (released March 2010). 開始提供 目前預設的編碼系統為 xxx_general_ci (default) 為了中文語系使用不要出問題,建議修正如下: ----------------------------------------------------- # 修正 mysql 的設定檔 [root@c7 my.cnf.d]# more /etc/my.cnf.d/my-huge.cnf  [client] default-character-set=utf8mb4 [code] default-character-set=utf8mb4 [mysqld] character-set-server=utf8mb4 collation-server=utf8mb4_general_ci # restart mysql service # 檢查系統的編碼變數 ---------------------------- [root@c7 my.cnf.d]# mysql -u root -p Enter password: MariaDB [(none)]> SHOW VARIABLES WHERE Variab...

PostgreSQL 9.4 in CentOS Linux 7 簡易安裝教學

圖片
PostgreSQL 9.4 in CentOS Linux 7 # 安裝下載 http://www.postgresql.org/download/linux/redhat/ # 安裝 REPO 來源檔 yum install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-1.noarch.rpm  -y # 安裝主要資料庫程式 yum install postgresql94-server postgresql94-contrib -y /usr/pgsql-9.4/bin/postgresql94-setup initdb systemctl enable postgresql-9.4.service systemctl start postgresql-9.4.service # 裝好後所有的設定檔及紀錄檔都在 /var/lib/pgsql 這個目錄內 [root@c7 ~]# ls /var/lib/pgsql -la total 8 drwx------.  3 postgres postgres   36 Mar 23 09:27 . drwxr-xr-x. 70 root     root     4096 Mar 23 09:27 .. drwx------.  4 postgres postgres   48 Mar 23 09:27 9.4 -rwx------.  1 postgres postgres  267 Mar 23 09:27 .bash_profile # 確認帳號 [root@c7 ~]# id postgres uid=26(postgres) gid=26(postgres) groups=26(postgres) # 切換使用者,並且登入系統設定 [root@c7 ~]# su - postgres -bash-4.2$ psql template1 psql (9.4.6) Type "help" for help. # 建立一個使用者為 mtchang ...

php7 vs. GO lang vs. C on CentOS 7 Linux 速度比較

圖片
php7 vs. GO lang vs. C on CentOS 7 Linux 速度比較 繼上一篇後,想說 php7 已經很快了,但是到底和原生 C 差多少..... 所以就抓了php7 , GO 及 C 三種語言來比較看看氣泡演算法, 12 各項目排序 90萬次花費的時間。 結論: PHP7 ==>  5.9242088794708 s GO  ==>  0.228.885223 s C ==> 0.174889 s 換算一下, ms, us 的單位, 結論是 php7 連 GO 和 C 的車尾燈都看不到... GO 還可以看得到C 的車尾燈!!!!! 且 GO 比 C 好寫多了,我可以接受這一點點的微小差距。 有圖有真相.... C bubble sort 演算法  http://www.programmingsimplified.com/c/source-code/c-program-bubble-sort C 計算時間差 http://www.binarytides.com/get-time-difference-in-microtime-in-c/ php 及 go 的程式碼 https://jaxbot.me/articles/benchmarks_nodejs_vs_go_vs_php_3_14_2013 別人做的 php vs go https://www.ransona.com/blog/2014/11/06/go-vs-php-performance-restful-service/

Apache Spark 測試 FPGrowth(傳統C語言與Spark 的簡易測試)

圖片
因為剛剛把 Apache 的 Spark 設定好,順便驗證測試看看效能如何? 剛好發現 Spark 的 MLLIB 內有內建的 FPGrowth 演算法 ,剛好跟它有點熟所以就用這個演算法加上網路上的資料來測試看看。 先講結論:資料量小,不利於使用巨量資料工具。 關於 fpgrowth 演算法請先參考這篇: http://blog.jangmt.com/2015/10/fpgrowth-algorithm.html 底下紀錄測試的過程,及使用的參數。 測試運算資料來源: http://fimi.ua.ac.be/data/ Frequent Itemset Mining Dataset Repository--- LAB (1) Christian Borgelt 寫的 C 語言程式 FPGrowth 對上 Spark scala fpgrowth 程式 --- # FPGrowth 先把 -m1 同時出現的SET設為1個,支持度 5 ,信任度為 80%(default) # 這個案例花費了 0.09s 運算了 0.01s [hadoop@hnamenode FrequentItemset]$ ./fpgrowth -m1 -s5 T10I4D100K.dat T10I4D100K.out.txt ./fpgrowth - find frequent item sets with the fpgrowth algorithm version 6.7 (2015.08.18)         (c) 2004-2015   Christian Borgelt reading T10I4D100K.dat ... [870 item(s), 100000 transaction(s)] done [0.09s]. filtering, sorting and recoding items ... [10 item(s)] done [0.00s]. sorting and reducing transactions ... [281/100000 transaction(s)] done [0.01s]. writing T10I4D100K.out.txt .....

關聯規則--用來發現資料中屬性具有高度關聯的樣式(fpgrowth algorithm)

圖片
這篇不是要講很艱深的東西,簡單解釋一下啥事關聯規則。 基本上上面這張購物欄交易資料,透過底下的 apriori 演算法程式,可以找到啤酒和尿布具有很大的相關性,他的支持度高達 50 。 故事請看這裡 。這是個範例,只是說明關聯規則程式可發覺這樣形式的規則關聯樣式。 在網路上有個人  Christian Borgelt 寫了很多程式,其中有 apriori 和 fpgrowth ,基本上這兩個程式做的工作差不多,但是 fpgrowth 有效率多了。 所以今天用這個 fpgrowth 程式來跑跑看數據。 我從: http://fimi.ua.ac.be/data/ Frequent Itemset Mining Dataset Repository 抓了很多資料 http://fimi.ua.ac.be/data/T10I4D100K.dat http://fimi.ua.ac.be/data/T40I10D100K.dat http://fimi.ua.ac.be/data/webdocs.dat.gz 放到我的電腦內,然後去找 Christian Borgelt http://www.borgelt.net/fpgrowth.html  抓了一些程式。 大概長的這樣: [hadoop@hnamenode FrequentItemset]$ ls -la -rwxrwxr-x. 1 hadoop hadoop      486760 Sep  5 05:17 fpgrowth -rw-rw-r--. 1 hadoop hadoop     4022055 Oct 14  2010 T10I4D100K.dat -rw-rw-r--. 1 hadoop hadoop    15478113 Oct 14  2010 T40I10D100K.dat -rw-rw-r--. 1 hadoop hadoop         151 Oct 17 23:15 webdocs.out 有個很簡單的檔案  sample_fpgr...

Hadoop HDFS 上傳檔案速度測試

因為不太清楚 Hadoop HDFS 在傳輸檔案的速度,所以寫了一個小程式來測試 HDFS 上傳檔案的速度。 先講結論 :hdfs 大概會花3秒的時間做協調的傳輸工作,所以大約 1MB 左右的時間都是 3 秒。傳輸的檔案越大,速度越快。 結果整理如下: 容量      傳輸時間  平均速度(MBytes) 110K 3 36KB/S 1.1MB 3 375KB/S 10.7MB   4 2739.2KB/S --> 2.675MB 107.1MB   9   11.9MB/S 1.0GB   23 44.521MB/S 11GB   216 52.148MB/S 過程及程式測試 shell script [hadoop@hnamenode input]$ cat run_put.sh #!/bin/bash ARGC1='input.txt' ARGC1=$1 if [ "ARGC1" != "" ]; then PROG_START=$(date +%s) hdfs dfs -put ${ARGC1} /public/data/ PROG_END=$(date +%s) PROG_DURING=$(expr $PROG_END - $PROG_START) echo "上傳 ${ARGC1} 檔案到 HDFS:/public/data/ 目錄下" echo "花費時間: ${PROG_DURING} 秒" hdfs dfs -ls -h /public/data/${ARGC1} fi [hadoop@hnamenode input]$ ls -alh total 12G drwxrwxr-x. 2 hadoop hadoop 4.0K Oct 17 13:23 . drwxrwxr-x. 4 hadoop hadoop 4.0K Oct  4 00:26 .. -rw-rw-r--. 1 hadoop hadoop  11G Oct  1 22:33 input100K.txt ...

chrony 網路對時服務

---- chrony 網路對時服務 ---- NTPd 套件在 CentOS 7 以後,逐漸被棄用了。改成 chrony 套件提供服務 # 安裝 chrony 移除 ntp ,並啟動服務 yum remove -y ntp yum install -y chrony systemctl start chronyd.service systemctl enable chronyd.service # 驗證程序是否工作 [root@hnamenode ~]# systemctl status chronyd.service chronyd.service - NTP client/server    Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled)    Active: active (running) since Sat 2015-10-10 15:57:08 CST; 23h ago  Main PID: 886 (chronyd)    CGroup: /system.slice/chronyd.service            └─886 /usr/sbin/chronyd -u chrony Oct 10 15:57:08 hnamenode.cm.nsysu.edu.tw systemd[1]: Starting NTP client/server... Oct 10 15:57:08 hnamenode.cm.nsysu.edu.tw chronyd[886]: chronyd version 1.29.1 starting Oct 10 15:57:08 hnamenode.cm.nsysu.edu.tw chronyd[886]: Linux kernel major=3 minor=10 patch=0 Oct 10 15:57:08 hnamenode.cm.nsysu.edu.tw chronyd[886]: hz=100 shift_hz=7 freq_scale=1.00000000...

R in HADOOP - install

R in HADOOP - install ---------------- 就是再 R 透過 lib 呼叫 HADOOP 的 api 跑 hdfs 及 mapreduce 程式 ------ Step 0 : 先把 hadoop 的系統環境變數確認,可以用 env 看到底下設定的環境變數 ------ # 底下為我設定的範例,請以你的 hadoop env 路徑修改 [root@hdatanode17 ~]# cat .bash_profile   # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH # ---------------------------------------------- # HADOOP ENV # ---------------------------------------------- #JAVA export JAVA_HOME=/usr/java/latest export JRE_HOME=/usr/java/latest/jre # HADOOP export HADOOP_PREFIX=/home/hadoop/hadoop export HADOOP_HOME=$HADOOP_PREFIX export HADOOP_COMMON_HOME=$HADOOP_PREFIX export HADOOP_CONF_DIR=$HADOOP_PREFIX/etc/hadoop export HADOOP_HDFS_HOME=$HADOOP_PREFIX export HADOOP_MAPRED_HOME=$HADOOP_PREFIX export HADOOP_YARN_HOME=$HADOOP_PREFIX export HADOOP_NAMENODE_OPTS="-XX:+UseParallelGC -Xmx1g...