分类 linux 下的文章

mysql主从同步设置

主从同步配置步骤如下:

环境:MySQL server 5.1.60 64位   CentOS 5.3 64 bit位

一、主服务器配置

编辑主服务器配置文件/etc/my.cnf,如果该文件不存在请执行

 cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

【有关MySQL参数调优不在本文描述】

[mysqld] 加入:

max_connect_errors = 720000
binlog-do-db=DATABASE

检查以下选项:

log-bin=mysql-bin
server-id       = 1
binlog_format=mixed

- 阅读剩余部分 -

libaio.so.1()(64bit) is needed by MySQL-server

从官网下的mysql5.5的server,系统是centos 6.4 x86_64,安装时一直报错:

[root@dbserver opt]# rpm -ivh MySQL-server-5.5.31-2.el6.x86_64.rpm 
error: Failed dependencies:
	libaio.so.1()(64bit) is needed by MySQL-server-5.5.31-2.el6.x86_64
	libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.5.31-2.el6.x86_64
	libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.5.31-2.el6.x86_64

下载MySQL-devel、MySQL-shared-compat、MySQL-shared安装后仍然报错

解决方法:

  安装libaio-0.3.107-10.el6.x86_64.rpm 即可

  下载地址:

  http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm


安装配置Rsync同步

rsync 官网 http://rsync.samba.org/

    rsync 可以安装在*unix 系统上,windows下也有客户端,作者本意是想用写一个可以替代scp的工具。用法上与scp有些类似,但现多用来同步文件和做备份。

    rsync可以在本机目录、本机到远程主机,远程主机到本机之间复制文件,也可以配合定时任务做文件的增量备份。特点是可以保证文件原有的权限、日期等属性,可以保证远程同步的目录内文件内容完全一致。

一、安装

      主从都要安装,主以rsync --daemon 运行为服务器模式,从用rsync 同步

1.1 下载 

wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz

- 阅读剩余部分 -

monit设置邮件频率和短信警报

一、monit 配置邮件发送频率

1.1 增加心跳周期
默认为60s 改为120s,可适当在增加

set daemon  120

1.2 增加进程检测周期
将默认的:

check system 192.168.16.204
if loadavg (1min) > 6  
if loadavg (5min) > 4  
if memory usage > 95%  
if swap usage > 95%      
if cpu usage (user) > 95%
if cpu usage (system) > 95%
if cpu usage (wait) > 95% 

改为如果三次(或更多)都达到警报条件则报警

check system 192.168.16.204
if loadavg (1min) > 6   for 3  cycles then alert
if loadavg (5min) > 4   for 3  cycles then alert
if memory usage > 95%    for 3  cycles then alert
if swap usage > 95%       for 3  cycles then alert
if cpu usage (user) > 95%  for 3 cycles then alert
if cpu usage (system) > 95%  for 3 cycles then alert
if cpu usage (wait) > 95%     for 3  cycles then alert

二、monit发短信警报

2.1 服务器安装curl

yum install curl

查看rpm -qa|grep curl

2.2 发送短信脚本

#!/bin/bash
/usr/bin/curl -s -d api_id=XXXX -d user=XXXX -d  password=**** -d to=86130******** -d "text=$*"  "http://api.clickatell.com/http/sendmsg?"

配置例子:

check host localhost with address 192.168.16.204
if failed port 25 type tcp with timeout 10 seconds for 2 times within 3 cycles then exec "/opt/sendsms localhost 192.168.16.204:25 connect failed!"

当senmail 关掉后 会收到短信:localhost 192.168.16.204:25 connect failed!

安装配置M/monit

Monit 是用于对系统中的进程、文件、目录、以及设备等进行监视和管理的工具。Monit 包含一个内嵌的 HTTP(S) Web 界面,你可以使用浏览器方便地查看 Monit 所监视的服务器。Monit只能监控一台主机是免费的,M/monit可以集中监控多台运行monit的服务器,需要购买授权,但也提供全功能试用一个月。

monit特点:监控配置简单灵活,可以监控项目足够强大,web页面功能强大直观,可以配合外部脚本自动修复工作不正常的程序,官方文档详细
缺点:在实际使用M/monit中发现误报高,受网络环境影响严重,不支持snmp感觉不够主流

一、下载

官方网站:http://www.mmonit.org/
去官网下载 monit和mmonit 的最新版本。
其中 monit为单服务器版本;M/monit 为多服务器版本,但免费用户只能使用一个月,一个月后想继续使用需更新证书

