mysql主从同步配置

2010年4月5日 vi 没有评论

主: 192.168.1.242
从:192.168.1.241

一、设置主库
1、修改主库my.cnf,主要是设置个不一样的id和logbin
[root@viyin.net testsvn]# vi /etc/my.cnf
server-id = 1
log-bin=-bin
2 添加一个复制权限的授权一个帐号
> grant replication slave on *.* to viyin@’192.168.1.%’ identified by ‘viyin.net’;
3 检查创建是否成功
> select user,host from .user;
+——-+————-+
| user | host |
+——-+————-+
| vi | % |
| root | 127.0.0.1 |
| viyin | 192.168.1.% |
| | localhost |
| root | localhost |
| | viyin.net |
+——-+————-+
4 锁主库表
> flush tables with read lock;

5 显示主库信息
> show master status;
+——————+———-+————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+————–+——————+
| -bin.000006 | 1687279 | | |
+——————+———-+————–+——————+
1 row in set (0.00 sec)

6 打包数据库
[root@viyin.net ]# tar zcvf /root/var.tar.gz /usr/local//var
tar: Removing leading `/’ from member names
7 迁移数据
[root@viyin.net ]# scp -P 2222 /root/var.tar.gz 192.168.1.241:/root
root@192.168.1.241′s password:
var.tar.gz 100% 1167KB 1.1MB/s 00:00

二、设置从服务器
1 解包(不是生产环境,俺把/var目录全删了)
2 解锁
> unlock tables;
3 编辑配置文件
#vim /etc/my.cnf
server-id = 2
master-host = 192.168.1.242
master-user = viyin
master-password = viyin.net
master-port = 3306
4 重启
5 在从库上设置同步
设置连接MASTER MASTER_LOG_FILE为主库的File,MASTER_LOG_POS为主库的Position
> slave stop;
> change master to master_host=’192.168.1.242′,master_user=’vi’, master_password=’vivi’,
master_log_file=’-bin.000006′, master_log_pos=1687279;
6、启动从库服务
> slave start;
7 测试
> CREATE TABLE `vi` (
-> `id` INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
-> `username` VARCHAR( 20 ) NOT NULL ,
-> `password` CHAR( 32 ) NOT NULL ,
-> `time` DATETIME NOT NULL ,
-> `number` FLOAT( 10 ) NOT NULL ,
-> `content` TEXT NOT NULL ,
-> PRIMARY KEY ( `id` )
-> ) ENGINE = MYISAM ;
Query OK, 0 rows affected (0.02 sec)

> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.242
Master_User: vi
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: -bin.000006
Read_Master_Log_Pos: 1687606
Relay_Log_File: vi13-relay-bin.000002
Relay_Log_Pos: 578
Relay_Master_Log_File: -bin.000006
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1687606
Relay_Log_Space: 732
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)

ERROR:
No query specified

增加:
#需要备份的库
binlog-do-db=viyin
#忽略的数据库
binlog-ignore-db=
binlog-ignore-db=test
主从上都要设置

svn安装配置,post-commit同步

2010年4月3日 vi 没有评论

1.搭建
yum install  httpd httpd-devel -server php php-devel php-
2.yum安装及所需模块
 yum install httpd subversion mod_dav_svn mod_auth_mysql
centos默认源的版本较老。1.4.2的。yum前。换一个源。(参考:RedHat和CentOs系统下的第三方软件仓库
3.查看版本
[root@abc100 ~]# –version
, version 1.6.9 (r901367)
compiled Mar 22 2010, 00:59:50

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
– handles ‘http’ scheme
– handles ‘https’ scheme
* ra_svn : Module for accessing a repository using the network protocol.
– with Cyrus SASL authentication
– handles ‘’ scheme
* ra_local : Module for accessing a repository on local disk.
– handles ‘file’ scheme
4.确认已安装模块
[root@abc100 modules]# pwd
/etc/httpd/modules
[root@abc100 modules]# ls |grep

mod_dav_svn.so

5.修改httpd.conf配置文件,载入模块
增加

  1. LoadModule dav_svn_module     modules/mod_dav_svn.so
  2. LoadModule authz_svn_module   modules/mod_authz_svn.so
  3. LoadModule php5_module modules/libphp5.so

6.配置

  1. [root@abc100 conf.d]# pwd
  2. /etc/httpd/conf.d
  3. [root@abc100 conf.d]# vi subversion.conf
  4.  
  5. <Location /svn>
  6. DAV svn
  7. SVNPath /var/www/testsvn/
  8. AuthType Basic
  9. AuthName "Authorization Realm"
  10. AuthUserFile /var/www/testsvn/passwd
  11. Require valid-user
  12. </Location>

7.创建版本库
svnadmin create /var/www/testsvn/
chown . /var/www/testsvn/ -R
8.增加用户名密码验证
htpasswd -c /var/www/testsvn/passwd viyin.net

重启apahce后看效果。

8.post-commit(利用的钩子post-commit同步测试服务器代码)

[root@abc100 hooks]# pwd
/var/www/testsvn/hooks

cp post-commit.tmpl post-commit
chown . post-commit

修改post-commint

  1. export LANG="en_US.UTF-8"
  2. svn up /var/www/html/viyin.net/

chmod a+x post-commit

chown -R . /var/www/html/viyin.net (确保web目录能访问,否则post-commit不会正常工作)

co file:///var/www/svn4/ /var/www/0519 检出

nagios不能发送飞信报警一例

2010年4月1日 vi 没有评论

转载自:http://blog.formyz.org/?p=330 感谢作者分享
虽然一直不喜欢移动,但受人之托,勉为其难帮他调试了一下。过程很简单,但其中的技巧却值得拿出来分享,于是就有了这个文章。

问题描述:

(1)以web方式查看监控状态,显示故障,却收不到报警短信。

(2)系统日志出现“Warning: Attempting to execute the command “/usr/local// –mobile=13660600600 –pwd=little228 –to=13909088009 –msg-utf8=”[linux1-CRITICAL] CHECK_NRPE: Socket timeout after 10 seconds. (20:51:12)”” resulted in a return code of 127. Make sure the script or binary you are trying to execute actually exists…”。

情况了解:

该系统管理员说,他用手工方式执行飞信发短信没问题,再切换成用户,也没问题。

处理过程:

(1)登陆该服务器,查看系统日志和日志,果然如此。

(2)查看飞信所在的目录,发现已经被系统管理员设置成777了。

(3)先修改一下他的/etc/sudoers文件,用visudo进去,新增一行“ ALL=NOPASSWD:/usr/local/feiton/feiton”保存。

(4)切换到用户:su –

(5)执行sudo /usr/local/feiton/feiton ,报无lib*.so文件。

(6)这些文件在/usr/local/feiton里呆着呢,先看看/usr/lib里有没有这些。

(7)切换回root,查一下/usr/lib目录,果然没有这些lib*.so。

(8)从这个目录,把这些个lib*.so统统拷贝到/usr/lib目录。

(9)再切换到用户执行sudo /usr/local/feiton/feiton 哈哈,没报错了。

(10)停止一个监控机上的服务,片刻,就发短信了。

对于监控短信报警,还是建议使用短信接口,不行该死的飞信,不能发其他运营商的手机短信。

xen安装配置

2010年3月29日 vi 3 条评论

初次配置,我装了X11和VNCSERVER(vnc配置)。图形界面方便些。

1.安装
# yum -y install *
安装需要的服务
# yum -y install kernel-*
安装管理程序
#yum -y install virt-manager

2.修改/etc/grub.conf ,用内核启动

3.virt-manager管理界面

阅读全文…

freebsd apache

2010年3月27日 vi 没有评论

1.报错: No such file or directory: Failed to enable the ‘’ Accept Filter
载入模块
vivi#kldload accf_http
vivi#kldload accf_data
重启就好了

2.vivi# ./apachectl -k start 无提示,80端口未开

查看日志
vivi# cat /var/log/httpd-error.log
[Sat Mar 27 22:09:46 2010] [alert] (EAI 8)hostname nor servname provided, or not known: mod_unique_id: unable to find IPv4 address of “vivi”

编辑/usr/local/etc/apache22/httpd.conf
注释这行 #LoadModule unique_id_module libexec/apache22/mod_unique_id.so

打开/etc/rc.conf设置:

accf_data_load=”YES”
accf_http_load=”YES”
apache22_enable=”YES”

安装、更新ports

2010年3月27日 vi 没有评论

使用 安装/同步ports 系统
使用不需要事先安装 ports tree,并且能够在任何时候恢复到已知的最新状态(即使手工对ports tree进行了修改)。

第一次使用: fetch extract
以后使用更新: fetch update
放在cron里运行: cron

对比更新 vbs

2010年3月26日 vi 没有评论
  1. Option Explicit
  2.  
  3. sub copyfol(sDir,Ddir)
  4.  'sDiry要对比的文件夹,,Ddir要操作文件夹
  5.    dim fso,fol,fs,f1, objfile
  6.    dim arrFiles(),arrSize(),arrModified()
  7.    dim i
  8.    if right(ddir,1)<>"\" then ddir =ddir & "\"
  9.    if right(sdir,1)<>"\" then sdir =sdir & "\"
  10.    Set fso = CreateObject("Scripting.FileSystemObject")
  11.    '判断文件是否存在
  12.    if not (fso.FolderExists(sdir))  then
  13.        msgbox "找不到文件夹:" & sdir
  14.        exit sub
  15.    end if
  16.    if not (fso.FolderExists(ddir))  then
  17.         msgbox "找不到文件夹:" & sdir
  18.         exit sub
  19.    end if
  20.  
  21.    '获得要操作的文件列表及相关信息并储存到数组
  22.    set fol=fso.GetFolder(ddir)
  23.    set fs=fol.files
  24.    i=0
  25.    redim arrFiles(fs.count-1)
  26.    redim arrSize(fs.count-1)
  27.    redim arrModified(fs.count-1)
  28.    for each f1 in fs
  29.       arrfiles(i)=f1.name
  30.       arrSize(i)=f1.size
  31.       arrModified(i)=f1.DateLastModified
  32.       i=i+1
  33.    next
  34.    '把要操作的文件夹逐一根要对比的文件比较,不同则覆盖,多余就删除,没有就复制
  35.    set fol=fso.GetFolder(sdir)
  36.    set fs=fol.files
  37.    for i = 0 to ubound(arrfiles)
  38.        '文件存在则比较是否相同,否则删除
  39.  
  40.        dim delfile  '要操作类型,
  41.        delfile=false
  42.        for each f1 in fs
  43.            if strcomp(arrfiles(i),f1.name,vbTextCompare)=0 then             
  44.                if arrsize(i)<> f1.size or arrModified(i)<>f1.DateLastModified then
  45.                   fso.copyfile f1.path, ddir & arrfiles(i),true       
  46.                end if
  47.                delfile=true '如果文件存在
  48.                exit for
  49.             end if
  50.         next
  51.         if not delfile then                 
  52.             set objfile=fso.getfile(ddir &arrfiles(i))
  53.             objfile.Delete (true)
  54.          end if         
  55.     next
  56.    '如果对比目录sdir中有文件是要操作目录ddir中没有的,则复制到ddir
  57.    for each f1 in fs
  58.        delfile=false
  59.        for i=0 to ubound(arrfiles)
  60.           if strcomp(f1.name,arrfiles(i),vbtextcompare)=0 then
  61.              delfile=true
  62.              exit for
  63.           end if
  64.         next
  65.          if right (ddir,1)<>"\" then ddir=ddir &"\"
  66.         if not delfile then         
  67.            f1.copy ddir,true
  68.         end if
  69.    next
  70.    '以下代码处理子文件夹 
  71.    dim fols
  72.    set fol=Fso.GetFolder(sdir)
  73.    set fols=fol.SubFolders
  74.    for each f1 in fols
  75.       if not (fso.FolderExists(ddir & f1.name)) then
  76.          fso.CreateFolder(ddir & f1.name)
  77.       end if
  78.       copyfol sdir & f1.name ,ddir & f1.name
  79.    next
  80. end sub
  81.  
  82.    '以下是对比路径 第一个是远程路径 第二个是本地路径
  83. copyfol "c:\viyin.net","C:\www.viyin.net"