Rootop 服务器运维与web架构

2013-01-18
发表者 Venus
暂无评论

linux安装mysql5.5.29

话说主从复制老出问题,怀疑是版本问题,想换成最新版本,下载,解压,找configure文件,没找到?正儿八经的,mysql5.5以后开始采用cmake方式安装。大有不同了。

参考官网文档:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

先安装gcc gcc-c++ cmake bison ncurses-devel,下载mysql。

[root@s2 ~]#wget -c http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
[root@s2 ~]#wget -c http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz
[root@s2 ~]#wget -c http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.29.tar.gz

话说从国外下很慢,先用迅雷下载,再传到服务器。

[root@s2 ~]#yum install -y ncurses-devel

安装cmake
[root@s2 cmake-2.8.10.2]# ./configure
[root@s2 cmake-2.8.10.2]# gmake
[root@s2 cmake-2.8.10.2]# make install

安装bison
[root@s2 bison-2.5]# ./configure
[root@s2 bison-2.5]# make
[root@s2 bison-2.5]# make install

安装mysql:
[root@s2 ~]#useradd -s /sbin/nologin networkquestions

[root@s2 mysql-5.5.29]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \              //编译支持所有字符
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=networkquestions \
-DMYSQL_TCP_PORT=3306

[root@s2 mysql-5.5.29]#make

[root@s2 mysql-5.5.29]#make install

安装的时候比较人性化,带百分比。

修改属主
[root@s2 local]# chown -R networkquestions:networkquestions /usr/local/mysql

拷贝配置文件
[root@s2 mysql]# cp /usr/local/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
提供了更多的参考配置,我这里用innodb引擎,内存已经大于4G,采用了my-innodb-heavy-4G.cnf作为参考。

初始化


#./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=networkquestions

Installing MySQL system tables…
OK
Filling help tables…
OK

[root@s2 support-files]# cp mysql.server /etc/init.d/mysqld

[root@s2 support-files]#chmod 755 /etc/init.d/mysqld

到此可以完成,剩余其它配置慢慢调整。

附:
编译的一个报错:
Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found.  Please install appropriate package,
这就是因为没有安装ncurses-devel。
资料说需要加软链接,这里没执行。看看会不会出现问题。
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

2013-01-17
发表者 Venus
暂无评论

Could not parse relay log event entry. The possible reasons are: the master’s binary log is corrupted

mysql主从做复制,从库报错:
130116 18:23:09 [ERROR] Slave: Could not parse relay log event entry. The possible reasons are: the master’s binary log is corrupted (you can check this by running ‘mysqlbinlog’ on the binary log), the slave’s relay log is corrupted (you can check this by running ‘mysqlbinlog’ on the relay log), a network problem, or a bug in the master’s or slave’s MySQL code. If you want to check the master’s binary log or slave’s relay log, you will be able to know their names by issuing ‘SHOW SLAVE STATUS’ on this slave. Error_code: 0

在show slave status\G;中记录下Relay_Master_Log_File、Exec_Master_Log_Pos参数。

Master_Log_File: mysql-bin.000123
Read_Master_Log_Pos: 1059298549
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 405876091
Relay_Master_Log_File: mysql-bin.000123
Exec_Master_Log_Pos: 675697758

shell>stop slave;

重新配置同步,把Exec_Master_Log_Pos的偏移量+1 、Relay_Master_Log_File值不变,以此来作为同步日志名称及偏移量。

同步参考:https://www.rootop.org/pages/1503.html

至于为什么出现这个错误,大多数资料都显示为mysql版本太低,我这里是5.0,同步功能或许真不咋地,而且从库version比主库低!

2013-01-16
发表者 Venus
暂无评论

键盘英文缩写全称及含义

ALT = alter  [‘ɔːltə; ‘ɒl-] 改变

CTRL = control   [kən’trəʊl]控制

Fn = function   [‘fʌŋ(k)ʃ(ə)n] 功能、作用

ec = escape   [ɪ’skeɪp; e-] 逃脱,逃走

tab = tabulator  [‘tæbjʊleɪtə] 做表的人、制表机、跳格键

caps = capitals  [‘kæpətl]  首都、资本、能源、大写字母

shift = shift [ʃɪft] 移动、变化

Numlk = number lock [‘nʌmbə] [lɒk] 数字锁定

Del = delete [dɪ’liːt] 删除

PgUp = page up

PgDn = page down

纯属无聊~~~

2013-01-11
发表者 Venus
暂无评论

修改内核参数提高web服务器性能

      在默认安装的apache中,keepalive部分没有On,每次请求都要建立新的tcp连接,也不能及时的释放连接,增加了很多time_wait的状态并且系统没有重用,apache进程总数比较大,导致默认安装的服务器压力很大,几近假死!

修改内核参数:/etc/sysctl.conf

net.ipv4.tcp_syncookies = 1
开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
net.ipv4.tcp_tw_reuse = 1
允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1
开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。
net.ipv4.tcp_fin_timeout=15
如果套接字由本端要求关闭,此参数决定了它保持在FIN-WAIT-2状态的时间。
net.ipv4.tcp_keepalive_probes=2
TCP发送keepalive探测以确定该连接已经断开的次数。可以设置为5左右
net.ipv4.tcp_keepalive_intvl=2
当探测没有确认时,重新发送探测的频度。可以设置为15左右

对apache加以修改:

KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 2000

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

/proc/sys/net/ipv4下可以看到可以修改的内核参数,不懂的可以直接复制参数名称,google之。