2017年11月6日 星期一

新聞寫「松坂乏人問津?」11年過去了啊~


看到「松坂大輔乏人問津 拒球員兼教練這步走錯了?」引起回憶


2006年王建民上大聯盟第二年,正在連戰連捷,讓大家對他的伸卡球驚呼連連的時候,松坂還在西武,某天中午職場菜鳥的我們去吃咖喱,我隨口問了句:松坂什麼時候要去大聯盟啊?

果然,2006/11/15就獲得紅襪的競標,隔年2007就在大聯盟開始比賽,美聯東區兩支死對頭各有一個亞洲強投,話題性十足

轉眼11年過去了,王建民受傷後只在各職棒系統尋求機會,松坂已經回到日本但已經不再被視為戰力了

但儘管如此,當年2003亞錦賽讓中華隊只有兩人能打出安打的比賽,永遠讓台灣球迷印象深刻



2017年8月29日 星期二

閱讀「實用智能:讓事情如我們所願而發生的能力」

努力得到想要的東西,不要聽信「別計較、越想要就越得不到」這些說法,奴性不會讓老闆公平對待你,老闆只會想辦法滿足他搞不定的人

原文:
https://www.darencademy.com/article/view/id/16468

2017年8月18日 星期五

安裝Redis

-安裝
取得tar.gz並解壓縮
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable

安裝以前要先
yum install make gcc gcc-c++ kernel-devel

再執行,版本的問題
make MALLOC=libc

最後
make install

安裝完成可以測試會不會跑
#redis-server
按ctrl - C停止

-正式環境設置         注意:redis server 一定不能從internet連得到!!!
先修改~/redis-stable/redis.conf    (vim redis.conf),目的開放遠端連線、開機啟動
  1. comment掉這行:bind 127.0.0.1
  2. 改 protected-mode yes => no
  3. 設為daemon:daemonize yes
  4. 改log路徑:logfile "/var/log/redis_6379.log"
  5. 改working directory: dir /var/redis/6379

production建議這樣放置
sudo mkdir /etc/redis
sudo mkdir /var/redis

將Redis 預設script搬到開機執行位置
sudo cp utils/redis_init_script /etc/init.d/redis_6379

開一個空白目錄,讓Redis儲存dump
sudo mkdir /var/redis/6379

