Rootop 服务器运维与web架构

2013-08-30
发表者 Venus
暂无评论

mysql独立表空间

修改my.cnf ,添加:

innodb_file_per_table = 1

重启mysql服务。

MyISAM引擎,这种引擎的数据库会分别创建三个文件:表结构、表索引、表数据空间。我们可以将某个数据库目录直接迁移到其他数据库也可以正常工作。

InnoDB 默认会将所有的数据库InnoDB引擎的表数据存储在一个共享空间中:ibdata1,增删数据库的时候,ibdata1文件不会自动收缩,单个数据库的备份也将成为问题。通常只能将数据使用mysqldump 导出,然后再导入解决这个问题。

在MySQL的配置文件[mysqld]部分,增加innodb_file_per_table参数。

独立表空间:

1. 每个表都有自已独立的表空间。
2. 每个表的数据和索引都会存在自已的表空间中。
3. 可以实现单表在不同的数据库中移动。
4. 空间可以回收(除drop table操作处,表空不能自已回收)

2013-08-27
发表者 Venus
暂无评论

linux下subversion及客户端安装配置

redhat中自带subversion,yum安装即可:
[root@rhel ~]# yum install -y subversion

创建仓库,存放配置文件及代码:
[root@rhel ~]# mkdir /mnt/svn

生成仓库信息:
[root@rhel ~]# svnadmin create /mnt/svn/

[root@rhel ~]# cd /mnt/svn/
[root@rhel svn]# ll -a
总计 72
drwxr-xr-x 7 root root 4096 08-27 10:20 .
drwxr-xr-x 4 root root 4096 08-27 10:19 ..
drwxr-xr-x 2 root root 4096 08-27 10:20 conf
drwxr-xr-x 2 root root 4096 08-27 10:20 dav
drwxr-sr-x 5 root root 4096 08-27 10:20 db
-r–r–r– 1 root root    2 08-27 10:20 format
drwxr-xr-x 2 root root 4096 08-27 10:20 hooks
drwxr-xr-x 2 root root 4096 08-27 10:20 locks
-rw-r–r– 1 root root  229 08-27 10:20 README.txt

会看到conf文件夹,存放配置文件,db文件夹存放代码,代码以数据库文件类型保存,而不是以源码树方式保存。

首先配置svnserve.conf:

anon-access = none   //改为none
auth-access = write    //默认,去掉前面注释
password-db = passwd   //认证文件
authz-db = authz   //权限设置realm = NQ’s Repository    //登陆时的提示信息

保存退出,编辑passwd文件,添加用户:

[users]
# harry = harryssecret
# sally = sallyssecret
nq = networkquestions    //用户名+密码

保存退出,编辑authz:

[groups]
# harry_and_sally = harry,sally

# [/foo/bar]
# harry = rw
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
[/]
nq = rw
    //nq 对根目录有读写权限

启动svn:
[root@rhel conf]# svnserve -d -r /mnt/svn/       // -d 启动守护进程,占用tcp协议的3690端口  -r 以/mnt/svn做为根目录

[root@rhel conf]# lsof -i:3690
COMMAND   PID USER   FD   TYPE DEVICE SIZE NODE NAME
svnserve 3428 root    3u  IPv6  14097       TCP *:svn (LISTEN)

可以看到已经启动,编辑iptables,开放3690端口:
[root@rhel ~]# vi /etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -p tcp –dport 3690 -j ACCEPT
重启iptables。

客户端配置:
windows下最常用的就是TortoiseSVN这个客户端。安装好后会集成到右键菜单里。
在合理的路径下创建文件夹(svn)存放代码。右键,选择 SVN checkout 检出。

输入svn服务器地址,格式:svn://192.168.1.137

用户名密码  (可以勾选记住密码)

检出成功

创建的文件夹变为绿色勾

在windows下新建页面,更新到svn服务器中。右键,选择Commit,更新即可。

提交成功。

