目录
一、MariaDB安装
二、Apache安装
一、MariaDB安装
- MariaDB的安装和Mysql的差不多,安装过程如下:
[root@minglinux-01 /usr/local/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
//下载MariaDB免编译二进制包
[root@minglinux-01 /usr/local/src] tar -zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
//解压
[root@minglinux-01 /usr/local/src] mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
//移动位置
[root@minglinux-01 /usr/local/src] cd !$ //进入mariadb文件夹
cd /usr/local/mariadb
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
//初始化,加上basedir
- 复制相关配置文件
[root@minglinux-01 /usr/local/mariadb] ls support-files/
binary-configure my-medium.cnf policy
magic my-small.cnf wsrep.cnf
my-huge.cnf mysqld_multi.server wsrep_notify
my-innodb-heavy-4G.cnf mysql-log-rotate
my-large.cnf mysql.server
[root@minglinux-01 /usr/local/mariadb] cp support-files/my-small.cnf /usr/local/mariadb/my.cnf //配置文件有多个,因为是实验用,选个小的得了
[root@minglinux-01 /usr/local/mariadb] cp support-files/mysql.server /etc/init.d/mariadb //复制启动脚本
- 修改/etc/init.d/mariadb启动脚本
定义basedir、datadir、conf以及启动参数
basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=$basedir/my.cnf //还要在下面启动命令定义一下
这里需要定义conf是为了不跟之前安装的mysql出现冲突,一般不会有mysql和mariadb同时安装的情况,如果只安装一种一个,可以不用定义。直接把my.cnf 放到etc下即可。
'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=$?
# Make lock for RedHat / SuSE
if test -w "$lockdir"
then
touch "$lock_file_path"
fi
- 启动mariadb
[root@minglinux-01 /usr/local/mariadb] killall mysqld
[root@minglinux-01 /usr/local/mariadb] ps aux |grep mysql
root 3461 0.0 0.0 112720 980 pts/2 S+ 23:06 0:00 grep --color=auto mysql
[root@minglinux-01 /usr/local/mariadb] /etc/init.d/mariadb start
Reloading systemd: [ 确定 ]
Starting mariadb (via systemctl): [ 确定 ]
[root@minglinux-01 /usr/local/mariadb] ps aux |grep mariadb
root 3506 0.0 0.0 115432 1712 ? S 23:06 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/minglinux-01.pid
mysql 3742 0.7 5.6 1014272 105644 ? Sl 23:06 0:00 /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=minglinux-01.err --pid-file=/data/mysql/minglinux-01.pid --socket=/tmp/mysql.sock --port=3306
root 3770 0.0 0.0 112720 984 pts/2 S+ 23:08 0:00 grep --color=auto mariadb
[root@minglinux-01 /usr/local/mariadb] netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1119/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 864/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1119/master
tcp6 0 0 :::3306 :::* LISTEN 3742/mysqld
tcp6 0 0 :::22 :::*
二、Apache安装
- 下载源码包
首先在阿里云开源镜像站下载Apache2.4版本的源码包,2.4版本有一个
比较麻烦的事情,还需要手动编译安装apr以及apr-util包,所以这里一并下载apr及apr-util包。命令如下:
[root@minglinux-01 /usr/local/src] wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.35.tar.gz
[root@minglinux-01 /usr/local/src] wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.5.tar.gz
[root@minglinux-01 /usr/local/src] wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz
- apr包解压并安装
[root@minglinux-01 /usr/local/src] tar -zxvf apr-1.6.5.tar.gz
[root@minglinux-01 /usr/local/src/apr-1.6.5] cd apr-1.6.5/
[root@minglinux-01 /usr/local/src/apr-1.6.5] ./configure --prefix=/usr/local/apr
// 这里会出现提示rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands ,没有关系,不用管它
[root@minglinux-01 /usr/local/src/apr-1.6.5] echo $?
0
[root@minglinux-01 /usr/local/src/apr-1.6.5] make && make install //编译安装
- apr-util包下载安装
[root@minglinux-01 /usr/local/src] tar zxvf apr-util-1.6.1.tar.gz
[root@minglinux-01 /usr/local/src] cd apr-util-1.6.1/
[root@minglinux-01 /usr/local/src/apr-util-1.6.1] make && make install
//出现错误提示xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录,解决办法是:
yum install –y expat-devel
[root@minglinux-01 /usr/local/src/apr-util-1.6.1] yum install –y expat-devel
[root@minglinux-01 /usr/local/src/apr-util-1.6.1] make && make install //再次执行编译安装即可
[root@minglinux-01 /usr/local/src/apr-util-1.6.1] echo $?
0
- 安装httpd
[root@minglinux-01 /usr/local/src] tar zxvf httpd-2.4.37.tar.gz
[root@minglinux-01 /usr/local/src] ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@minglinux-01 /usr/local/src] cd httpd-2.4.37/
[root@minglinux-01 /usr/local/src/httpd-2.4.37] ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@minglinux-01 /usr/local/src/httpd-2.4.37] echo $?
0
[root@minglinux-01 /usr/local/src/httpd-2.4.37] make
[root@minglinux-01 /usr/local/src/httpd-2.4.37] make insatll
make过程出现了如下报错:
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to 'XML_SetElementHandler'
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”
解决方法:
[root@minglinux-01 /usr/local/src/httpd-2.4.37] ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most --with-included-apr
出现报错 “configure: error: Bundled APR requested but not found at ./srclib/.Download and unpack the corresponding apr and apr-util packages to ./srclib/.”
root@minglinux-01 /usr/local/src/httpd-2.4.37] cd ..
[root@minglinux-01 /usr/local/src] cp -r apr-1.6.5 /usr/local/src/httpd-2.4.37/srclib/apr
[root@minglinux-01 /usr/local/src] cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.37/srclib/apr-util
[root@minglinux-01 /usr/local/src/httpd-2.4.37] ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most --with-included-apr
[root@minglinux-01 /usr/local/src/httpd-2.4.37] make && make install //重新编译安装
[root@minglinux-01 /usr/local/src/httpd-2.4.37] echo $?
0
如果make过程出现“configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/”错误,则执行
yum install -y pcre pcre-devel
安装prce库文件。
上例中,--prefix指定安装目录,--enable-so表示启用DSO。DSO的意思是,把某些功能以模块(一个功能模块就是一个 so 文件,这些文件在编译完 httpd 后会看到)的形式展现出来。enable-mods-shared=most表示以共享的方式安装大多数功能模块,安装后会在modules目录下面看到这
些文件。
安装完后,查看httpd的目录结构以及modules目录下面的模块文件:
[root@minglinux-01 /usr/local/src/httpd-2.4.37] ls /usr/local/apache2.4/
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
[root@minglinux-01 /usr/local/src/httpd-2.4.37] ls /usr/local/apache2.4/modules
httpd.exp mod_lbmethod_heartbeat.so
mod_access_compat.so mod_log_config.so
mod_actions.so mod_log_debug.so
mod_alias.so mod_logio.so
mod_allowmethods.so mod_macro.so
mod_auth_basic.so mod_mime.so
mod_auth_digest.so mod_negotiation.so
mod_auth_form.so mod_proxy_ajp.so
mod_authn_anon.so mod_proxy_balancer.so
mod_authn_core.so mod_proxy_connect.so
mod_authn_dbd.so mod_proxy_express.so
mod_authn_dbm.so mod_proxy_fcgi.so
mod_authn_file.so mod_proxy_fdpass.so
mod_authn_socache.so mod_proxy_ftp.so
mod_authz_core.so mod_proxy_hcheck.so
mod_authz_dbd.so mod_proxy_http.so
mod_authz_dbm.so mod_proxy_scgi.so
mod_authz_groupfile.so mod_proxy.so
mod_authz_host.so mod_proxy_uwsgi.so
mod_authz_owner.so mod_proxy_wstunnel.so
mod_authz_user.so mod_ratelimit.so
mod_autoindex.so mod_remoteip.so
mod_buffer.so mod_reqtimeout.so
mod_cache_disk.so mod_request.so
mod_cache.so mod_rewrite.so
mod_cache_socache.so mod_sed.so
mod_cgid.so mod_session_cookie.so
mod_dav_fs.so mod_session_dbd.so
mod_dav.so mod_session.so
mod_dbd.so mod_setenvif.so
mod_dir.so mod_slotmem_shm.so
mod_dumpio.so mod_socache_dbm.so
mod_env.so mod_socache_memcache.so
mod_expires.so mod_socache_shmcb.so
mod_ext_filter.so mod_speling.so
mod_file_cache.so mod_status.so
mod_filter.so mod_substitute.so
mod_headers.so mod_unique_id.so
mod_include.so mod_unixd.so
mod_info.so mod_userdir.so
mod_lbmethod_bybusyness.so mod_version.so
mod_lbmethod_byrequests.so mod_vhost_alias.so
mod_lbmethod_bytraffic.so mod_watchdog.so
文件夹存放内容:
bin:存放可执行文件,该目录下的httpd二进制文件用于启动httpd服务
conf:配置文件所在目录
htdocs:网站访问页,网页文件存放在该目录下
logs:存放错误和访问日志
man:帮助文档
modules:扩展模块文件(.so),一个模块即一个.so文件,每个模块代表一个功能
- 查看httpd加载了哪些模块
[root@minglinux-01 /usr/local/src/httpd-2.4.37] /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe46:125. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
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)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
- 启动apache
[root@minglinux-01 /usr/local/src/httpd-2.4.37] /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe46:125. Set the 'ServerName' directive globally to suppress this message
[root@minglinux-01 /usr/local/src/httpd-2.4.37] ps aux |grep httpd
root 51835 0.0 0.1 95320 2580 ? Ss 00:00 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 51836 0.0 0.1 382148 2360 ? Sl 00:00 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 51837 0.0 0.1 382148 2356 ? Sl 00:00 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 51838 0.0 0.1 382148 2360 ? Sl 00:00 0:00 /usr/local/apache2.4/bin/httpd -k start
root 51921 0.0 0.0 112720 984 pts/0 S+ 00:00 0:00 grep --color=auto httpd
[root@minglinux-01 /usr/local/src/httpd-2.4.37] netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1119/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 864/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1119/master
tcp6 0 0 :::3306 :::* LISTEN 4135/mysqld
tcp6 0 0 :::80 :::* LISTEN 51835/httpd
tcp6 0 0 :::22 :::* LISTEN 864/sshd
扩展
apache dso https://yq.aliyun.com/articles/6298
apache apxs https://wizardforcel.gitbooks.io/apache-doc/content/51.html
apache工作模式 https://blog.csdn.net/STFPHP/article/details/52954303