啟動 redis-server (不用#redis-server的方法,這是開發用的)
sudo /etc/init.d/redis_6379 start

測試是否成功,執行下列要能看到dump.rdb
#redis-cli save
# ls /var/redis/6379/
檢視/var/log/redis_6379.log有新的log寫入


參考:

Redis Quick Start

This is a quick start document that targets people without prior experience with Redis. Reading this document will help you:
  • Download and compile Redis to start hacking.
  • Use redis-cli to access the server.
  • Use Redis from your application.
  • Understand how Redis persistence works.
  • Install Redis more properly.
  • Find out what to read next to understand more about Redis.

Installing Redis

The suggested way of installing Redis is compiling it from sources as Redis has no dependencies other than a working GCC compiler and libc. Installing it using the package manager of your Linux distribution is somewhat discouraged as usually the available version is not the latest.
You can either download the latest Redis tar ball from the redis.io web site, or you can alternatively use this special URL that always points to the latest stable Redis version, that is, http://download.redis.io/redis-stable.tar.gz.
In order to compile Redis follow this simple steps:
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
At this point you can try if your build works correctly by typing make test, but this is an optional step. After the compilation the src directory inside the Redis distribution is populated with the different executables that are part of Redis:
  • redis-server is the Redis Server itself.
  • redis-sentinel is the Redis Sentinel executable (monitoring and failover).
  • redis-cli is the command line interface utility to talk with Redis.
  • redis-benchmark is used to check Redis performances.
  • redis-check-aof and redis-check-dump are useful in the rare event of corrupted data files.
It is a good idea to copy both the Redis server and the command line interface in proper places, either manually using the following commands:
  • sudo cp src/redis-server /usr/local/bin/
  • sudo cp src/redis-cli /usr/local/bin/
Or just using sudo make install.
In the following documentation we assume that /usr/local/bin is in your PATH environment variable so that you can execute both the binaries without specifying the full path.

Starting Redis

The simplest way to start the Redis server is just executing the redis-server binary without any argument.
$ redis-server
[28550] 01 Aug 19:29:28 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[28550] 01 Aug 19:29:28 * Server started, Redis version 2.2.12
[28550] 01 Aug 19:29:28 * The server is now ready to accept connections on port 6379
... more logs ...
In the above example Redis was started without any explicit configuration file, so all the parameters will use the internal default. This is perfectly fine if you are starting Redis just to play a bit with it or for development, but for production environments you should use a configuration file.
In order to start Redis with a configuration file use the full path of the configuration file as first argument, like in the following example: redis-server /etc/redis.conf. You should use the redis.conf file included in the root directory of the Redis source code distribution as a template to write your configuration file.

Check if Redis is working

External programs talk to Redis using a TCP socket and a Redis specific protocol. This protocol is implemented in the Redis client libraries for the different programming languages. However to make hacking with Redis simpler Redis provides a command line utility that can be used to send commands to Redis. This program is called redis-cli.
The first thing to do in order to check if Redis is working properly is sending a PING command using redis-cli:
$ redis-cli ping
PONG
Running redis-cli followed by a command name and its arguments will send this command to the Redis instance running on localhost at port 6379. You can change the host and port used by redis-cli, just try the --help option to check the usage information.
Another interesting way to run redis-cli is without arguments: the program will start in interactive mode, you can type different commands and see their replies.
$ redis-cli                                                                
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"
At this point you are able to talk with Redis. It is the right time to pause a bit with this tutorial and start the fifteen minutes introduction to Redis data types in order to learn a few Redis commands. Otherwise if you already know a few basic Redis commands you can keep reading.

Securing Redis

By default Redis binds to all the interfaces and has no authentication at all. If you use Redis into a very controlled environment, separated from the external internet and in general from attackers, that's fine. However if Redis without any hardening is exposed to the internet, it is a big security concern. If you are not 100% sure your environment is secured properly, please check the following steps in order to make Redis more secure, which are enlisted in order of increased security.
  1. Make sure the port Redis uses to listen for connections (by default 6379 and additionally 16379 if you run Redis in cluster mode, plus 26379 for Sentinel) is firewalled, so that it is not possible to contact Redis from the outside world.
  2. Use a configuration file where the bind directive is set in order to guarantee that Redis listens just in as little network interfaces you are using. For example only the loopback interface (127.0.0.1) if you are accessing Redis just locally from the same computer, and so forth.
  3. Use the requirepass option in order to add an additional layer of security so that clients will require to authenticate using the AUTH command.
  4. Use spiped or another SSL tunnelling software in order to encrypt traffic between Redis servers and Redis clients if your environment requires encryption.
Note that a Redis exposed to the internet without any security is very simple to exploit, so make sure you understand the above and apply at least a firewalling layer. After the firewalling is in place, try to connect with redis-cli from an external host in order to prove yourself the instance is actually not reachable.

Using Redis from your application

Of course using Redis just from the command line interface is not enough as the goal is to use it from your application. In order to do so you need to download and install a Redis client library for your programming language. You'll find a full list of clients for different languages in this page.
For instance if you happen to use the Ruby programming language our best advice is to use the Redis-rb client. You can install it using the command gem install redis.
These instructions are Ruby specific but actually many library clients for popular languages look quite similar: you create a Redis object and execute commands calling methods. A short interactive example using Ruby:
>> require 'rubygems'
=> false
>> require 'redis'
=> true
>> r = Redis.new
=> #<Redis client v2.2.1 connected to redis://127.0.0.1:6379/0 (Redis v2.3.8)>
>> r.ping
=> "PONG"
>> r.set('foo','bar')
=> "OK"
>> r.get('foo')
=> "bar"

Redis persistence

You can learn how Redis persistence works on this page, however what is important to understand for a quick start is that by default, if you start Redis with the default configuration, Redis will spontaneously save the dataset only from time to time (for instance after at least five minutes if you have at least 100 changes in your data), so if you want your database to persist and be reloaded after a restart make sure to call the SAVE command manually every time you want to force a data set snapshot. Otherwise make sure to shutdown the database using the SHUTDOWN command:
$ redis-cli shutdown
This way Redis will make sure to save the data on disk before quitting. Reading the persistence page is strongly suggested in order to better understand how Redis persistence works.

Installing Redis more properly

Running Redis from the command line is fine just to hack a bit with it or for development. However at some point you'll have some actual application to run on a real server. For this kind of usage you have two different choices:
  • Run Redis using screen.
  • Install Redis in your Linux box in a proper way using an init script, so that after a restart everything will start again properly.
A proper install using an init script is strongly suggested. The following instructions can be used to perform a proper installation using the init script shipped with Redis 2.4 in a Debian or Ubuntu based distribution.
We assume you already copied redis-server and redis-cli executables under /usr/local/bin.
  • Create a directory where to store your Redis config files and your data:
    sudo mkdir /etc/redis
    sudo mkdir /var/redis
    
  • Copy the init script that you'll find in the Redis distribution under the utils directory into /etc/init.d. We suggest calling it with the name of the port where you are running this instance of Redis. For example:
    sudo cp utils/redis_init_script /etc/init.d/redis_6379
  • Edit the init script.
    sudo vi /etc/init.d/redis_6379
    
Make sure to modify REDISPORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number.
  • Copy the template configuration file you'll find in the root directory of the Redis distribution into /etc/redis/ using the port number as name, for instance:
    sudo cp redis.conf /etc/redis/6379.conf
    
  • Create a directory inside /var/redis that will work as data and working directory for this Redis instance:
    sudo mkdir /var/redis/6379
    
  • Edit the configuration file, making sure to perform the following changes:
    • Set daemonize to yes (by default it is set to no).
    • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
    • Change the port accordingly. In our example it is not needed as the default port is already 6379.
    • Set your preferred loglevel.
    • Set the logfile to /var/log/redis_6379.log
    • Set the dir to /var/redis/6379 (very important step!)
  • Finally add the new Redis init script to all the default runlevels using the following command:
    sudo update-rc.d redis_6379 defaults
    
You are done! Now you can try running your instance with:
sudo /etc/init.d/redis_6379 start
Make sure that everything is working as expected:
  • Try pinging your instance with redis-cli.
  • Do a test save with redis-cli save and check that the dump file is correctly stored into /var/redis/6379/ (you should find a file called dump.rdb).
  • Check that your Redis instance is correctly logging in the log file.  (/var/log/redis_6379.log )
  • If it's a new machine where you can try it without problems make sure that after a reboot everything is still working.
Note: In the above instructions we skipped many Redis configuration parameters that you would like to change, for instance in order to use AOF persistence instead of RDB persistence, or to setup replication, and so forth. Make sure to read the example redis.conf file (that is heavily commented) and the other documentation you can find in this web site for more information.

2017年8月8日 星期二

CentOS6 啟動MongoDB 3.4失敗解決方法

下指令service mongod start 先遇到mongodb log status = 2

嘗試把/etc/mongod.conf 下列行刪掉

systemLog:
  logAppend: true
  logRotate: reopen

以及把下列檔案刪掉
/etc/logrotate.d/mongodb

再下指令
service mongod start

確認執行狀態

service mongod status
出現下列錯誤訊息

● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-08-09 10:58:29 CST; 13s ago
     Docs: https://docs.mongodb.org/manual
  Process: 25673 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=51)
  Process: 25670 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 25668 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 25666 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 25673 (code=exited, status=51)

