基于Tengine部署LNMP环境
Tengine-2.0.0
MySQL-5.6.15
Php-5.3.3
CentOS-6.3
源码安装、配置mysql-5.6.15
安装
从5.6开始,mysql用cmake替代了大家熟悉的configure
yum install gcc gcc++ cmake
下载源码。。。
tar zxf mysql-5.6.15.tar.gz
cd mysql-5.6.15
cmake ./ #这样就会安装到/usr/local/mysql/。
make
make install
创建mysql用户,赋予权限
useradd mysql
chown -R mysql.mysql/usr/local/mysql
配置
初始化mysql
cd /usr/local/mysql/scripts
./mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
配置my.cnf(/etc/my.cnf)
[client]
port = 3306
socket = /tmp/mysql5.sock
# Here follows entries forsome specific programs
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /tmp/mysql5.sock
basedir = /usr/local/mysql
datadir =/usr/local/mysql/data
open_files_limit = 10240
server-id = 1
character-set-server = utf8
skip-name-resolve
max_connections = 1000
max_connect_errors = 100000
max_allowed_packet = 512M
max_heap_table_size = 1024M
max_length_for_sort_data =4096
back_log=100
interactive_timeout = 600
wait_timeout = 600
default-storage-engine =InnoDB
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
query_cache_size = 128M
query_cache_limit = 2M
query_cache_min_res_unit =2k
thread_cache_size = 300
table_open_cache = 1024
tmp_table_size = 256M
#*********** Logs relatedsettings ***********
long_query_time = 3
log_output = FILE
slow_query_log = 1
log_queries_not_using_indexes
#*********** MyISAMSpecific options ***********
key_buffer_size = 32M
bulk_insert_buffer_size =64M
myisam_sort_buffer_size =128M
myisam_max_sort_file_size =10G
myisam_repair_threads = 1
myisam_recover
#*********** INNODBSpecific options ***********
innodb_file_per_table
transaction-isolation =READ-COMMITTED
innodb_additional_mem_pool_size= 128M
innodb_buffer_pool_size =10240M
innodb_data_file_path =ibdata1:1024M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency =0
innodb_log_buffer_size =16M
innodb_log_file_size = 256M
innodb_log_files_in_group =2
innodb_flush_log_at_trx_commit= 2
innodb_max_dirty_pages_pct= 80
innodb_lock_wait_timeout =120
innodb_flush_method=O_DIRECT
[mysqldump]
quick
max_allowed_packet = 512M
[mysql]
no-auto-rehash
# Remove the next commentcharacter if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 20M
read_buffer_size = 2M
write_buffer_size = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
编辑启动文件(/etc/init.d/mysqld)
#!/bin/sh
#
# mysqld This shell script takes care ofstarting and stopping
# the MySQL subsystem (mysqld).
#
# chkconfig: - 64 36
# description: MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile:/var/run/mysqld/mysqld.pid
# Source function library.
./etc/rc.d/init.d/functions
# Source networkingconfiguration.
. /etc/sysconfig/network
exec="/usr/local/mysql/bin/mysqld_safe"
prog="mysqld"
# Set timeouts here so theycan be overridden from /etc/sysconfig/mysqld
STARTTIMEOUT=120
STOPTIMEOUT=60
[ -e /etc/sysconfig/$prog ]&& . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
# extract value of a MySQLoption from config files
# Usage: get_mysql_optionSECTION VARNAME DEFAULT
# result is returned in$result
# We use my_print_defaultswhich prints all options from multiple files,
# with the more specificones later; hence take the last match.
get_mysql_option(){
result=`/usr/local/mysql/bin/my_print_defaults "$1" | sed -n"s/^--$2=//p" | tail -n 1`
if [ -z "$result" ]; then
# not found, use default
result="$3"
fi
}
get_mysql_option mysqlddatadir "/usr/local/mysql/data"
datadir="$result"
get_mysql_option mysqldsocket "/tmp/mysql5.sock"
socketfile="$result"
get_mysql_optionmysqld_safe log-error "/d1/data/bj-idc4-proxy51.err"
errlogfile="$result"
get_mysql_option mysqld_safepid-file "/usr/local/mysql/data/bj-idc4-proxy51.pid"
mypidfile="$result"
start(){
[ -x $exec ] || exit 5
# check to see if it's already running
RESPONSE=`/usr/local/mysql/bin/mysqladmin--socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
if [ $? = 0 ]; then
# already running, do nothing
action $"Starting $prog: "/bin/true
ret=0
elif echo "$RESPONSE" | grep -q"Access denied for user"
then
# already running, do nothing
action $"Starting $prog: "/bin/true
ret=0
else
# prepare for start
touch "$errlogfile"
chown mysql:mysql"$errlogfile"
chmod 0640 "$errlogfile"
[ -x /sbin/restorecon ] &&/sbin/restorecon "$errlogfile"
if [ ! -d "$datadir/mysql" ]; then
# First, make sure $datadir isthere with correct permissions
if [ ! -e "$datadir" -a !-h "$datadir" ]
then
mkdir -p "$datadir"|| exit 1
fi
chown mysql:mysql"$datadir"
chmod 0755 "$datadir"
[ -x /sbin/restorecon ] &&/sbin/restorecon "$datadir"
# Now create the database
action $"Initializing MySQLdatabase: " /usr/local/mysql/scripts/mysql_install_db--datadir="$datadir" --user=mysql
ret=$?
chown -R mysql:mysql"$datadir"
if [ $ret -ne 0 ] ; then
return $ret
fi
fi
chown mysql:mysql "$datadir"
chmod 0755 "$datadir"
# Pass all the options determinedabove, to ensure consistent behavior.
# In many cases mysqld_safe wouldarrive at the same conclusions anyway
# but we need to be sure. (An exception is that we don't force the
# log-error setting, since this scriptdoesn't really depend on that,
# and some users might prefer toconfigure logging to syslog.)
# Note: set --basedir to prevent probesthat might trigger SELinux
# alarms, per bug #547485
$exec --datadir="$datadir" --socket="$socketfile" \
--pid-file="$mypidfile" \
--basedir=/usr/local/mysql--user=mysql >/dev/null 2>&1 &
safe_pid=$!
# Spin for a maximum of N secondswaiting for the server to come up;
# exit the loop immediately ifmysqld_safe process disappears.
# Rather than assuming we know a validusername, accept an "access
# denied" response as meaning theserver is functioning.
ret=0
TIMEOUT="$STARTTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
RESPONSE=`/usr/bin/mysqladmin--socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`&& break
echo "$RESPONSE" | grep-q "Access denied for user" && break
if ! /bin/kill -0 $safe_pid2>/dev/null; then
echo "MySQL Daemon failedto start."
ret=1
break
fi
sleep 1
let TIMEOUT=${TIMEOUT}-1
done
if [ $TIMEOUT -eq 0 ]; then
echo "Timeout error occurredtrying to start MySQL Daemon."
ret=1
fi
if [ $ret -eq 0 ]; then
action $"Starting $prog:" /bin/true
touch $lockfile
else
action $"Starting $prog:" /bin/false
fi
fi
return $ret
}
stop(){
if [ ! -f "$mypidfile" ];then
# not running; per LSB standardsthis is "ok"
action $"Stopping $prog:" /bin/true
return 0
fi
MYSQLPID=`cat "$mypidfile"`
if [ -n "$MYSQLPID" ]; then
/bin/kill "$MYSQLPID">/dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
TIMEOUT="$STOPTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
/bin/kill -0"$MYSQLPID" >/dev/null 2>&1 || break
sleep 1
let TIMEOUT=${TIMEOUT}-1
done
if [ $TIMEOUT -eq 0 ]; then
echo "Timeout erroroccurred trying to stop MySQL Daemon."
ret=1
action $"Stopping$prog: " /bin/false
else
rm -f $lockfile
rm -f"$socketfile"
action $"Stopping$prog: " /bin/true
fi
else
action $"Stopping $prog:" /bin/false
fi
else
# failed to read pidfile, probablyinsufficient permissions
action $"Stopping $prog:" /bin/false
ret=4
fi
return $ret
}
restart(){
stop
start
}
condrestart(){
[ -e $lockfile ] && restart || :
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p "$mypidfile" $prog
;;
restart)
restart
;;
condrestart|try-restart)
condrestart
;;
reload)
exit 3
;;
force-reload)
restart
;;
*)
echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?