The Mirages

樱桃沟夹事

最近有个需求是要在一台机器上同步多个不同机房的数据库,这也是为了备份需求。于是不得不在同一台机器上跑多个mysql slave
运行多个mysql无非就是跑在不同的端口,有的是写多个my.cnf然后写多个mysqld来强制使用不同的数据目录。但是我这个人还是比较懒,还是写在单个my.cnf文件更容易一些。

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
#[client]
#password = your_password
#port = 3306
#socket = /tmp/mysql.sock
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = multi
password = multi
[mysqld1]
port = 3306
socket = /tmp/mysql.sock1
skip-locking
pid-file=/data/mysql/data1/net-app1a.pid
datadir = /data/mysql/data1
log=/data/mysql/data1/net-app1.log
log-slow-queries=/data/mysql/data1/slowquery.log
user = mysql
long_query_time = 1
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
myisam_sort_buffer_size = 64M
thread_cache = 32
query_cache_size = 32M
thread_concurrency = 2
max_connections=1000
server-id = 12
master-host = 192.168.0.101
master-user = repl
master-password = 'repl'
master-port = 3306
report-host = hostname
master-connect-retry = 30
replicate-do-db = aaa
log-bin
log-slave-updates



[mysqld2]
port = 3307
socket = /tmp/mysql.sock2
pid-file = /data/mysql/data2/net-app1b.pid
datadir = /data/mysql/data2
log=/data/mysql/data2/net-app1.log
log-slow-queries=/data/mysql/data2/slowquery.log
user = mysql
long_query_time = 1
key_buffer = 128M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 1M
read_buffer_size = 1M
myisam_sort_buffer_size = 32M
thread_cache = 32
query_cache_size = 16M
thread_concurrency = 2
max_connections=1000
server-id = 13
master-host = 192.168.0.102
master-user = repl
master-password = 'repl'
master-port = 3306
report-host = hostname
master-connect-retry = 30
replicate-do-db = bbb
replicate-do-db = ccc
log-bin
log-slave-updates
```

把mysql这个database复制到data1和data2之中,当然要注意下权限

这样使用/usr/local/mysql/bin/mysqld_multi start 1-2 来启动这里的mysql1和mysql2

但是现在还不能使用/usr/local/mysql/bin/mysqld_multi stop 1-2来关闭mysql1和mysql2,必须添加shutdown权限
```c
mysql -u root -S /tmp/mysqld.sock1 -p
> GRANT SHUTDOWN ON *.* TO 'multi'@'localhost' IDENTIFIED BY 'multi';
mysql -u root -S /tmp/mysqld.sock2 -p
> GRANT SHUTDOWN ON *.* TO 'multi'@'localhost' IDENTIFIED BY 'multi;
```
这样添加了shutdown权限后就可以用上述命令来关闭mysql1和mysql2

对于其它用户必须在添加的时候加上IP地址如 192.168.% 这样的方式,不能使用localhost这个表示方式,如果使用localhost那就必须指定sock来进行访问,就像上面那样的方式。而用IP的方式就是可以使用不同端口来进行登录。
```c
mysql -P 3306 -u rmcore -p
mysql -P 3307 -u rmcore -p

新年寄语
2009年到了,纷乱复杂的2008年过去了,过去的这一年是特别的一年,而对于我来说只是一个开始的1年。
从2008年开始,我终于开始对于自己的人生有了一定的规划。回首2008年初的计划,现在看来只是完成了1/3而已。
2008年这一年中我看了很多书。主要是经济,管理和心理类图书。但是看了很多都没有自己的独立思考,不能真正的融会贯通。所以2009年对于我来说就是把2008年这些学到的东西提出质疑并能最终消化。
2009年另外一个大事情就是准备在北京南站附近买房子。当然价格合适才买,不然坚决不买,所谓价格合适对于我来说就是家庭年收入5倍以内,或者租售比11以内。
2009年最期待的事情是想我的那位从北京接到上海来一起生活1-2年时间,等北京房子装修好,这边办好结婚登记手续后去北京工作生活。
上面都是一些整体上的计划。下面说下工作上的。
在屁屁公司继续安心的呆着,完整搭完自有的智能解析系统,虽然模拟环境中早完成了,但是生产环境中一直没有使用,这次金融危机了,所以要从其它地方切换回自有的环境。
完整规划好那个已有的计划,现在也就计划了2%左右的程度。
学习英文口语,martin是个好榜样。