Aug 09 10:58:28 chttl-97d3548f99e4a8cb.local.com systemd[1]: Starting High-performance, schema-free document-oriented database...
Aug 09 10:58:28 chttl-97d3548f99e4a8cb.local.com systemd[1]: Started High-performance, schema-free document-oriented database.
Aug 09 10:58:28 chttl-97d3548f99e4a8cb.local.com mongod[25673]: about to fork child process, waiting until server is ready for connections.
Aug 09 10:58:28 chttl-97d3548f99e4a8cb.local.com mongod[25673]: forked process: 25676
Aug 09 10:58:29 chttl-97d3548f99e4a8cb.local.com systemd[1]: mongod.service: main process exited, code=exited, status=51/n/a
Aug 09 10:58:29 chttl-97d3548f99e4a8cb.local.com systemd[1]: Unit mongod.service entered failed state.
Aug 09 10:58:29 chttl-97d3548f99e4a8cb.local.com systemd[1]: mongod.service failed.


參考這篇 https://stackoverflow.com/questions/18524925/mongodb-service-wont-start
將/var/lib/mongo的權限都換成mongod 重啟成功!
原文:
- Check the file permissions inside your database folder

    - note you need to be in your dbpath folder mine was /var/lib/mongo I went to cd /var/lib
    - I ran ls -l mongo