二、monit安装和配置

2.1 安装和启动monit

将下载的安装包解压到/opt,编辑opt/monit/conf/monitrc 文件,配置完成后将其拷贝到etc目录。
运行/opt/monit/bin/monit -t 检查有无语法错误,之后运行 /opt/monit/bin/monit start 启动monit。启动成功会显示 IP+port,若能通过IP+port访问web端,安装成功。
可以运行monit -h 查看参数的帮助文档,常用参数:

 -c file   指定配置文件
 -t   测试配置文件
 reload  重新初始化monit
 status   打印所有监控的服务的完整状态报告
 stop/start

2.2 配置monitrc文件

 set daemon  120    #设置monit作为守护进程运行,每2分钟监视一次
 set logfile syslog facility log_daemon   #设置日志文件
 set idfile /var/.monit.id  #设置id文件
 set statefile /var/.monit.state  #设置状态文件
# set mailserver mail.bar.baz,    # 设置邮件服务器,单用户版要设置,mmonit不需要设置
#                backup.bar.baz port 10025,  # 备份邮件服务器
#                localhost                   #
#set eventqueue      #这个选项是当邮件服务器挂掉时存储警报,稍后发送,一般用不到
#     basedir /var/monit  #存储目录
#     slots 100           # 存储邮件数量
set mmonit http://monit:monit@192.168.1.10:8080/collector   #发送到mmonit  ,在mmonit中要填写这里的用户名和密码,可以设置多个
set mmonit http://monit:monit@192.168.1.11:8080/collector
and register without credentials
set httpd port 2812 and  #设置web访问端口
use address 192.168.11.119  # 本机使用的端口,尽量填写外网ip和public DNS
#   allow 0.0.0.0/0                   #允许访问的ip段
allow 192.168.11.119              #允许访问的ip
allow monit:monit       # 设置页面监控访问的用户名和密码
#    allow @monit           # 允许monit组的用户访问(rw)
#    allow @users readonly  # 允许users组用户访问,只有只读权限
#***************************************************************#
# *****这里写具体要监控的服务******#
#****************常见服务监控见官方例子*********************#

三、M/monit 安装和配置

安装M/monit

1.解压安装包
2.安装mysql数据库
3.简单配置数据库,创建一个数据库mmonit并创建一个对此数据库有所有权的用户

grant all privileges on mmonit.*to  username@‘localhost’ identified by “password”;   

若数据库不在本地,请修改localhost为相应的需要访问的ip地址
4.在M/monit安装目录的db文件夹中将mmonit-schema.mysql 导入上步所创的mmonit数据库

配置M/monit

编辑/mmonit/conf/server.xml文件,进行mmonit的配置

<Connector address=”*” port=”8080″ processors=”10″ />  更改web端口
<Realm url=”mysql://username:password@database’ip:3306/相应database”    其它的数据库连接方式注释掉
    minConnections=”5″
    maxConnections=”250″
    reapConnections=”3000″ />

3.3 启动M/monit

/mmonit/bin/mmonit start

在将monit安装在需要监控的机器上,设置转到mmonit,登陆mmonit就可以看到监控的机器了,设置好monit端的连接用户名密码就可以了。至此就可以通过mmonit的web端进行监控了,web端设置比较简单,这里不多说。
ps:mmonit的web端默认的账号密码为admin swordfish

四、官方文档

http://mmonit.com/wiki/
http://mmonit.com/wiki/Monit/FAQ
http://mmonit.com/documentation/mmonit_manual.pdf
http://mmonit.com/monit/documentation/monit.html
http://mmonit.com/monit/documentation/monit.pdf

linux下安装和配置FastDFS

本文FastDFS安装环境:
centos6.2 64位
GCC
FastDFS 3.06
libevent 2.0.17-stable (FastDFS依赖包)
Tracker Server,Storage Server都安装在一台服务器上,IP:192.168.1.44

一.安装

1.1 准备

FastDFS 安装文件 、libevent 包
官网:


FastDFS :  http://code.google.com/p/fastdfs/
Libevent :   http://libevent.org/

下载:

wget  https://github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz     

1.2安装Libevent

tar -xvf libevent-2.0.17-stable.tar.gz
cd libevent-2.0.17-stable

源码安装

./configure –prefix=/usr  
make clean
make  
make install

1.3 安装FastDFS

