CentOS 5.5 下安裝Countly Web Server過程記錄
1. 系統更新與中文語言包安裝
2. 基本環境配置:
2.1. NodeJS安裝
依賴項安裝
yum -y install gcc gcc-c++ openssl-devel
下載並解壓安裝 nodejs
cd /opt wget –c http://nodejs.org/dist/v0.12.4/node-v0.12.4.tar.gz tar zxvf node-v0.12.4.tar.gz cd node-v0.12.4 ./configure --prefix=/usr/local/nodejs make && make install
注意此時會有錯誤輸出信息:
./configure File "./configure", line 442 fpu = 'vfpv3' if armv7 else 'vfpv2' ^ SyntaxError: invalid syntax
這是因爲Python當前版本 2.4.3 不夠,需要升級Python
升級Python:
cd /opt wget -c http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 tar jxvf Python-2.7.3.tar.bz2 cd Python-2.7.3 ./configure make && make install
正常情況下即使python2.7安裝成功後,系統默認指向的python仍然是2.4.3版本,考慮到yum是基於python2.4.3才能正常工作,不敢輕易卸載。
解決方法:建立軟連接
mv /usr/bin/python /usr/bin/python.bak ln -s /usr/local/bin/python2.7 /usr/bin/python
使yum配置指向特定版本python2.4
vi /usr/bin/yum
將第一行顯示的
#/usr/bin/python
修改爲#/usr/bin/python2.4
保存修改:wq
繼續上面的步驟重新安裝NodeJS:
cd /opt/node-v0.12.4 ./configure --prefix=/usr/local/nodejs make && make install
注意,又有新的錯誤:
ImportError: No module named bz2 make[1]: *** [/opt/node-v0.12.4/out/Release/obj/gen/libraries.cc] 錯誤 1 make[1]: Leaving directory '/opt/node-v0.12.4/out' make: *** [node] 錯誤 2
這個錯誤是由於python中沒有裝bz2的庫導致的
繼續安裝bz2
yum install -y bzip2* cd /opt/Python-2.7.2/Modules/zlib ./configure make && make install
重新安裝python
cd /opt/Python-2.7.2/ python2.7 setup.py install
繼續上面的步驟重新安裝NodeJS:
cd /opt/node-v0.12.4 ./configure --prefix=/usr/local/nodejs make && make install
這次應該可以安裝成功了
配置NodeJS環境變量
- 進入profile編輯環境變量
vim /etc/profile
在
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
一行的【上面】添加如下內容:#set for nodejs export NODE_HOME=/usr/local/nodejs export PATH=$NODE_HOME/bin:$PATH
:wq
保存並退出,編譯/etc/profile 使配置生效source /etc/profile
輸入測試:
node -v
得到版本號
v0.12.4
- 進入profile編輯環境變量
2.2 Ngnix安裝
在安裝nginx前,需要確保系統安裝了g++、gcc、openssl-devel、pcre-devel和zlib-devel 和libevent
yum install pcre-devel libevent openssl yum -y install zlib zlib-devel pcre
下載、解壓安裝Nginx
wget -c http://nginx.org/download/nginx-1.8.0.tar.gz tar –zxv –f nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure --prefix=/usr/local/nginx make && make install
測試nginx
開啓:/usr/local/nginx/sbin/nginx
測試http訪問
curl localhost
得到以下輸出信息表示成功安裝並開啓nginx
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> </pre>
3. 安裝Countly Web Server
下載到/opt,並解壓
cd /opt wget –c https://github.com/Countly/countly-server/archive/master.zip unzip countly-server-master.zip mv ./countly-server-master ./countly
複製countly web配置文件,並修改配置
cd /opt/countly/frontend/express/ cp config.sample.js config.js vi config.js
將
mongodb
服務器地址host
修改爲192.168.8.16
,保存並退出
:wq
複製api配置文件,並修改mongodb host
cd ../../api/ cp config.sample.js config.js vi config.js
將
mongodb
服務器地址host
修改爲192.168.8.16
,保存並退出
:wq
複製 countly.config.js
cd /opt/countly/frontend/express/public/javascripts/countly/ cp countly.config.sample.js countly.config.js
此時如果執行
node /opt/countly/api/api.js
node會報錯誤,沒有time 組件,需要安裝time
組件
使用淘寶提供的源進行安裝npm --registry http://registry.cnpmjs.org/ install time
這個時間比較長,會進行
node-gyp rebuild
,安裝完成後,就可以測試node /opt/countly/api/api.js
和node /opt/countly/frontend/express/app.js
了
4. 配置服務自啓動
4.1 安裝supervisor 進程管理,設置自啓動
下載並安裝supervisor
cd /opt && wget -c --no-check-certificate https://pypi.python.org/packages/source/s/supervisor/supervisor-3.1.1.tar.gz tar zxvf supervisor-3.1.1.tar.gz cd supervisor-3.1.1 python setup.py install
如果出現錯誤:
Traceback (most recent call last): File "setup.py", line 32, in <module> from setuptools import setup, find_packages ImportError: No module named setuptools
下載安裝python組件:setuptools17.0
unzip setuptools-17.0.zip cd setuptools-17.0 python setup.py install
繼續用python安裝 supervisor
cd /opt/supervisor-3.1.1 python setup.py install
- 編輯countly-supervisor.conf
bash
vi /opt/countly/bin/config/supervisord.conf
將%(here)s/../..
和%(here)s
替換爲/opt/countly
,保存修改:wq
- 配置supervisor文件
bash
echo_supervisord_conf > /etc/supervisord.conf
vi /etc/supervisord.conf
將最後兩行取消註釋,改爲:
[include]
files = /opt/countly/bin/config/supervisord.conf
保存:wq
配置supervisor 自啓動
vi /etc/init.d/supervisor
添加加入代碼:
#!/bin/bash # supervisor Startup script for the Countly HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Countly # processname: supervisor # pidfile: /var/run/supervisor.pid # config: /etc/supervisord.conf supervisordd=/usr/local/bin/supervisord supervisor_config=/etc/supervisord.conf supervisor_pid=/var/run/supervisor.pid RETVAL=0 prog="supervisor" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $supervisordd ] || exit 0 # Start supervisor daemons functions. start() { PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/nodejs/bin if [ -e $supervisor_pid ];then echo "supervisor already running...." exit 1 fi echo $"Starting $prog with conf:$supervisor_config" daemon $supervisordd --configuration ${supervisor_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/supervisor return $RETVAL } # Stop supervisor daemons functions. stop() { echo -n $"Stopping $prog: " killproc $supervisordd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/supervisor /var/run/supervisor.pid } # reload supervisor service functions. reload() { PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/nodejs/bin echo -n $"Reloading $prog: " #kill -HUP `cat ${supervisor_pid}` killproc $supervisordd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
保存修改
:wq
設置文件屬性爲可執行chmod a+x /etc/init.d/supervisor
測試:
service supervisor start
可以看到:
Starting supervisor with conf:/etc/supervisord.conf [確定]
- 添加到開機啓動項中:
bash
vi /etc/rc.local
加入:
bahs
/etc/init.d/supervisor start
保存:wq
4.2 配置Nginx自啓動
添加nginx腳本
vi /etc/init.d/nginx
加入下面的內容:
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
保存並退出
:wq
設置文件的訪問權限(a+x
==> all user can execute 所有用戶可執行)chmod a+x /etc/init.d/nginx
添加到開機啓動項中
vi /etc/rc.local
加入一行
/etc/init.d/nginx start
保存並退出,下次重啓會生效。完成所有配置,重啓服務器。
reboot
重新打開terminal輸入:
curl localhost
得到:
Moved Temporarily. Redirecting to /login
5. 說明
過程中參考了這些文章
安裝中文語言支持包
http://www.xshell.net/linux/GNOM.html
CentOS安裝NodeJS
http://zhaohe162.blog.163.com/blog/static/38216797201402234212981/
給nodejs的npm更換源
http://blog.sina.com.cn/s/blog_77a8ce670101cdd3.html
升級CentOS5.6_X64 python2.4.3到2.7
http://hxl2009.blog.51cto.com/779549/1031310
python中沒有裝bz2的庫
http://flyer2010.iteye.com/blog/1699946
配置環境變量
http://blog.csdn.net/zhaoweitco/article/details/12677089