- This showed me that databases were owned by root, which is wrong. I ran the following to fix this: chown -R mongod:mongod mongo.

2016年12月6日 星期二

比爾蓋茲分享的五本書

看到下列這篇,我對於"合作、協調及分配來做事,並且了解到沒有一個人可以或應該知道所有事情的答案"很有感覺

[分工與委派,好像是這樣沒錯!]
絕大多數的領導或管理都會說到分工、委派的重要,選擇也比能力重要,但是有些主管似乎開始誤用了授權與委派

可能主管們從一場會議中接受高層的命令,可能PM與客戶訪談後帶回一些需求,可能來自公司核心的政策需要遵守,主管發一封email 、一通電話、走到基層座位旁邊交待一句:請處理!就叫作委派了~!?

[重點在負責啊]
實際上等客戶來追進度了,直接對客戶說:我都以經交辦誰去做了,長官來看成果了,直接對基層說:我不是都交待給你了嗎,如果都不用負責,也未免太簡化分工委派的本質了,甚至有些主管竟然說出:我授權給你,被交辦的人通常是有責無權吧

[為什麼這種現在普遍存在?]
很奇怪,為什麼畫大餅的人永遠在指揮會做事的人?我們不得不承認,畫大餅本身也是一種能力,畫大餅或許不好聽,如果說成:包裝,是不是比較好聽了一點呢?

你覺得你的上級沒實力只會包裝,高層怎麼都不會發現,殊不知,因為高層要更精美的包裝,要畫的餅更大了,所以高層怎麼會譴責這種行為呢?

這是現實,是很殘酷的啊


4. 《The Myth of the Strong Leader》,Archie Brown著

截自博客來
在今年全球各地打的激烈的選戰中,讓比爾·蓋茲重新閱讀了這本於2014年出版的書籍。Brown是來自牛津大學的學者,花費超過50年研究不論好的、壞的、醜陋的各式面向的政治領導力。
Brown認為真正對歷史及人性貢獻良多的領袖,其實並不是我們ㄧ般認為那樣是「強有力的領導者」,反之,這些領袖都傾向透過合作、協調及分配來做事,並且了解到沒有一個人可以或應該知道所有事情的答案,就像作者布朗不能預測他的書在2016年的今天會變得怎麼樣。

2016年11月14日 星期一

渣打信用卡不論多少錢都會寄email 通知

很多銀行有通知的下限 例如3000元以上

但渣打(昇利和鈦金)連刷100都會通知

感覺是不錯

但優惠本身是很差的

單純為了刷 2 筆而刷

2016年10月2日 星期日


聊聊物盡其用愛地球吧,請盡量補充吧!

書: TAAZE, 可以換成錢的,"如個人戶欲匯出現金至銀行帳戶(注意:會員申請匯出須提供台灣當地設立之銀行,恕不接受國外銀行。),每筆匯款需扣除手續費15元"、茉莉二手書店之類的,但我喜歡TAAZE,因為線上就可以判斷這本書是否已經太多人再賣。

捐給圖書館,但我喜歡問館員是否這本書會上架,因為有些書館員認為太舊或館藏太多就不會上架,有些不錯的書竟然是不會上架的,因為館藏已經有!?

電器 3C: 蝦皮, ruten, yahoo拍賣,沒有賣掉就PTT give 版


電腦: 綠色奇蹟,本身不需負擔運費

傘:放捷運站愛心傘架

筆記本:放公司公共區給人取用

贈品筆:通常是XX展或X品集團填問卷的原子筆,給大樓警衛,寫簿冊很需要筆,而且公用的筆很容易壞掉

不太可能賣錢的雜物:例如過期的奶粉,PTT Give 版

其它的贈物方法:Give543贈物網、facebook張貼問朋友、直接放回收區讓回收的人撿,盡量維持東西的完整功能,也盡量放在回收箱的醒目處