冬日的5点还是一片漆黑中
头班车有如黑暗中的灯光照射过来
它是如此的早
赶车的每个人似乎都有很着急的事情一般
不然他们也不会赶这个车
农村的广袤土地上
车窗外一片漆黑
只有汽车的车灯照亮着前方
等在车站的人们
当汽车靠近的时候
一种欣喜的感觉透在脸上
来了,终于来了
虽然等待的时候也许很长了

首先需要在新服务器上安装系统,最好是跟原来的被迁移服务器上操作系统相同,这样就省的在新服务器上重新编译系统软件了。但是如果你要从linux迁移到freebsd平台上那真的需要重新编译了。
其次要理清所有需要迁移的服务器上相关域名和系统平台软件,比如apache, nginx, lighttpd, mysql, php, lucent等等,如果相同系统平台,那只需要把相关软件目录打包传到新服务器上就可以了。当然也有个前提是以前安装都要通过–prefix来指定目录,如果默认安装那就会把这些系统软件分散到系统其它目录之中。
再次是迁移程序数据,这些如网站,数据库等等,这些一般是先通过打包再传输到新服务器上,然后在旧服务器上启动rsyncd服务端,然后再在新服务器上通过rsync来同步数据。这样是为了防止漏传输相关数据。
接着是让开发修改相关配置文件,比如修改连接数据库地址等等,但是这些最好在系统hosts里做,这样可以为以后再次迁移节省很多时间。
然后我们需要修改crontab,logrotated等等这些系统配置,特别对于不同系统平台,那更是要修改更多的系统配置文件。
在本地指下hosts来访问网站,如果有时间还可以再次进行压力测试。
关闭原有网站的动态内容,如果有CDN,那让CDN进行强制缓存。然后我们再次同步网站数据,千万别把新的配置文件给覆盖掉。以及同步数据库等等。
最后让重新指下网站的A记录,或者让CDN指向新的源站。

func最近好像热的很。安装也很方便。分为master和client,两端都需要安装func和certmaster

首先是下载func和certmaster


 wget http://download.fedora.redhat.com/pub/epel/5/i386/func-0.21-1.el5.noarch.rpm wget http://download.fedora.redhat.com/pub/epel/5/i386/certmaster-0.20-2.el5.noarch.rpm rpm -ivh certmaster-0.20-2.el5.noarch.rpm rpm -ivh func-0.21-1.el5.noarch.rpm 

master:

然后配置 /etc/certmaster/certmaster.conf 主要是 listen addr = 最好为空,这样你的所有网卡的 51235 都被监听

minion.conf 设置主机名certmaster = www.zauc.com

阅读全文 »