tar -xvf FastDFS_v3.06.tar.gz
cd FastDFS
./make.sh    (如果需要HTTP支持,将make.sh中”# WITH_HTTPD=1″的#去掉)
./make.sh install

安装结束 运行 ·/usr/local/bin/fdfs_trackerd· 如果显示

Usage: /usr/local/bin/fdfs_trackerd <config_file>

则安装成功
PS:如果提示找不到libevent-2.0.so.5 则:
1.64位系统

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

32 位系统

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5

2.如果执行上面的ln -s 操作仍然提示找不到libevent-2.0.so.5 则删除

/usr/lib(64)/libevent-2.0.so.5执行下面的操作

64位

cp /opt/libevent-2.0.17-stable/.libs/libevent-2.0.so.5 /usr/lib64/

32位

cp /opt/libevent-2.0.17-stable/.libs/libevent-2.0.so.5 /usr/lib/

二.配置

FastDFS的配置文件在%解压目录%/conf目录下(本例中安装成功后会在/etc/fdfs/下自动生成),其中包括

Client.conf                客户端上传配置文件
Storage.conf    文件存储服务器配置文件
Tracker.conf    负责均衡调度服务器配置文件
http.conf          http服务器配置文件

配置文件需要根据服务器环境的不同,进行不同的配置,具体可以参考FastDFS官方的安装配置文档
http://code.google.com/p/fastdfs/wiki/Setup
以及FastDFS原理介绍文档
http://code.google.com/p/fastdfs/wiki/Overview
在本例中,Tracker Server,Storage Server都安装在一台服务器上,IP:192.168.1.44

2.1 配置及启动Tracker Server

A、修改/etc/fdfs/tracker.conf文件,修改如下
可以自己指定目录位置,但目录必须存在,用于存储日志及storage server等信息,否则tracker server无法启动

base_path=/home/yuqing/fastdfs -> base_path=/fastdfs/fastdfs_tracker   

改成你想要的http端口,将来http下载文件的端口就是他了,本例中没有更改还是用8080

http.server_port=8080 -> http.server_port=8090   

http支持

##include http.conf -> #include http.conf   

默认4GB,如果空间不足,建议调小,否则会报no free space的异常,无法正常启动,本例没有改,仍为4GB

reserved_storage_space = 4GB -> reserved_storage_space = 1GB    

tracker server对storage server供服务的端口,使用默认的即可,也可以自定义 本例中使用默认

port=22122  

B、将http.conf文件拷贝到/etc/fdfs目录下,(确保/etc/fdfs下有httpd.conf文件)执行

cp %解压目录%/conf/http.conf /etc/fdfs/  

注:为了支持http,必须将这个文件拷贝到此目录,否则无法启动,报param http.XXX not exist or is empty类似的错误
C、进入/usr/local/bin/目录,启动tracker服务器,执行


/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

D、查看进程和日志

ps -ef 查看进程,如果有进程则看日志是否有错误

进入/fastdfs/fastdfs_tracker/logs/trackerd.log查看tracker的启动日志,如果看到类似
则tracker server已经启动成功!

2.2 配置及启动Storage Server

A、修改/etc/fdfs/storage.conf文件,修改如下:
可以自定义,但必须存在此目录,用于存储storage相关的log、group内的相关信息

base_path=/home/yuqing/fastdfs -> /fastdfs/fastdfs_storge

文件的存储位置,在一台storage server上可以指定多个存储位置

store_path0=/home/yuqing/fastdfs -> store_path0=/fastdfs/fastdfs_storge/storge1
store_path0=/fastdfs/fastdfs_storge/storge2

必须指定group name

group_name=group1  

修改成tracker server的IP和端口信息

tracker_server=192.168.209.121:22122 -> tracker_server=192.168.1.44:22122
http支持

##include http.conf ->#include http.conf

B、启动storage服务器,执行

/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

如无意外应该看到下图
C、验证进程和查看日志

ps -ef验证进程之后more /fastdfs/fastdfs_storge/logs/storaged.log查看storage服务器启动日志,如果看到类似
则storage server已经启动成功!

3.验证及使用

经过前面的安装、配置、启动,马上就可以看到FastDFS的效果了,我们先上传一个文件,然后再通过http下载。

3.1 上传文件

FastDFS安装包中,自带了客户端程序,通过程序可以进行文件上传。在使用这个客户端程序之前,首先需要配置client.conf,然后再进行文件上传及下载。
1、修改/etc/fdfs/client.conf文件,修改如下:
可自定义,但此目录必须存在,用于存放文件上传log

base_path=/home/yuqing/fastdfs-> base_path=/fastdfs/fastdfs_client

改tracker的ip


tracker_server=192.168.0.197:22122->tracker_server=192.168.1.44:22122

改端口,本例没有改

http.tracker_server_port=8080 ->http.tracker_server_port=8090

支持http

##include http.conf ->#include http.conf

2、上传文件
先创建一个名为aaa的文件 touch /tmp/aaa
之后执行


/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/aaa

如果命令行反馈类似如下:

出现file url 则说明上传文件成功。

3.2下载文件

可以用默认客户端也可以自己集成,用自带默认客户端 在编译时要开启http支持,并在storage.conf、 tracker.conf 中开启http 支持,本文用默认客户端。
在浏览器中,输入上图中的url地址, tracker server会自动重定向到存储文件的storage server,文件下载成功。
至此,已经成功搭建了FastDFS

ps : 通过上传下载文件验证功能比较麻烦,Fastdfs 有提供一个叫fdfs_monitor的工具可以查看fastdfs的详细工作状态,如果工作不正常会提示有错误,例如:

1.查看storage的工作状态:fdfs_monitor  /etc/fdfs/storage.conf
2.查看fastdfs的工作状态 :fdfs_monitor  /etc/fdfs/client.conf
查看tracker的工作状态和第2步是一样的,不能用fdfs_monitor /etc/fdfs/tracker.conf 来查看,否则会报错.
根据已上步骤的shell脚本见:   http://opswill.com/articles/how-to-install-and-configure-fastdfs-tracker-and-storage.html

4.参考文档
官网 http://code.google.com/p/fastdfs/
官方论坛 http://bbs.chinaunix.net/forum-240-1.html(有配置文件详解)
http://blog.csdn.net/poechant/article/details/6995697

tomcat安装godaddy的ssl安全证书

godaddy有三种ssl证书: 1.单个域名 2.多域名ucc证书 3.单域名无限子域名 wildcard证书
我用的是第二种支持5个域名ucc证书,原本只有一个域名,想在加一个域名测试用.服务器端是tomcat 6

注意:新加域名会让当前证书在24小时内生效,如果是生产环境一定要小心

一、添加新域名

login godaddy ----->My account----> SSL CERTIFICATES---->Launch
选中要加子域名的common name ----> manage ----> 在New Subject Alt Name加入新域名,CSR可以不写

二、生成keystore和csr

由于我删除了原来的keystore 和 csr,所以重新生成一下,如果你没有删除只要直接导入新证书就可以了

keytool -keysize 2048 -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore

按照提示来就可以了,注意 First and Last Name只要填common name就可以了
生成csr 文件

keytool -certreq -keyalg RSA -alias tomcat -file csr.csr -keystore tomcat.keystore

三、更新csr文件

  将csr.csr的内容复制一下,到godaddy的面板里,选中common name 之后点击re-key,粘贴上新生成的csr,之后下载新生成的证书文件

四、导入新的证书

之前按照网上的教程说官方的教程里有错误,导入根证书的时候要下载alicert_class2_root.crt 导入,根据我的实践如果是单个域名,导入valicert_class2_root.crt是没问题的.但是如果你的ucc下有多个域名,就要按照官方的教程来,下载gd-class2-root.crt导入

官方下载的zip包里有三个文件 gd_bundle.crt gd_intermediate.crt 和 YourCommonName.crt
我们要导入的三个文件是 gd-class2-root.crt  gd_intermediate.crt YourCommonName.crt

  开始导入:

keytool -import -alias root -keystore tomcat.keystore -trustcacerts -file gd-class2-root.crt

这里会提示有 system-wide的CA是否要覆盖,一定要输入yes

keytool -import -alias intermed -keystore tomcat.keystore -trustcacerts -file gd_intermediate.crt

keytool -import -alias tomcat -keystore tomcat.keystore -trustcacerts -file <name of your certificate>

五、配置Tomcat

编辑tomcat目录下tomcat/conf/server.xml 找到配置ssl的地方修改为

<Connector port="8443"  minSpareThreads="5" maxSpareThreads="75"
      enableLookups="true" disableUploadTimeout="true"
      acceptCount="100"  maxThreads="200"
      scheme="https" secure="true" SSLEnabled="true"
      clientAuth="false" sslProtocol="TLS"
      keystoreFile="/opt/membership-apache-tomcat-6.0.36/server2.keystore"
      keystorePass="PASSWORD"/>

要修改 keystoreFile的路径和PASSWDOD为你第二步生成keystore所在的路径和生成证书时输入的密码
重启tomcat生效.最后可以用godaddy提供的ssl检查工具来检查是否安装成功

六、参考文章

http://support.godaddy.com/help/article/5239/generating-a-csr-and-installing-an-ssl-certificate-in-tomcat-4x5x6x?pc_split_value=4

fastdfs 自动安装配置脚本

在服务器上翻出来之前写的一个FastDFS的安装脚本,功能:

自动安装FastDFS的tracker和storage
自动配置(基本上是默认配置)
FastDFS 的版本为3.08 现在已经不是最新的推荐版本了,需要的自己改脚本里的链接.

此脚本根据我之前写的一篇文章编写:
http://opswill.com/articles/how-to-install-and-configure-fastdfs-tracker-and-storage.html

#!/bin/bash
if [ $UID -ne 0 ];then
    echo "please run this script as root "
else
cat << menu
1) Install
2) Unistall
menu
    echo -n "please enter your choice:"
