二、) 安装MySQL、memcache

1.) 安装MySQL,步骤如下:

[root@localhost]#tar zxf mysql-standard-5.0.27-linux-i686.tar.gz -C /usr/local/server
[root@localhost]#mv /usr/local/server/mysql-standard-5.0.27-linux-i686 /usr/local/server/mysql
[root@localhost]#cd /usr/local/server/mysql
[root@localhost]#./scripts/mysql_install_db --basedir=/usr/local/server/mysql \
                                --datadir=/usr/local/server/mysql/data --user=nobody
[root@localhost]#cp /usr/local/server/mysql/support-files/my-large.cnf \
/usr/local/server/mysql/data/my.cnf

2.) 修改 MySQL 配置,增加部分优化参数,如下:

[root@localhost]#vi /usr/local/server/mysql/data/my.cnf

主要内容如下:

[mysqld]
basedir = /usr/local/server/mysql
datadir = /usr/local/server/mysql/data
user    = nobody
port    = 3306
socket  = /tmp/mysql.sock

wait_timeout    = 30

long_query_time=1
#log-queries-not-using-indexes = TRUE
log-slow-queries=/usr/local/server/mysql/slow.log
log-error = /usr/local/server/mysql/error.log
external-locking = FALSE

key_buffer_size = 512M
back_log        = 400
table_cache     = 512
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size    = 4M
myisam_sort_buffer_size = 64M
thread_cache_size       = 32
query_cache_limit       = 2M
query_cache_size        = 64M

thread_concurrency      = 4
thread_stack    = 128K
tmp_table_size  = 64M
binlog_cache_size       = 2M
max_binlog_size = 128M
max_binlog_cache_size   = 512M
max_relay_log_size      = 128M
bulk_insert_buffer_size = 8M
myisam_repair_threads   = 1

skip-bdb

#如果不需要使用innodb就关闭该选项
#skip-innodb

innodb_data_home_dir    = /usr/local/server/mysql/data/
innodb_data_file_path   = ibdata1:256M;ibdata2:256M:autoextend
innodb_log_group_home_dir       = /usr/local/server/mysql/data/
innodb_log_arch_dir     = /usr/local/server/mysql/data/
innodb_buffer_pool_size = 512M
innodb_additional_mem_pool_size = 8M
innodb_log_file_size    = 128M
innodb_log_buffer_size  = 8M
innodb_lock_wait_timeout        = 50
innodb_flush_log_at_trx_commit  = 2
innodb_file_io_threads  = 4
innodb_thread_concurrency       = 16
innodb_log_files_in_group       = 3

以上配置参数请根据具体的需要稍作修改。
运行以下命令即可启动 MySQL 服务器:

/usr/local/server/mysql/bin/mysqld_safe \
--defaults-file=/usr/local/server/mysql/data/my.cnf &

由于 MySQL 不是安装在标准目录下,因此必须要修改 mysqld_safe 中的 my_print_defaults 文件所在位置,才能通过 mysqld_safe 来启动 MySQL 服务器。

3.) memcache + libevent 安装
编译安装:

[root@localhost]#cd libevent-1.2a
[root@localhost]#./configure --prefix=/usr/ && make && make install
[root@localhost]#cd ../memcached-1.2.0
[root@localhost]#./configure --prefix=/usr/local/server/memcached --with-libevent=/usr/
[root@localhost]#make && make install

备注:如果 libevent 不是安装在 /usr 目录下,那么需要把 libevent-1.2a.so.1 拷贝/链接到 /usr/lib 中,否则 memcached 无法正常加载。
运行以下命令来启动 memcached:

[root@localhost]#/usr/local/server/memcached/bin/memcached \
-l 192.168.8.1 -d -p 10000 -u nobody -m 128

表示用 daemon 的方式启动 memcached,监听在 192.168.8.1 的 10000 端口上,运行用户为 nobody,为其分配 128MB 的内存。

技术相关: