您的位置:首页 > 大数据 > 人工智能

日报系统 daily report

2015-10-19 15:22 381 查看
一、系统准备

1.安装好httpd
2.安装node.js 包括(node npm express)
3.安装redis http://redis.io/download 4.下载daily report安装包 http://www.open-open.com/lib/view/open1374583955746.html

二、Node.js安装与配置

1、epel源

yum install epel-release

2、安装node.js

yum install node*

3、安装npm

yum install npm*

4、测试node和npm

[root@centos ~]# node -v
v0.10.36
[root@centos ~]# npm -v
1.3.6
[root@centos ~]#
此时说明node和npm安装成功。

三、redis安装与配置

1、解压压缩包

tar -zxvf redis-2.8.22.tar.gz
cd redis-2.8.22

2、安装

make 完成之后
在同级目录的src中会出现三个文件
redis-benchmark redis-cli redis-server

(1)拷贝命令

cp redis-cli redis-server redis-benchmark /usr/bin

这样是为了随时可以使用该命令,方便而已。。。

(2)拷贝配置文件

cp ./redis.conf /etc/

3、启动数据库

(1)命令是:redis-server /etc/redis.conf

如果没有进行任何配置会出现如下错误:
[4625] 19 Oct 11:48:20.939 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[4625] 19 Oct 11:48:20.939 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[4625] 19 Oct 11:48:20.940 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[4625] 19 Oct 11:48:20.940 * The server is now ready to accept connections on port 6379

(2)警告处理

第一个警告。
vim /etc/sysctl.conf 在最后一行添加:
vm.overcommit_memory=1
保存退出。
刷新配置使其生效
sysctl vm.overcommit_memory=1
第二个警告.
执行:echo never > /sys/kernel/mm/transparent_hugepage/enabled
第三个警告:
Echo 511 >/proc/sys/net/core/somaxconn

(3)再次启动

redis-server /etc/redis.conf

[4713] 19 Oct 12:22:04.895 # Server started, Redis version 2.8.22
[4713] 19 Oct 12:22:04.895 * DB loaded from disk: 0.000 seconds
[4713] 19 Oct 12:22:04.896 * The server is now ready to accept connections on port 6379

(4)测试

[root@centos ~]# ps -eaf |grep redis
root 4713 1576 0 12:22 pts/0 00:00:00 redis-server *:6379
root 4742 4720 0 12:22 pts/1 00:00:00 grep redis
[root@centos ~]# netstat -an |grep :6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
tcp 0 0 :::6379 :::* LISTEN

(5)创建库

redis-cli
redis 127.0.0.1:6379> incr next_user_id(integer) 1执行完该命令后表明 next_user_id 的值为1,然后执行如下命令(1:user_name和1:password中的1即为上一步执行incr next_user_id后的 next_user_id的值)redis 127.0.0.1:6379> hmset users 1:user_name admin 1:password 1234567OK执行下面的命令将管理员adminn的id添加到管理员集合中redis 127.0.0.1:6379> sadd admin 1(integer) 1

四、daily安装与配置

1、解压

unzip WalterShe-dailyReport-e3fcff6.zip
cd WalterShe-dailyReport-e3fcff6

2、移动文件与目录

cp -R * /var/www/html/
将所有的文件与目录拷贝到网站的根目录中。
cd /var/www/htnl

3、安装

npm install

到此安装成功!

4、配置

(1)配置访问端口

在config.conf
最后的port处可以定义

(2)配置app.js

如果没有配置会出现以下情况:

body-parser deprecated bodyParser: use individual json/urlencoded middlewares app.js:29:31
body-parser deprecated undefined extended: provide extended option node_modules/body-parser/index.js:85:29
express-session deprecated undefined resave option; provide resave option app.js:32:9
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:32:9
Express server listening on port 3000

需要添加一下:
var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: false })) ;

该行注释掉:app.use(require('body-parser')());

[root@centos html]# node app.js
express-session deprecated undefined resave option; provide resave option app.js:34:9
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:34:9
Express server listening on port 3000

上面的警告需要修改:

该行注释掉:app.use(session({ store: new redisStore({host:sessiondbconfig.host, port:sessiondbconfig.port, pass:sessiondbconfig.pass, db:sessiondbconfig.db, prefix:'sess', ttl:3600}), secret: 'iamwaltershe' }));
在注释行下添加:

app.use(session({secret: '<mysecret>',
saveUninitialized: true,
resave: true}));

(3)再次启动

[root@centos ~]# node /var/www/html/app.js
Express server listening on port 8888

到此说明report系统部署完毕。。
可以通过访问:http://ip:8888
默认用户:admin 密码:1234567
5 启动脚本

vim /etc/init.d/daily

#!/bin/bash
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network
#chkconfig:345 61 61

#description:daily
RETVAL=0
start()
{
service httpd start 1>/dev/null  2>&1
#!/bin/bash
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network
#chkconfig:345 61 61

#description:daily
RETVAL=0
start()
{
service httpd start 1>/dev/null  2>&1
iptables -F
node /var/www/html/app.js >>/root/report.log &
redis-server /etc/redis.conf    &
echo "The daily system is running..."
}
stop()
{
service httpd stop 1>/dev/null 2>&1
ps -eaf |grep app.js|head -n 1 >/root/soft/daily.id
dailyid=`awk '{print $2}' /root/soft/daily.id`
kill -9 $dailyid
echo "the app.js process is killed"

redisid=`ps -eaf|grep redis|head -n 1|awk -F " " '{print $2}'`
kill -9 $redisid
echo "redis server process is killed"
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "please input start or stop,restart";;
esac
exit $RETVAL
chkconfig --add daily

chkconfig --level 2345 daily on

service daily start 可以启动服务了。
6.监控脚本
vim /root/monitor.sh
#!/bin/bash
#监控进程宕掉。自动启动服务。
proc_name="app.js"
proc_name1="redis-server"
proc_num()                                              # 计算进程数
{
num=`ps -ef | grep $proc_name | grep -v grep | wc -l`
return $num
}
proc_num1()
{
num=`ps -eaf| grep $proc_name1 |grep -v grep|wc -l`
return $num
}
proc_num1
number1=$?
proc_num
number=$?
if [ $number -eq 0 ] || [ $number1 -eq 0 ]
then
/sbin/service daily restart
fi
需要添加到crontab任务中去。
crontab -e
1/* * * * * bash /root/monitor.sh 1>/dev/null 2>&1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  日报系统