read  choice
case "$choice" in
    1)
           
echo "************************************************************"
echo " This script will auto install FastDFS tracker and storage"
echo " And configure it automantic,tracker and storage will install localhost"
echo " Notice that the conf files are located in /etc/fdfs"
echo " The main programs locate in /usr/local/bin/fdfs_*"
echo "libevent version: 2.0.17    FastDFS version: 3.08"
echo "************************************************************"
           
read -s -n 1 -p "press a key to continue ..."
   
patform=`uname -i`
IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
echo -e "\e[1;31m preparing the packages.......\e[0m"
    rm -rf libevent-2.0.17-stable.tar.gz
    rm -rf FastDFS_v3.08.tar.gz
    yum check-update
           
echo -e "\e[1;31m install gcc etc .......\e[0m"
    yum -y install gcc gcc-c++ glib2 glib2-devel make
echo -e "\e[1;31m download and install  libevent .......\e[0m"
    wget  http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
    tar -xvf libevent-2.0.17-stable.tar.gz && cd libevent-2.0.17-stable && ./configure --prefix=/usr && make clean && make && make install
    cd ../ && rm -rf libevent-2.0.17-stable libevent-2.0.17-stable.tar.gz
           
    if [ $patform='x86_64' ];then
            if [ -e /usr/lib/libevent-2.0.so.5 ];then
                    ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
            fi
    fi
