avatar

目录
LAMP在Centos6.8下的編譯安裝與設置

> LAMP 以下

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

apache-httpd


bash
1
2
3
4
5
6
7
8
9
10
11
> apr环境
# wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
# wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
# tar xf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
# tar xf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install

httpd安装

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.23.tar.gz
# tar xf httpd-2.4.23.tar.gz
# cd httpd-2.4.23
./configure \
--prefix=/usr/local/httpd \
--sysconfdir=/etc \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre \
--with-mpm=event \ #event模型
--with-libxml2 \
--with-zib \
--enable-ssl \
--enable-so \
--enable-mbstring \
--enable-rewrite \
--enable-modules=all \
--enable-mods-shared=all \
--enable-mpms-shared=all \
--enable-cgid \ #event模型中使用cgid
--enable-proxy \ #开启代理支持
--enable-proxy-fcgi #开启代理支持php

--enable-proxy-http \ #开启代理http,一般代理tomcat和其它http协议
--enable-proxy-ajp \ #开启apache二进制传输协议,一般代理tomcat
--enable-proxy-balancer \ #开启代理负载均衡
--enable-lbmethod-heartbeat \ #开启负载均衡心跳检测,以下为心跳检测功能
--enable-heartbeat \ #开启心跳检测
--enable-slotmem-shm \ #
--enable-slotmem-plain \
--enable-watchdog

# make && make install

环境配置

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/httpd/bin
source /etc/profile.d/httpd.sh
vim /etc/man.config
MAN /usr/local/httpd/man
# ln -sv /usr/local/httpd/include /usr/include/httpd


