杂记
更新日期:
安装了下虚拟机,并在上面搭了下环境
虚拟机安装
1 orcale 的 VBox 很烂,再一次挂掉,不能忍啊。 卸掉 2 VMWare 还要注册 。。。 溜掉 3 VMWare Player Good
VMWare Player Download Link -> ubuntu iso ->
安装ssh
1 2 3 | sudo apt-get install openssh-server Try: ssh <username>@<remote ip> |
安装monit
主要参考: link1, mmonit doc link
以下来源link1
1 2 3 4 5 6 7 8 | sudo apt-get install monit --- sudo apt-get remove monit /var/monit/monitrc //配置文件 sudo /etc/init.d/monit start sudo /etc/init.d/monit stop sudo /etc/init.d/monit restart |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | ## ## 示例monit配置文件,说明: ## 1. 域名以example.com为例。 ## 2. 后面带xxx的均是举例用的名字,需要根据自己的需要修改。 ## ############################################################################### ## Monit control file ############################################################################### # # 检查周期,默认为2分钟,对于网站来说有点长,可以根据需要自行调节,这改成30秒。 set daemon 30 # 日志文件 set logfile /var/log/monit.log # # 邮件通知服务器 # #set mailserver mail.example.com set mailserver localhost # # 通知邮件的格式设置,下面是默认格式供参考 # ## Monit by default uses the following alert mail format: ## ## --8<-- ## From: monit@$HOST # sender ## Subject: monit alert -- $EVENT $SERVICE # subject ## ## $EVENT Service $SERVICE # ## # ## Date: $DATE # ## Action: $ACTION # ## Host: $HOST # body ## Description: $DESCRIPTION # ## # ## Your faithful employee, # ## monit # ## --8<-- ## ## You can override the alert message format or its parts such as subject ## or sender using the MAIL-FORMAT statement. Macros such as $DATE, etc. ## are expanded on runtime. For example to override the sender: # # 简单的,这只改了一下发送人,有需要可以自己修改其它内容。 set mail-format { from: webmaster@example.com } # 设置邮件通知接收者。建议发到gmail,方便邮件过滤。 set alert userxxx@gmail.com set httpd port 2812 and # 设置http监控页面的端口 use address www.example.com # http监控页面的IP或域名 allow localhost # 允许本地访问 allow 58.68.78.0/24 # 允许此IP段访问 ##allow 0.0.0.0/0.0.0.0 # 允许任何IP段,不建议这样干 allow userxxx:passwordxxx # 访问用户名密码 ############################################################################### ## Services ############################################################################### # # 系统整体运行状况监控,默认的就可以,可以自己去微调 # # 系统名称,可以是IP或域名 check system www.example.com if loadavg (1min) > 4 then alert if loadavg (5min) > 2 then alert if memory usage > 75% then alert if cpu usage (user) > 70% then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert # # 监控nginx # # 需要提供进程pid文件信息 check process nginx with pidfile /var/run/nginx.pid # 进程启动命令行,注:必须是命令全路径 start program = "/etc/init.d/nginx start" # 进程关闭命令行 stop program = "/etc/init.d/nginx stop" # nginx进程状态测试,监测到nginx连不上了,则自动重启 if failed host www.example.com port 80 protocol http then restart # 多次重启失败将不再尝试重启,这种就是系统出现严重错误的情况 if 3 restarts within 5 cycles then timeout # 可选,设置分组信息 group server # 可选的ssl端口的监控,如果有的话 # if failed port 443 type tcpssl protocol http # with timeout 15 seconds # then restart # # 监控apache # check process apache with pidfile /var/run/apache2.pid start program = "/etc/init.d/apache2 start" stop program = "/etc/init.d/apache2 stop" # apache吃cpu和内存比较厉害,额外添加一些关于这方面的监控设置 if cpu > 50% for 2 cycles then alert if cpu > 70% for 5 cycles then restart if totalmem > 1500 MB for 10 cycles then restart if children > 250 then restart if loadavg(5min) greater than 10 for 20 cycles then stop if failed host www.example.com port 8080 protocol http then restart if 3 restarts within 5 cycles then timeout group server # 可选,依赖于nginx depends on nginx # # 监控spawn-fcgi进程(其实就是fast-cgi进程) # check process spawn-fcgi with pidfile /var/run/spawn-fcgi.pid # spawn-fcgi一定要带-P参数才会生成pid文件,默认是没有的 start program = "/usr/bin/spawn-fcgi -a 127.0.0.1 -p 8081 -C 10 -u userxxx -g groupxxx -P /var/run/spawn-fcgi.pid -f /usr/bin/php-cgi" stop program = "/usr/bin/killall /usr/bin/php-cgi" # fast-cgi走的不是http协议,monit的protocol参数也没有cgi对应的设置,这里去掉protocol http即可。 if failed host 127.0.0.1 port 8081 then restart if 3 restarts within 5 cycles then timeout group server depends on nginx |
start和stop的program参数里的命令必须是全路径,否则monit不能正常启动,比如killall应该是/usr/bin/killall。
对于spawn-fcgi,很多人会用它来管理PHP的fast-cgi进程,但spawn-fcgi本身也是有可能挂掉的,所以还是需要用monit来监控spawn-fcgi。spawn-fcgi必须带-P参数才会有pid文件,而且fast-cgi走的不是http协议,monit的protocol参数也没有cgi对应的设置,一定要去掉protocol http这项设置才管用。
进程多次重启失败monit将不再尝试重启,收到这样的通知邮件表明系统出现了严重的问题,要引起足够的重视,需要赶紧人工处理。
安装Chrome
1 2 3 4 | download: google-chrome-stable_current_i386.deb sudo dpkg -i google-chrome-stable_current_i386.deb sudo apt-get install -f |
安装JDK
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | $ getconf LONG_BIT //操作系统位数 32 $ lsb_release -a //操作系统信息 No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.3 LTS Release: 12.04 Codename: precise 1 sudo apt-get purge openjdk* 2 Download : jdk-7u51-linux-i586.tar.gz 3 sudo su 4 mkdir /usr/lib/java 5 cd /usr/lib/java 6 mv ~/Downloads/jdk-7u51-linux-i586.tar.gz . 7 tar xvf jdk-7u51-linux-i586.tar.gz 8 mv jdk1.7.0_51/ java-7-sun 9 vi /etc/environment 10 PATH="/usr/lib/java/java-7-sun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" JAVA_HOME="/usr/lib/java/java-7-sun" CLASSPATH="/usr/lib/java/java-7-sun/lib" 11 source /etc/environment 12 java -version 13 Done |
安装Tomcat
1 2 3 4 5 6 | 1 Download Tomcat 2 vi ~/.bashrc 3 export CATALINA_HOME=<apache-tomcat path> export PATH=$PATH:$CATALINA_HOME/bin 4 Done |
添加Tomcat启动脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # !/bin/bash # Usage: tomcat [start|stop|reload|restart] # export JAVA_HOME= export CATALINA_HOME= export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin export PATH=$PATH:$HOME/bin export BASH_ENV=$HOME/.bashrc export USERNAME="root" case "$1" in start) echo -n "tomcat start: " cd $CATALINA_HOME/bin/ sh startup.sh echo "Done" ;; stop) echo -n "tomcat stop:" cd $CATALINA_HOME/bin/ sh shutdown.sh echo "Done" ;; restart) $0 stop $0 start ;; *) echo "Usage: tomcat [start|stop|reload|restart]" exit 1 esac exit 0 |
monit添加tomcat监听
1 2 3 4 5 6 | check process tomcat with pidfile /var/run/catalina.pid start program = "/etc/init.d/tomcat start" stop program = "/etc/init.d/tomcat stop" if 9 restarts within 10 cycles then timeout if failed url http://127.0.0.1:8080/ timeout 120 seconds for 5 cycles then restart |
catalina.pid
1 2 3 | vi $CATALINA_HOME/bin/catalina.sh Add Line: CATALINA_PID=/var/run/catalina.pid |
1 2 3 4 5 6 7 8 | monit -h
monit -d 30
monit start tomcat || monit start all
monit status
CHECK: http://localhost:2812
monit stop tomcat
|