echo -e "\e[1;31m download fastdfs......\e[0m"
    wget http://fastdfs.googlecode.com/files/FastDFS_v3.08.tar.gz
    tar -xvf FastDFS_v3.08.tar.gz && cd FastDFS && ./make.sh  && ./make.sh  install
    cd ../ && rm -rf FastDFS_v3.08.tar.gz FastDFS
echo -e "\e[1;31m configure Fastdfs tracker server.......\e[0m"
mkdir -p /var/fastdfs/tracker
mkdir -p /var/fastdfs/storage
mkdir -p /var/fastdfs/data
    sed -i 's/reserved_storage_space = 4GB/reserved_storage_space = 1GB/' /etc/fdfs/tracker.conf
    sed -i 's#base_path=/home/yuqing/fastdfs#base_path=/var/fastdfs/tracker#' /etc/fdfs/tracker.conf
echo -e "\e[1;31m start fastdfs tracker.......\e[0m"
    /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
echo -e "\e[1;31m configure Fastdfs storage server.......\e[0m"
    sed -i 's#base_path=/home/yuqing/fastdfs#base_path=/var/fastdfs/storage#' /etc/fdfs/storage.conf
    sed -i 's#store_path0=/home/yuqing/fastdfs#store_path0=/var/fastdfs/data#' /etc/fdfs/storage.conf
    sed -i 's/tracker_server=192.168.209.121:22122/tracker_server='$IP':22122/' /etc/fdfs/storage.conf
    /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
echo -e "\e[1;31m install and start service finish!,please check it\e[0m"
            ;;
    2)
            killall fdfs_trackerd
            killall fdfs_storaged
            rm -rf /var/fastdfs/tracker /var/fastdfs/storage
            rm -rf /usr/local/bin/fdfs_* /usr/local/bin/stop.sh /usr/local/bin/restart.sh /etc/fdfs/
            echo -e "\e[1;31m Unistall Finished \e[0m"
            ;;
    *)
            echo -e "\e[1;31m input error,please run this script again\e[0m"
            exit 0;
            ;;
esac
fi

最新文章

最近回复

分类

归档

统计

  • 文章总数:168篇
  • 分类总数:5个
  • 评论总数:103条
  • 页面总数:172个
  • 本站运行:4885天

其它