# vim /etc/init.d/httpd
=========================启动脚本开始========================================
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible \
# server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
# implementing the current HTTP standards.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/httpd/bin/apachectl
httpd=${HTTPD-/usr/local/httpd/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo_failure
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
status -p ${pidfile} $httpd > /dev/null
if [[ $? = 0 ]]; then
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
else
echo -n $"Stopping $prog: "
success
fi
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=6
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
# Force LSB behaviour from killproc
LSB=1 killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
if [ $RETVAL -eq 7 ]; then
failure $"httpd shutdown"
fi
fi
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if status -p ${pidfile} $httpd >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac

exit $RETVAL

=============================启动脚本结束=========================================================

# chmod +x /etc/init.d/httpd
# chkconfig --add httpd

配置文件

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# vim /etc/httpd/httpd.conf
注释掉: DocumentRoot "/usr/local/httpd/htdocs"

PidFile "/var/run/httpd.pid"
Include /etc/httpd/extra/httpd-vhosts.conf
Index index.php index.html index.htm

vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName ha1.yzio.com
DocumentRoot "/www/html"
proxyrequest off ; 关掉正向代理,启用反向代理
proxypassmatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/www/html/$1
<directory "/www/html">
options none
AllowOverride none
required all granted
</directory>
Errorlog "/var/log/ha1.yzio.com_error"
CustomLog "/var/log/ha1.yzio.com_access" common
</VirtualHost>

mysql


bash
1
2
3
4
5
> 工作用户、目录准备
# groupadd -g 306 mysql
# useradd -g 306 -u 306 -r -s /sbin/nologin -M mysql
# mkdir /mydata/data
# chown -R mysql.mysql /mydata/data

通用二进制安装

bash
1
2
3
4
5
6
# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz
# tar xf mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz -C /usr/local
# cd /usr/local
# ln -sv mysql-5.7.15-linux-glibc2.5-x86_64 mysql
# cd mysql
# chmod -R mysql.mysql ./*

环境准备

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
# source /etc/profile.d/mysqld.sh
# vim /etc/ld.so.conf.d/mysqld.conf
/usr/local/mysql/lib
# ldconfig
# ldconfig -p | grep mysql
# vim /etc/man.config
MAN /usr/local/mysql/man
# ls -sv /usr/local/mysql/include /usr/include/mysqld
# cp support-files/my.cnf-production /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld

# vim /etc/my.cnf
basedir = /usr/local/mysql
datadir = /mydata/data
innodb_file_per_table = 1
log_bin = master-bin
log_bin_index = master-bin.index
binlog_format = mixed

初始化

bash
1
# bin/mysql --initialize --user=mysql --datadir=/mydata/data --basedir=/usr/local/mysql

查看密码 在初始化过程回显中,或

bash
1
2
3
4
5
# cat /root/.mysql_secret
# mysql -uroot -p
输入上面的默认密码
mysql> SET PASSWORD = PASSWORD('dldkshja');
mysql> SHOW DATABASES;

全库备份

bash
1
# mysql -uroot -p -e "SHOW DATABASES;" | grep -Evi "database|information|performance" | sed -r 's@^([a-z].*$)@mysqldump -uroot -p"dldkshja" -B \1 | gzip > /root/\1.sql.gz@g' | bash &> /dev/null

mysql多实例

编译安装参数

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/data \
-DSYSCONFDIR=/etc -DWITH_SSL=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock





# groupadd -g 306 mysql
# useradd -g 306 -u 306 -r -s /sbin/nologin -M mysql
# mkdir /mydata/{3306,3307}/data -pv
# chown -R mysql.mysql /mydata/

通用二进制安装

bash
1
2
3
4
5
6
# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz
# tar xf mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz -C /usr/local
# cd /usr/local
# ln -sv mysql-5.7.15-linux-glibc2.5-x86_64 mysql
# cd mysql
# chmod -R mysql.mysql ./*

环境准备

bash
1
2
3
4
5
6
7
8
9
10
# vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
# source /etc/profile.d/mysqld.sh
# vim /etc/ld.so.conf.d/mysqld.conf
/usr/local/mysql/lib
# ldconfig
# ldconfig -p | grep mysql
# vim /etc/man.config
MAN /usr/local/mysql/man
# ls -sv /usr/local/mysql/include /usr/include/mysqld

配置mysqld启动脚本

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# vim /mydata/3306/mysqld
#!/bin/bash
# chkconfig: 345 43 57
# description: mysqld-master

. /etc/init.d/functions
port=3306
mysql_user="root"
mysql_pwd="dldkshja"
cmdPath="/usr/local/mysql/bin"
mysql_sock=/mydata/${port}/mysql.sock
conf_file=/mydata/${port}/my.cnf
prog="MySQL"
pid_file=/mydata/${port}/mysql.pid

function start() {
if [ -e "$mysql_sock" ]; then
action "$prog is running..."
exit
else
$cmdPath/mysqld_safe --defaults-file=${conf_file} &> /dev/null &
sleep 5
if [ -e $pid_file ]; then
action "Starting $prog: " /bin/true
else
action "Starting $prog: " /bin/false
fi

fi
}

function stop() {
if [ -e "$mysql_sock" ]; then
$cmdPath/mysqladmin -u$mysql_user -p$mysql_pwd -S ${mysql_sock} shutdown &> /dev/null
action "Stopping $prog" /bin/true
else
action "$prog is stopped..."
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
*)

esac

配置my.cnf配置文件

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# vim /mydata/3306/my.cnf
[client]
port = 3306
socket = /mydata/3306/mysql.sock

[mysql]
no-auto-rehash

[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysqld
datadir = /mydata/3306/data
socket = /mydata/3306/mysql.sock # 本地套接字文件
pid-file = /mydata/3306/mysql.pid # 守护进程号文件
server-id = 1 # 服务序列号
character-set-server = utf8 # 默认服务字符集

innodb_file_per_table = 0 # 关闭innodb数据库单文件存放在磁盘

# 以下为BINLOG
log-bin = /mydata/3306/master-bin # 开启binlog日志
log_bin_index = master-bin.index # binlog日志的索引
binlog_format = mixed # binlog记录格式
expire_logs_days = 7 # binlog日志保存天数
log-slave-updates # 从库做级联日志
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M

# 以下为慢查询LOG
long_query_time = 10 # 最长查询时间,秒
slow_query_log = OFF # 慢查询日志开关
slow_query_log_file = /mydata/3306/data/mysql1-slow.log # 慢查询日志路径
log_queries_not_using_indexes = 1 # 开启记录未使用索引的查询

# 以下为普通查询日志和错误日志,错误日志在[mysqld_safe]内
#general_log = 0 # 关闭普通查询日志
#general_log_file = /mydata/3306/mysql.log # 普通日志路径
#log-error = /mydata/3306/error.log # 错误日志路径

# 以下为查询缓存
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k

slave-skip-errors = 1032,1062,1007 # 从库跳过简单错误

innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_buffer_pool_size = 32M
innodb_data_file_path = idbata1:128M:autoextend
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

relay-log = /mydata/3306/relay-bin # 从库中继日志
relay-log-info-file = /mydata/3306/relay-log.info # 从库中继日志被执行信息日志

read-only # 设置从库不能写入,读写分离用

open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000

external_locking = FALSE
max_allowed_packet = 8M
sort_buffer_size = 1M
join_buffer_size = 1M

thread_cache_size = 100
thread_concurrency = 2
thread_stack = 192k

tmp_table_size = 2M
max_heap_table_size = 2M



key_buffer_size = 16M
read_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names = 1
# skip-name-resolve

# replicate-ignore-db = mysql # 从库忽略的数据库名

# table_cache = 614

# innodb_additional_mem_pool_size = 4M
# innodb_file_io_threads = 4

#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_treads = 1
#myisam_recover
#default_table_type = InnoDB
#transaction_isolation = READ-COMMITTED
#log_long_format

以上两个脚本要修改相应的路径

初始化数据库

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# cd /usr/local/mysql
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/3306/data
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/3307/data

# /mydata/{3306,3307}/mysqld start
# netstat -tnulp | grep 330
tcp 0 0 :::3306 :::* LISTEN 10184/mysqld
tcp 0 0 :::3307 :::* LISTEN 9911/mysqld

# mysql -uroot -p初始化的密码 -S /mydata/3306/mysql.sock
mysql> set password = password('dldkshja')

# mysql -uroot -p初始化的密码 -S /mydata/3307/mysql.sock
mysql> set password = password('dldkshja')

php


bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
> 编译
# wget http://cn2.php.net/distributions/php-5.6.26.tar.gz
# tar xf php-5.6.26.tar.gz
# cd php-5.6.26
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--sysconfdir=/etc \
--enable-fpm \ ;开启php-fpm FastCGI;如php运行为httpd模块则:--with-apxs2=/usr/local/apache/bin/apxs \
--with-libxml-dir \
--with-openssl \
--without-sqlite3 \
--without-pdo-sqlite \
--with-zlib-dir \
--with-pcre-dir \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd \
--enable-sockets \ ;开启套接字方式支持
--enable-mbstring \ ;支持多字符集
--with-zlib \
--with-bz2 \
--enable-zip \
--with-gd \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--enable-maintainer-zts \ ;支持httpd 的 worker、event模型
--with-mcrypt ;支持加密库

# make && make install

环境配置

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# mkdir /etc/php.d
# vim /etc/profile.d/php-fpm.sh
export PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin
# source /etc/profile.d/php-fpm.sh
# vim /etc/ld.so.conf.d/php-fpm.conf
/usr/local/php/lib
# ldconfig
# ldconfig -p | grep php
# vim /etc/man.config
MAN /usr/local/php/man
# ln -sv /usr/local/php/include /usr/include/php

# cp php.ini-producation /etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# cd /usr/local/php/
# cp etc/php-fpm.conf.default etc/php-fpm.conf
# vim etc/php-fpm.conf
pm.max_children = 100
pm.start_servers = 8
pm.min_spare_servers = 2
pm.max_spare_servers = 5

# server php-fpm start

文件配置

bash
1
2
3
4
5
6
7
8
9
10
11
# vim /www/html/index.php
<?php
$conn = mysql_connect('localhost','root','dldkshja');
if ($conn)
echo access...;
else
echo failure...;
mysql_close($conn);

phpinfo();
?>

xcache


bash
1
2
3
4
5
6
7
8
# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
# tar xf xcache-3.2.0.tar.gz
# cd xcache-3.2.0
# phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache
# cp xcache.ini /etc/php.d

# service php-fpm restart

> LAMP 以上

文章作者: l10ng's
文章链接: https://l10ng.github.io/posts/LAMP/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 l10ng's

评论