innodb的innodb_buffer_pool_size 在32机器上只能最大为2G,这样本来增加内存为了提高速度,受这个限制发挥不出来。听说想到64位的环境可以用超过2G的内存,于是就开始重新部署。 环境: Centos 5.3 64位 Mysql 5.1.33 安装 Centos安装没有什么特别,只是要记得下载64的系统, MYSQL编译安装,对于安装过的人,也是很简单,这里还是把某些过程写一下,以供参考。 安装完Centos后,就按以下步骤操作: 1.换CentOS的yum源 cd /etc/yum.repos.d/ mv CentOS-Base.repo CentOS-Base.repo.bak wget http://blog.s135.com/soft/linux/centos/5.2/CentOS-Base.repo 2.定时校正服务器时钟 yum install ntp #如果ntp已经安装可以略过 crontab -e 加入如下一行: 15 3 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1 3.安装所需的程序 LANG=C yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel 4.下载软件 5.编译安装软件 5.2编译安装mysql 以下内容存为mysql-install.sh /usr/sbin/groupadd mysql /usr/sbin/useradd -g mysql mysql tar zxvf mysql-5.1.33.tar.gz #sphinx安装 cd /opt/software tar zxvf sphinx-0.9.9-rc1.tar.gz -C /opt cd /opt/sphinx-0.9.9-rc1 cp -R /opt/sphinx-0.9.9-rc1/mysqlse /opt/mysql-5.1.33/storage/sphinx cd /opt/mysql-5.1.33 sh BUILD/autorun.sh cd mysql-5.1.33/ ./configure --prefix=/usr/local/webserver/mysql/ --without-debug --without-bench --enable-thread-safe-client --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-charset=latin1 --with-extra-charsets=utf8 --with-plugins=innobase --with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-yicike --enable-local-infile --with-plugins=sphinx --with-plugins=all --with-unix-socket-path=/usr/local/webserver/mysql/sock/mysql.sock make && make install chmod +w /usr/local/webserver/mysql chown -R mysql:mysql /usr/local/webserver/mysql cd ../ 执行(如果不是另存为mysql-install.sh的可以忽略这一步) chmod +x mysql-install.sh ./mysql-install.sh 5.2.1创建MySQL数据库存放目录 mkdir -p /data/mysql/data/ chown -R mysql:mysql /data/mysql/ 5.2.2以mysql用户帐号的身份建立数据表 /usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/data/mysql/data --user=mysql 可能会失败,如果机器里以前安装了mysql,需要将原来的my.cnf名称修改为my.cnf.temp 5.2.3创建my.cnf配置文件 输入以下内容 [client] default-character-set = utf8 port = 3306 socket = /tmp/mysql.sock [mysql] prompt="(\u:www.yicike.com:)[\d]> " no-auto-rehash [mysqld] default-character-set = utf8 user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /usr/local/webserver/mysql datadir = /data/mysql/data open_files_limit = 10240 back_log = 600 max_connections = 1000 max_connect_errors = 6000 table_cache = 614 external-locking = FALSE max_allowed_packet = 32M sort_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 300 thread_concurrency = 8 query_cache_size = 32M query_cache_limit = 2M query_cache_min_res_unit = 2k default-storage-engine = MyISAM default_table_type = MyISAM thread_stack = 192K transaction_isolation = READ-COMMITTED tmp_table_size = 246M max_heap_table_size = 246M long_query_time = 1 log_long_format log-bin = /data/mysql/binlog binlog_cache_size = 4M binlog_format = MIXED max_binlog_cache_size = 8M max_binlog_size = 512M expire_logs_days = 7 key_buffer_size = 256M read_buffer_size = 1M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_max_extra_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover skip-name-resolve master-connect-retry = 10 #slave-skip-errors = 1032,1062,126,1114,1146,1048,1396 server-id = 2 innodb_additional_mem_pool_size = 16M innodb_buffer_pool_size = 8G #由于我的机器是16G innodb_data_file_path = ibdata1:1024M:autoextend innodb_file_io_threads = 4 innodb_thread_concurrency = 8 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 16M innodb_log_file_size = 128M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 innodb_file_per_table = 0 [mysqldump] quick max_allowed_packet = 32M 5.2.4创建管理MySQL数据库的shell脚本 输入以下内容 #!/bin/sh mysql_username="admin" mysql_password="12345678" function_start_mysql() { printf "Starting MySQL...\n" /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf 2>&1 > /dev/null & } function_stop_mysql() { printf "Stoping MySQL...\n" /usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown } function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql sleep 5 function_start_mysql } function_kill_mysql() { kill -9 $(ps -ef | grep 'bin/mysqld_safe' | awk '{printf $2}') kill -9 $(ps -ef | grep 'libexec/mysqld' | awk '{printf $2}') } if [ "$1" = "start" ]; then function_start_mysql elif [ "$1" = "stop" ]; then function_stop_mysql elif [ "$1" = "restart" ]; then function_restart_mysql elif [ "$1" = "kill" ]; then function_kill_mysql else printf "Usage: /data/mysql/mysql {start|stop|restart|kill}\n" fi 加上可执行权限 chmod +x /data/mysql/mysql 5.2.5创建一个具有root权限的用户(admin)和密码(12345678) 启动数据库 /data/mysql/mysql start 通过命令行登录管理MySQL服务器(不用密码) /usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock 创建账号 GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678'; FLUSH PRIVILEGES; 停止数据库 /data/mysql/mysql stop phpmyadmin管理 可能phpmyadmin连接不上mysql,这是由于原来安装了MYSQL,需要修改php.ini,加上以下这个 mysql.default_socket =/tmp/mysql.sock 部署成功。 (责任编辑:IT) |