设置svn更新时自动提交到web目录
在svn库中有个hooks目录,用来触发条件的。
[root@localhost ~]# cd /mnt/svn/hooks/
[root@localhost hooks]# ll
总用量 40
-rwxrwxrwx. 1 root root   94 3月   7 21:18 post-commit
-rw-r--r--. 1 root root 1977 3月   4 22:58 post-commit.tmpl
-rw-r--r--. 1 root root 1638 3月   4 22:58 post-lock.tmpl
-rw-r--r--. 1 root root 2289 3月   4 22:58 post-revprop-change.tmpl
-rw-r--r--. 1 root root 1567 3月   4 22:58 post-unlock.tmpl
-rw-r--r--. 1 root root 3426 3月   4 22:58 pre-commit.tmpl
-rw-r--r--. 1 root root 2410 3月   4 22:58 pre-lock.tmpl
-rw-r--r--. 1 root root 2786 3月   4 22:58 pre-revprop-change.tmpl
-rw-r--r--. 1 root root 2100 3月   4 22:58 pre-unlock.tmpl
-rw-r--r--. 1 root root 2780 3月   4 22:58 start-commit.tmpl
[root@localhost hooks]# cat post-commit   //提交后触发
#!/bin/sh
DEST_DIR=/var/www/html
svn update $DEST_DIR --username nq --password networkquestions
exit 
[root@localhost hooks]# chmod 777 post-commit

可以实现客户端commit代码时,提交到svn库中同时提交到web目录。

2013-08-25
发表者 Venus
暂无评论

MySQL主从复制数据不一致的办法部分原因

1.网络的延迟

由于mysql主从复制是基于binlog的一种异步复制,通过网络传送binlog文件,理所当然网络延迟是主从不同步的绝大多数的原因,特别是跨机房的数据同步出现这种几率非常的大,所以做读写分离,注意从业务层进行前期设计。

2.主从两台机器的负载不一致

由于mysql主从复制是主数据库上面启动1个io线程,而从上面启动1个sql线程和1个io线程,当中任何一台机器的负载很高,忙不过来,导致其中的任何一个线程出现资源不足,都将出现主从不一致的情况。

3.max_allowed_packet设置不一致

主数据库上面设置的max_allowed_packet比从数据库大,当一个大的sql语句,能在主数据库上面执行完毕,从数据库上面设置过小,无法执行,导致的主从不一致。

4.key自增键开始的键值跟自增步长设置不一致引起的主从不一致。

5.mysql异常宕机情况下,如果未设置sync_binlog=1或者innodb_flush_log_at_trx_commit=1很有可能出现binlog或者relaylog文件出现损坏,导致主从不一致。

6.mysql本身的bug引起的主从不同步。

7.版本不一致,特别是高版本是主,低版本为从的情况下,主数据库上面支持的功能,从数据库上面不支持该功能。

以上就是常见的一些主从不同步的情况。或许还有其他的一些不同步的情况,请说出你所遇到的主从不一致的情况。

基于以上情况,先保证max_allowed_packet、自增键开始点和增长点设置一致,再者牺牲部分性能在主上面开启sync_binlog,对于采用innodb的库,推荐配置下面的内容

代码如下 复制代码

1、innodb_flush_logs_at_trx_commit = 1
2、innodb-support_xa = 1 # Mysql 5.0 以上
3、innodb_safe_binlog      # Mysql 4.0

同时在从数据库上面推荐加入下面两个参数

1、skip_slave_start
2、read_only

通过第三方工具校验一致性及同步参考:https://www.rootop.org/pages/3300.html

2013-08-23
发表者 Venus
暂无评论

windows下利用7-zip打包压缩为tar.gz

下载地址:http://7-zip.org/   国内可能有时无法访问,可以从国内网站上下载。

压缩文件夹:

安装完成后,7-zip集成到右键菜单里。

比如test文件夹,在test上 右键-> 7-zip -> add to archive -> Archive format: 选为tar ,其它不变,开始打包,打包完文件名变为test.tar
在 test.tar 上 右键 -> 7-zip -> add to archive -> Archive format: 选为gzip,其它不变,开始压缩,压缩完文件名变为 test.tar.gz
这样就可以往linux服务器传了。