Mariadb安装
[root@lyon-01 ~]# cd /usr/local/src/
[root@lyon-01 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@lyon-01 src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
移动文件夹至上层目录中,并重命名
[root@lyon-01 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[root@lyon-01 src]# cd /usr/local/mariadb/
[root@lyon-01 mariadb]# ls //看下是否是数据库文件
bin COPYING.thirdparty data docs include lib mysql-test README
COPYING CREDITS DESTINATION EXCEPTIONS-CLIENT INSTALL-BINARY man README.md script
初始化,指定用户名和数据库目录
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb //定义了bashdir 如果不定义,就回去找mysql
!! 实验中暂时没有定义
[root@lyon-01 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in ‘/data/mariadb‘ ...
OK
..................
[root@lyon-01 mariadb]# echo $? //看下是否执行成功
0
[root@lyon-01 mariadb]#
[root@lyon-01 mariadb]# ls /data/mariadb/ //看一下数据库文件
aria_log.00000001 ib_buffer_pool ib_logfile0 mysql test
aria_log_control ibdata1 ib_logfile1 performance_schema
[root@lyon-01 mariadb]# ls /data/mysql/ //对比mysql的数据库文件
auto.cnf ib_logfile0 lyon-01.err mysql test
ibdata1 ib_logfile1 lyon-01.pid performance_schema
-----> ok 和mysql差不多的文件
[root@lyon-01 mariadb]# ls support-files/ //mariadb配置文件 选个小的就行
##选择模板根据自己情况,我们选小的,后期可以添加其他的配置
binary-configure my-large.cnf mysql-log-rotate wsrep_notify
magic my-medium.cnf mysql.server
my-huge.cnf my-small.cnf policy/
my-innodb-heavy-4G.cnf mysqld_multi.server wsrep.cnf
我们拷贝一个小的配置文件模板 不放在/etc下了 放在另外一个目录下
[root@lyon-01 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
拷贝开机启动的脚本
[root@lyon-01 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
看下mariadb的配置文件 基本上不用改
修改启动脚本 vim /etc/init.d/mariadb
basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=$bashdr/my.cnf
定义了 conf 还要找启动命令下面定义下: 搜start 找
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" "$@" & //添加 --defaults-file="$conf"
[root@lyon-01 mariadb]# ps aux |grep mysql //看下mysql服务是否启动,先关闭它
root 2812 0.0 0.0 112664 972 pts/0 R+ 15:17 0:00 grep --color=auto mysql
[root@lyon-01 mariadb]# /etc/init.d/mariadb start //启动mariadb
Starting mariadb (via systemctl): Warning: mariadb.service changed on disk. Run ‘systemctl daemon-reload‘ to reload units.
[ 确定 ]
[root@lyon-01 mariadb]# ps aux |grep mariadb //看下mariadb是否起来
root 2836 0.0 0.1 115380 1732 ? S 15:17 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/lyon-01.pid
mysql 2952 2.9 5.6 1125120 56560 ? Sl 15:17 0:01 /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/lyon-01.err --pid-file=/data/mysql/lyon-01.pid --socket=/tmp/mysql.sock --port=3306
root 2994 0.0 0.0 112664 976 pts/0 S+ 15:18 0:00 grep --color=auto mariadb
[root@lyon-01 mariadb]# 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 1455/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2352/master
tcp6 0 0 :::3306 :::* LISTEN 2952/mysqld
tcp6 0 0 :::22 :::* LISTEN 1455/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2352/master
如果报错
在/usr/local/mariadb/my.cnf这个文件里的mysqld添加datadir=/data/mariadb
注意的点
[root@lyon-01 mariadb]# ps aux |grep mariadb
root 2836 0.0 0.1 115380 1732 ? S 15:17 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/lyon-01.pid
mysql 2952 0.2 6.4 1125120 64944 ? Sl 15:17 0:01 /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/lyon-01.err --pid-file=/data/mysql/lyon-01.pid --socket=/tmp/mysql.sock --port=3306
root 3752 0.0 0.0 112664 976 pts/0 S+ 15:30 0:00 grep --color=auto mariadb
[root@lyon-01 mariadb]#
--datadir=/data/mysql 并不是我们定义的/data/mariadb 因为它调用了/etc/my.cnf配置文件
解决方案--->> 修改/usr/local/mariadb/my.cnf
[mysqld]
datadir = /data/mariadb //在这里添加
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
thread_stack = 240K
然后再看
[root@lyon-01 mariadb]# killall mysqld //杀死mariadb服务
[root@lyon-01 mariadb]# /etc/init.d/mariadb start //再次启动
Starting mariadb (via systemctl): [ 确定 ]
[root@lyon-01 mariadb]# ps aux |grep mariadb
root 4081 0.0 0.1 115380 1744 ? S 15:43 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariad/lyon-01.pid
mysql 4200 4.1 5.9 1125020 59900 ? Sl 15:43 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/lyon-01.err --pid-file=/data/mariadb/lyon-01.pid --socket=/tmp/mysql.sock --port=3306
root 4236 0.0 0.0 112664 976 pts/0 R+ 15:43 0:00 grep --color=auto mariadb
[root@lyon-01 mariadb]#
可以看到 ,定义的datadir为/data/mariadb
Apache安装
Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache
Apache官网www.apache.org 下载地址失效的话,去r.aminglinux.com或官网找最新包
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
wget http://mirrors.hust.edu.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows) ,7自带的apr与我们httpd2.4是不通用的
tar zxvf httpd-2.4.27.tar.gz
tar zxvf apr-util-1.5.4.tar.gz
tar zxvf apr-1.5.2.tar.gz
cd /usr/local/src/apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install
实验流程
[root@lyon-01 src]# cd /usr/local/src/
[root@lyon-01 src]# wget 下面三个软件
2.4源码包: http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gzapr: http://mirrors.hust.edu.cn/apache/apr/apr-1.6.2.tar.gzapr-util: http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.0.tar.bz2
解压
tar zxvf httpd/httpd-2.4.27.tar.gz
tar zxvf apr-1.6.2.tar.gz
tar jxvf apr-util-1.6.0.tar.bz2
[root@lyon-01 src]# cd apr-1.6.2/
[root@lyon-01 apr-1.6.2]# ./configure --prefix=/usr/local/apr
。。。。。
[root@lyon-01 apr-1.6.2]# echo $?
0
OK
[root@lyon-01 apr-1.6.2]# make && make install
[root@lyon-01 apr-1.6.2]# ls /usr/local/apr/
bin build-1 include lib //看下是否有这几个文件
[root@lyon-01 apr-util-1.6.0]# cd apr-util-1.6.0/
[root@lyon-01 apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@lyon-01 apr-util-1.6.0]# echo $?
0
[root@lyon-01 apr-util-1.6.0]# make && make install
[root@lyon-01 apr-util-1.6.0]# ls /usr/local/apr-util/
bin include lib //看下是否有这几个文件
cd /usr/local/src/httpd-2.4.27
./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@lyon-01 httpd-2.4.27]# make && make install
make[1]: 离开目录“/usr/local/src/httpd-2.4.27”
[root@lyon-01 httpd-2.4.27]# echo $?
0
[root@lyon-01 httpd-2.4.27]#
-----httpd安装完成
[root@lyon-01 httpd-2.4.27]# ls /usr/local/apache2.4.7/
bin build cgi-bin conf error htdocs icons include logs man manual modules
小知识点:
里面有很多文件 我们接触比较多的是
bin 下面是可执行文件
conf 我们的配置文件所在目录
htdocs 存放访问页的目录
logs 日志相关的文件
man 帮助文档
modules 扩展模块 里面有很多模块 一个模块代表1个功能
下面两条命令就是查看我们安装了那些模块
# [root@lyon-01 apache2.4.7]# /usr/local/apache2.4.7/bin/apachectl -M
# [root@lyon-01 apache2.4.7]# /usr/local/apache2.4.7/bin/httpd -M
# static 静态模块 编译进了主脚本里
# shared 扩展模块 .so的文件
[root@lyon-01 apache2.4.7]# /usr/local/apache2.4.7/bin/apachectl start //启动Apache
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 123.129.254.12. Set the ‘ServerName‘ directive globally to suppress this message
这个提示我们不用管
[root@lyon-01 apache2.4.7]# ps aux |grep httpd //看下进程,已经起来了
root 32706 0.0 0.2 95516 2544 ? Ss 17:36 0:00 /usr/local/apache2.4.7/bin/httpd -k start
daemon 32707 0.0 0.4 382344 4460 ? Sl 17:36 0:00 /usr/local/apache2.4.7/bin/httpd -k start
daemon 32708 0.0 0.4 382344 4460 ? Sl 17:36 0:00 /usr/local/apache2.4.7/bin/httpd -k start
daemon 32709 0.0 0.4 382344 4460 ? Sl 17:36 0:00 /usr/local/apache2.4.7/bin/httpd -k start
root 32792 0.0 0.0 112664 972 pts/0 R+ 17:36 0:00 grep --color=auto httpd
[root@lyon-01 apache2.4.7]# 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 1455/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2352/master
tcp6 0 0 :::3306 :::* LISTEN 4200/mysqld
tcp6 0 0 :::80 :::* LISTEN 32706/httpd
tcp6 0 0 :::22 :::* LISTEN 1455/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2352/master
[root@lyon-01 apache2.4.7]#
OK
本文出自 “13348833” 博客,请务必保留此出处http://13358833.blog.51cto.com/13348833/1969241
原文地址:http://13358833.blog.51cto.com/13348833/1969241