nginx也算是可以根据来源IP来进行负载均衡了。
nginx默认安装就是支持geo模块的。
安装完成后编辑nginx.conf这个主配置文件如下:


 user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; geo $cncip { default 1; #未定义IP的默认为1 include cnc.conf; #包含进cnc.conf文件 } server { listen 80; server_name www3.zauc.com; location / { if ($cncip) { rewrite ^ http://www.baidu.com; #未定义在cnc.conf文件中的IP重定向到www,baidu.com } root /home/zauc/web; index index.wml index.html; } } } 

然后创建cnc.conf文件如下
#192.168.30.0/24 0;
192.168.21.0/24 0;

nginx 的wiki对于这个模块的说明在http://wiki.codemongers.com/NginxHttpGeoModule有粗略的说明。我们可以发现在nginx.conf主控制文件内也可以进行分类。

首先是在一开始定义好


 geo $country { default no; include conf/geo.conf; 127.0.0.0/24 us; 127.0.0.1/32 ru; 10.1.0.0/16 ru; 192.168.1.0/24 uk; } 
阅读全文 »

这个是apache2.2以后增加的新的特性。

首先我们这边有2个域名。一个是www.timo.com还有一个是mail.timo.com这两个域名。同时www.zauc.com内网有2台机器 (192.168.0.10和192.168.0.11),当然也可以是外网.mail.zauc.com这个域名的内网IP为 (192.168.0.20)

要使用proxy和blance一定要在编译的时候加入proxy和blance.


 ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-modules=all --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-vhost-alias make make install

安装完成后在extra/httpd-vhosts.conf中进行如下配置。


 ServerAdmin [email protected] ServerName www.timo.com ProxyPass / balancer://www.timo.com/ ErrorLog "logs/www.timo.com-error_log" CustomLog "logs/www.timo.com-access_log" common
阅读全文 »

首先是下载awstats,这个现在是有中文网站了
解压后后放到/usr/local下
然后运行tools/awstats_configure.pl
按照提示进行配置,主要是网站的名字配置

然后是是nginx进行配置,如果是APACHE或者是IIS就不用这样麻烦了。
首先是配置nginx的日志格式

1
2
3
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';

这个要注意其中的标点和空格。

在nginx上跑awstats需要支持fastcgi和perl才可以
fastcgi这个安装方法很多,一般是编译php5的时候直接放进去就可以了。当然我们现在为了方便就直接使用nginx-fcgi脚本http://www.nginx.eu/nginx-fcgi.html

使用脚本前需要安装下列perl模块

阅读全文 »

cacti本身自带了很多监控插件,如cpu,系统负载,磁盘等等。但是对于一些服务我们就必须另外找插件了。
现在我这边有用到的有nginx, apache, mysql, memcached, iis这几种

先说nginx插件。
http://forums.cacti.net/about26458.html
首先要在被监控服务器的nginx.conf文件中加上如下内容

location /nginx_status { 
  stub_status on;
  # disable access_log if requared 
  access_log off; 
  #allow XX.YY.AA.ZZ;
  #allow YY.ZZ.JJ.CC;
  #deny all;
  }

最后再重启下nginx就可以了。上面内容可以根据自己需求进行更改的。

在监控服务器上

 cp get_nginx_clients_status.pl /scripts/
 cp get_nginx_socket_status.pl /scripts/
 chmod 0755 /scripts/get_nginx_socket_status.pl
 chmod 0755 /scripts/get_nginx_clients_status.pl
阅读全文 »

vsftpd虚拟用户安装手册 目的:所有帐户存在一个文件内,而不是系统内。每个虚拟帐户都可以拥有自己独立的目录 安装过程不说了。

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
#cat vsftpd.conf

# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
listen=YES
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
use_localtime=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=www
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
chroot_local_user=YES
#secure_chroot_dir=/home/pplive/res
guest_enable=YES
guest_username=virtual_user
user_config_dir=/etc/vsftpd_user_conf
user_sub_token=$USER

还需要安装的软件是db4-util,根据各自系统不同来进行安装

首先是建立一个ftp总的帐户

useradd virtual_user -d /home/ftp/ -s /sbin/nologin

vi /etc/vsftpd/vsftpd_login
tom       //用户名
123       //密码

#建立用户数据库
db_load -T -t hash -f vsftpd_login /etc/vsftpd/vsftpd_login.db

#改变文件属性
chmod 600 /etc/vsftp/vsftpd_login.db

建立PAM文件,告诉系统你要使用自己的数据库了)
看看另一个文件vsftpd.pam,它有两行内容:

阅读全文 »
0%