1、mariadb:mysql的一个分支,从5.5后开始发布10.0.0的版本,由于mariadb是免费的,目前而言会是发展趋势:
mariadb的安装如下:基本和mysql的安装类似:
1:下载这个包:(由于地址在国外,下载会慢一些:)
[root@localhost_002 src]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
2:解压:
[root@localhost_002 src]# tar -zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
3:修改名称并挪目录:
[root@localhost_002 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
4:初始化mariadb: --user=mysql --datadir=/data/mariadb --basedir=/usr/local/mariadb(程序目录)
[root@localhost_002 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
5:拷贝配置脚本:(根据内存大小来选择不同的配置脚本)
[root@localhost_002 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
#由于mysql的已经放在/etc/my.cnf下,本次我们放在(程序目录)/usr/local/mariadb/my.cnf
[root@localhost_002 mariadb]# ls support-files/ #内存小可以选择small.再调整相关参数:
my-huge.cnf my-large.cnf my-small.cnf mysql-log-rotate
5:拷贝启动脚本:
[root@localhost_002 mariadb]# cp support-files/mysql.server / etc/init.d/mariadb
[root@localhost_002 mariadb]# chkconfig --add mariadb
修改配置文件:/usr/local/mariadb/my.cnf 主要修改[mysqld]那一部分即可:
[root@localhost_002 mariadb]# cat /usr/local/mariadb/my.cnf |grep -A10 'mysqld'
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
修改启动脚本:/etc/init.d/mariadb 需要指定confv:在启动start下面指定: --defaults-file="$conf"
[root@localhost_002 mariadb]# cat /etc/init.d/mariadb |grep -v '^#'|grep -v '^$'
basedir=/usr/loca/mariadb #指定程序目录:
datadir=/data/mariadb #至山顶数据库目录:
conf=$basedir/my.cnf #指定配置文件的位置:
#不过还需要在启动脚本下面指定conf: --defaults-file=“$conf”
case "$mode" in
'start')
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $basedir
echo $echo_n "Starting MySQL"
if test -x $bindir/mysqld_safe
then
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
wait_for_ready; return_value=$?
注释:如果是只安装mariadb,则完全可以定义到/etc/my.cnf下,则不需要在配置脚本写conf及其变量了:
6:启动mariadb:
[root@localhost_002 ~]# /etc/init.d/mariadb start
Starting mariadb (via systemctl): [ 确定 ]
[root@localhost_002 ~]# ps aux |grep mariadb
root 1285 0.1 0.1 115388 1752 ? S 21:51 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/localhost_002.pid
mysql 1401 3.8 5.9 1125056 59908 ? Sl 21:51 0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/localhost_002.err --pid-file=/data/mysql/localhost_002.pid --socket=/tmp/mysql.sock --port=3306
root 1437 0.0 0.0 112676 984 pts/0 R+ 21:51 0:00 grep --color=auto mariadb
[root@localhost_002 ~]#
详细安装命令如下:
下载mariadb包:
[root@localhost_002 src]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
[root@localhost_002 src]# tar -zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz #解压:
[root@localhost_002 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb #挪目录:
[root@localhost_002 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
#初始化mariadb:
[root@localhost_002 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
#拷贝配置脚本:
[root@localhost_002 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
#拷贝启动脚本:
[root@localhost_002 mariadb]# vim /etc/init.d/mariadb
basedir=/usr/loca/mariadb
datadir=/data/mariadb
conf=$basedir/my.cnf
#不过还需要在启动脚本下面指定conf: --defaults-file=“$conf”
case "$mode" in
'start')
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $basedir
echo $echo_n "Starting MySQL"
if test -x $bindir/mysqld_safe
then
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
wait_for_ready; return_value=$?
#修改启动脚本:
[root@localhost_002 ~]# /etc/init.d/mariadb start
注释:有时候启动mariadb后,用ps查看发现datadir=/data/mysql,我们已经自定义在启动脚本里定义到/data/mairadb下,为什么还会显示:
[root@localhost_002 ~]# /etc/init.d/mariadb start
Starting mariadb (via systemctl): [ 确定 ]
[root@localhost_002 ~]# ps aux |grep mariadb
root 1285 0.1 0.1 115388 1752 ? S 21:51 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/localhost_002.pid
mysql 1401 3.8 5.9 1125056 59908 ? Sl 21:51 0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/localhost_002.err --pid-file=/data/mysql/localhost_002.pid --socket=/tmp/mysql.sock --port=3306
---------------
这是因为调用了/etc/my.cnf的配置文件,因为我们在/usr/local/mariadb/my.cnf里未定义这个选项,所以去/etc/my.cnf里找了:解决方法:
可以注释掉/etc/my.cnf里的datadir:
可以去mariadb的配置文件(/usr/loca/mariadb/my.cnf)里添加datadir = /data/mariadb:
cat /usr/local/mariadb/my.cnf |grep -v ^# |grep -v ^$
[mysqld]
datadir = /data/mariadb
port = 3306
socket = /tmp/mysql.sock
然后再次重启:
[root@localhost_002 ~]# killall mysqld #停止掉这个服务:
[root@localhost_002 ~]# !ps
ps aux |grep mariadb
root 1497 0.0 0.0 112676 984 pts/0 R+ 22:12 0:00 grep --color=auto mariadb
[root@localhost_002 ~]# /etc/init.d/mariadb start
Starting mariadb (via systemctl): [ 确定 ]
[root@localhost_002 ~]# !ps
ps aux |grep mariadb
root 1523 0.6 0.1 115388 1756 ? S 22:12 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/localhost_002.pid
mysql 1642 9.3 5.4 1125024 54528 ? Sl 22:12 0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/localhost_002.err --pid-file=/data/mariadb/localhost_002.pid --socket=/tmp/mysql.sock --port=3306
root 1678 0.0 0.0 112676 984 pts/0 R+ 22:12 0:00 grep --color=auto mariadb
[root@localhost_002 ~]#
2、Apache是一个基金会的名字,从2.0开始改名到httpd了,httpd才是我们要安装的包,早起它的名字就叫Apache,apr和apr-util是一个通用的函函数库,它让httpd可以不关心底层的操作平台,可以很方便的移植(从linux到windows):www.apache.com
httpd2.2和2.4所依赖的apr通用库不同,由于今天安装的httpd2.4版本,所以Centos自带的yum安装的apr无法使用,需要自己手动编译:
1、首先下载httpd安装包和apr apr-util的二进制包:
httpd下载: wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.34.tar.gz
apr下载: wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
apr-util下载: wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz #安装是依赖apr:
1:编译安装apr及apr-util:
[root@localhost_002 src]# tar -zxvf apr-util-1.6.1.tar.gz #解压apr:
root@localhost_002 src]# tar -zxvf apr-1.6.3.tar.gz #解压apr-util:
root@localhost_002 src]# cd apr-1.6.3
[root@localhost_002 apr-1.6.3]# ./configure --prefix=/usr/local/apr #自动生成编译时所需要的makefile:
#可以用echo $? 确认是否运行成功:
保存信息如下:configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
缺少gcc: yum install -y gcc
[root@localhost_002 apr-1.6.3]# make && make install
[root@localhost_002 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #编译安装apr-util
注意:apr-util需要依赖apr才可以使用 : ---with-apr=/usr/local/apr
[root@localhost_002 apr-util-1.6.1]# make &&make install
报错信息如下:xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
解决:安装:yum install -y expat-devel
2:编译安装httpd:
解压:[root@localhost_002 src]# tar zxvf httpd-2.4.34.tar.gz
编译: 选项: --prefix=/usr/local/apapche2.4(路径) --enable=so -enable-mods-shared=most
[root@localhost_002 src]# cd httpd-2.4.34
[root@localhost_002 httpd-2.4.34]# ./configure --prefix=/usr/local/apache2.4 --with-arp=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable=so -enable-mods-sharead=most
注释:--enables=so:支持动态扩展模块功能,是一个.so的后缀名文件,apache是进程,可以通过配置文件调用这个模块:
#--enable-mods-shared=most:加载大多数的模块:
[root@localhost_002 src]#make && make install
报错信息如下:
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.34/support”
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.34/support”
make: *** [all-recursive] 错误 1
注释:错误为apr apr-util缺失,需要把apr目录及apr-util目录拷贝到httpd的目录下:如下:
[root@localhost_002 httpd-2.4.34]# cp -r apr-1.6.1 /usr/local/src/httpd-2.4.34/srclib/apr
[root@localhost_002 httpd-2.4.34]# cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.34/srclib/apr-util
再次make && make install即可::
安装步骤如下:
[root@localhost_002 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.34.tar.gz
正在保存至: “httpd-2.4.34.tar.gz” #httpd下载:
100%[===========================================================================================>] 9,098,780 1.80MB/s 用时 5.2s
[root@localhost_002 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
正在保存至: “apr-1.6.3.tar.gz.1” #apr下载:
100%[===========================================================================================>] 1,072,661 1.48MB/s 用时 0.7s
[root@localhost_002 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz
正在保存至: “apr-util-1.6.1.tar.gz” #apr-util下载:
100%[===========================================================================================>] 554,301 1.15MB/s 用时 0.5s
编译安装apr和apr-util:
[root@localhost_002 src]# tar -zxvf apr-util-1.6.1.tar.gz
root@localhost_002 src]# tar -zxvf apr-1.6.3.tar.gz
root@localhost_002 src]# cd apr-1.6.3
[root@localhost_002 apr-1.6.3]# ./configure --prefix=/usr/local/apr #自动生成编译时所需要的makefile:
#可以用echo $? 确认是否运行成功:
[root@localhost_002 apr-1.6.3]# make && make install
[root@localhost_002 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#编译安装apr-util
[root@localhost_002 apr-util-1.6.1]# make &&make install
[root@localhost_002 src]# tar zxvf httpd-2.4.34.tar.gz #解压httpd:
[root@localhost_002 src]# cd httpd-2.4.34
[root@localhost_002 httpd-2.4.34]# cp -r apr-1.6.1/usr/local/src/httpd-2.4.34/srclib/apr
[root@localhost_002 httpd-2.4.34]# cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.34/srclib/apr-util
[root@localhost_002 httpd-2.4.34]# ./configure --prefix=usr/local/apapche2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable=so --enable-mods-shared=most
#编译安装,enable=so表示动态加载模块, --enable-mods-shared=most表示加载大多数的模块:
[root@localhost_002 httpd-2.4.34]# make && make install
安装完成:
3:httpd的配置文件及其目录: /usr/lcoal/apapche/
[root@localhost_002 apapche2.4]# ls
bin build cgi-bin conf error htdocs icons include logs man manual modules
bin:启动脚本所在目录: httpd:
conf:配置文件目录:extra httpd.conf /conf/extra/httpd-vhost.conf
htdocs:默认网站访问页: log:日记相关:
/usr/local/apache2.4/modules:模块存放目录:
查看apapche的模块: /usr/local/apache2.4/bin/apachectl -M
[root@localhost_002 apapche2.4]# /usr/local/apapche2.4/bin/httpd -M
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
如下图例:apapche的模块可分为两部分:静态(static)和动态(shared):
静态static:是直接编订在主脚本里面的,是绑定在一起的:
动态shared:以.so结尾,存放在/usr/local/apache2.4目录下:
启动apapche: /usr/local/apache2.4/bin/apachectl start
[root@localhost_002 apapche2.4]# /usr/local/apapche2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe81:f44b. Set the 'ServerName' directive globally to suppress this message
[root@localhost_002 apapche2.4]# ps aux |grep httpd
root 64667 0.0 0.2 95580 2524 ? Ss 12:18 0:00 /usr/local/apapche2.4/bin/httpd -k start
daemon 64668 0.1 0.4 382408 4428 ? Sl 12:18 0:00 /usr/local/apapche2.4/bin/httpd -k start
daemon 64669 0.0 0.4 382408 4428 ? Sl 12:18 0:00 /usr/local/apapche2.4/bin/httpd -k start
daemon 64670 0.0 0.4 382408 4428 ? Sl 12:18 0:00 /usr/local/apapche2.4/bin/httpd -k start
root 64754 0.0 0.0 112720 968 pts/1 R+ 12:18 0:00 grep --color=auto httpd
可以正常启动:查看端口:netstat -lntp
[root@localhost_002 apapche2.4]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:52588 0.0.0.0:* LISTEN 876/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1092/master
tcp6 0 0 :::52588 :::* LISTEN 876/sshd
tcp6 0 0 :::80 :::* LISTEN 64667/httpd
tcp6 0 0 ::1:25 :::* LISTEN 1092/master
tcp6 0 0 :::3306 :::* LISTE