zhangsanfeng88 发表于 2018-11-18 08:25:48

linux的MariaDB、Apache(httpd)安装

MariaDB安装


[*]将下载的源码包放到这个目录下:

# cd /usr/local/src
  2.下载源码包:

# 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//这个是国外服务器,下载要四五十分钟,最后是下载后直接放到指定目录上。

  3.将压缩包解压:

# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  4.把目录移动到/usr/local/下并改名为mariadb:

# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
  5.进入目录查看:

# cd /usr/local/mariadb
  6.初始化指定用户mysql和路径:

# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
# ls /data/mariadb
aria_log.00000001aria_log_controlib_buffer_poolibdata1ib_logfile0ib_logfile1mysqlperformance_schematest

  7.复制配置文件:

# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf//为了与mysql区分,重新换一个文件路径
  8.编辑配置文件:
  vi /usr/local/mariadb/my.cnf //定义basedir和datadir
  如果没有修改/usr/local/mariadb/my.cnf配置文件,没有在mysqld中加一行 datadir=/data/mariadb,那么它就会调用/etc/my.cnf中的datadir,就会出现如图下的情况。

  那如果修改了/usr/local/mariadb/my.cnf配置文件,在mysqld中加一行 datadir=/data/mariadb,如下:

  然后重新启动mariadb服务,查看服务后如下:

  9.复制启动脚本:

# cp support-files/mysql.server /etc/init.d/mariadb
  10.编辑启动脚本:
  命令:vim /etc/init.d/mariadb
//定义basedir、datadir、conf以及启动参数
  basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=$basedir/my.cnf
  示例如下

# vim /usr/local/mariadb/my.cnf //配置脚本一般情况下不用更改。
# vim /etc/init.d/mariadb//按下图配置修改启动脚本,修改完成保存退出。


  备注:此启动脚本由于mariadb与mysql装在一台机器上,为了区分开来,需要定义conf与变量,如果只装mariadb的话就不需要定义。
  11.启动MariaDB,启动之前看看有没有mysqld的服务在启动,如果有它们是会冲突的,因为它们的监听端口是一样的:

# ps aux |grep mysql//先查看mysql的服务有没启动
root      8180.00.0 115376   504 ?      S    15:56   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/gary-tao.pid
mysql      11890.0 45.1 1038844 451316 ?      Sl   15:56   0:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/gary-tao.err --pid-file=/data/mysql/gary-tao.pid --socket=/tmp/mysql.sock
root       48530.00.0 112664   972 pts/0    R+   17:36   0:00 grep --color=auto mysql
#service mysqld stop   //关闭mysql服务
Shutting down MySQL.. SUCCESS!
# service mariadb start //etc/init.d/mariadb start//两种启动服务方式
Starting mariadb (via systemctl):                        [确定]
# ps aux |grep mariadb//服务启动成功
root       51980.00.1 1153801732 ?      S    17:42   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/gary-tao.pid
mysql      5314 10.85.4 1125120 54544 ?       Sl   17:42   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/gary-tao.err --pid-file=/data/mysql/gary-tao.pid --socket=/tmp/mysql.sock --port=3306
root       53530.00.0 112664   972 pts/0    S+   17:42   0:00 grep --color=auto mariadb
# netstat -ltnp//查看服务监听端口
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:22            0.0.0.0:*               LISTEN      800/sshd            
tcp      0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1230/master         
tcp6       0      0 :::3306               :::*                  LISTEN      5314/mysqld         
tcp6       0      0 :::22                   :::*                  LISTEN      800/sshd            
tcp6       0      0 ::1:25                  :::*                  LISTEN      1230/master   

Apache安装
  Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache


[*]Apache官网地址 www.apache.org
  2.wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz
  apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)
  3.下载安装包到指定目录:
  示例如下:

# cd /usr/local/src
  4.将压缩包解压:
  示例如下:

# tar zxvf httpd-2.4.29.tar.gz
# tar zxvf apr-1.6.3.tar.gz
# tar zxvf apr-util-1.6.1.tar.gz

  5.首先安装apr,进入apr目录,然后安装apr:
  示例如下:

# cd /usr/local/src/apr-1.6.3
# ./configure --prefix=/usr/local/apr
# echo $?
0
# make && make install
# ls /usr/local/apr/
binbuild-1includelib

  安装时报错问题解决:
  示例如下:

# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.3
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/apr-1.6.3':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
# yum install -y gcc//装gcc编译

  6.进入apr-util目录,安装apr-util,apr-util要指定apr,因为它依赖apr:
  示例如下:

# cd ../apr-util-1.6.1/
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
# ls /usr/local/apr-util/
binincludelib
  在编译安装的时候可能会遇到图下的情况,缺少expat的开发库,所以需要安装包:yum install expat-devel,安装完成之后再编译安装make && make install:

  7.进入http目录,安装httpd方法:
  示例如下:

# cd httpd-2.4.29
# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
# echo $?
0
  安装时报错:


[*]如果没有安装pcre这个包,就会出现下图的错误,我们可以使用 yum list |grep 关键字,查找关联的安装包。这里需要安装包:yum install -y pcre-devel.x86_64



[*]make编译的时候可能会出现下图的情况,把httpd,apr-util的源码包删除掉,然后在重新解压源码包,再重新把apr-util,httpd编译安装一遍

  8.进入apache2.4目录下的查看文件:

# cd /usr/local/apache2.4/
# ls
binbuildcgi-binconferrorhtdocsiconsincludelogsmanmanualmodules

  针对目录文件说明:


[*]bin:bin下的文件是可执行的二进制文件或命令,是核心的二进制文件,如httpd;
[*]conf:配置文件所在的目录;
[*]htdocs:存放了一个访问网页,默认的网站会放到这个目录下;
[*]logs:日志相关的目录,错误日志,访问日志等;
[*]man:帮助文档;
[*]modules:扩展模块,模块都放在这个目录下,每一个模块都代表一个功能;
  9.查看加载的模块:
  命令:


[*]/usr/local/apache2.4/bin/httpd -M
[*]/usr/local/apache2.4/bin/apachectl -M//shell文件,去调用了二进制httpd文件,-M就是把模块例出来。

# /usr/local/apache2.4/bin/httpd -M//下面AHOO558不是一个错误,只是一个警告,可以在配置文件中定义ServerName使其消失。
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 218.93.250.18. 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)
  说明:


[*]  static:静态,是直接把模块编译进了二进制文件httpd里。有static说明是httpd里的,静态模块是直接跟主程序(/usr/local/apache2.4/bin/httpd)绑定在一起,它们是一个整体。httpd是核心文件。

[*]shared:说明是扩展的模块,这个模块是一个文件(文件是在modules目录下面的.so文件);
  10.启动httpd(Apache监听端口是80端口):

# /usr/local/apache2.4/bin/apachectl start//执行启动命令
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 218.93.250.18. Set the 'ServerName' directive globally to suppress this message
# ps aux |grep httpd
root      460770.00.2955362604 ?      Ss   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    460780.00.4 3823644452 ?      Sl   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    460790.00.4 3823644452 ?      Sl   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    460800.00.4 3823644452 ?      Sl   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start
root      461650.00.0 112680   972 pts/0    R+   21:24   0:00 grep --color=auto httpd
# 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:22            0.0.0.0:*               LISTEN      800/sshd            
tcp      0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1230/master         
tcp6       0      0 :::3306               :::*                  LISTEN      6043/mysqld         
tcp6       0      0 :::80                   :::*                  LISTEN      46077/httpd         
tcp6       0      0 :::22                   :::*                  LISTEN      800/sshd            
tcp6       0      0 ::1:25                  :::*                  LISTEN      1230/master         


页: [1]
查看完整版本: linux的MariaDB、Apache(httpd)安装