Linux个人笔记(三:一些软件的安装配置)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CHEndorid/article/details/82960795
<!--现在没有源码编辑功能了,只能手动记录目录,手动翻页,哎,附上翻页的代码备用-->
<a href="#content">目录</a>
xxx等废话
<p id="content">跳转的地方(内容)</p>

本文内容:

001、5.6版本的MySQL的安装;002、安装Apache(2.4版本);003、安装PHP(5.6版本)

001、5.6版本的MySQL的安装

①下载软件包

#建议吧所有软件包都放到这个目录下面
cd /usr/local/src
#下载---截止2018年10月7日仍然有效,如果失效了,可以看一下这个网站:r.aminglinux.com
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz

②初始化,以下内容可以写成脚本或者自己一步一步的敲

#安装 perl-Module-Install,不安装会报错
yum install -y per-Module-Install
#解压
tar -zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
#判断 /usr/local/mysql 是否存在,如果存在,就改一下名字
[ -d /usr/local/mysql ] && mv /usr/local/mysql /usr/local/mysql_old
#将解压出来的文件挪位置,并改名字
mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysql
#简历MySQL用户,因为启动MySQL需要该用户,-s为指定shell
usradd -s /sbin/nologin mysql
cd /usr/local/mysql
#在根目录下创建datadir,数据库文件会放在这里面
mkdir -p /data/mysql
#更改权限,不更改后续操作就会出问题
chown -R mysql:mysql /data/mysql
#5.6是这个操作,5.7就不一样了
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

③配置MySQL

cp support-files/my-default.cnf /etc/my.cnf
#因为系统默认就有/etc/my.cnf,所以会提示是否覆盖
cp:是否覆盖"/etc/my.cnf"? y
#修改配置文件
vim /etc/my.cnf
#修改内容如下:

##########################################################################
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
 innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
######这要和自己服务器的hostname一致,我的是MasterC#######
 log_bin = MasterC

# These are commonly set, remove the # and set as required.
 basedir = /usr/local/mysql
 datadir = /data/mysql
 port = 3306
 server_id = 128
 socket = /tmp/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
 join_buffer_size = 128M
 sort_buffer_size = 2M
 read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
############################################################################

#复制启动脚本文件并修改其属性
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
#修改启动脚本
vim /etc/init.d/mysqld
############需要修改的地方是datadir=/data/mysql(前面初始化数据库时定义的目录)
#把启动脚本加入到系统服务列表中
chkconfig --add mysqld
#开机启动
chkconfig mysqld on
#启动服务
service mysqld start
#如果启动不了,请到/data/mysql/目录下查看错误日志,这个日志名通常是主机名.err

#检查MySQL是否启动的命令为
echo $?
#如果是0,则表示安装成功

#结果应大于2行
ps aux | grep mysqld
#看看有没有监听3306端口
netstat -lnp | grep 3306

 

002、安装Apache(2.4版本)

①下载软件包 httpd-2.4.35.tar.gz,官网地址为http://httpd.apache.org/download.cgi,按下图操作获得软件包地址,然后下载

cd /usr/local/src
wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.35.tar.gz

下载 apr 包及 apr-util 包,官网地址为https://apr.apache.org/download.cgi,同理获得软件包下载地址

wget http://download.nextag.com/apache//apr/apr-1.6.5.tar.gz
wget http://download.nextag.com/apache//apr/apr-util-1.6.1.tar.gz

②解压

扫描二维码关注公众号,回复: 3503411 查看本文章
tar -zxvf httpd-2.4.35.tar.gz
tar -zxvf apr-1.6.5.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz

③按以下先后顺序编译安装

apr

#操作前确保CentOS中已安装gcc,如果没有,则使用以下命令
#yum install -y gcc
cd /usr/local/src/apr-1.6.5
#运行apr-1.6.5下面的 configure,--prefix 表示指定安装目录
#运行完后会生成 Makefile 文件
./configure --prefix=/usr/local/apr
#make 会根据 Makefile 文件中的预设参数进行编译,这一步已经是gcc在工作了
#makeinstall 创建相关软件的存放目录和配置文件
make && make install

#运行会输出一大堆文字,可用下面语句判断安装成功与否,返回0表示成功
echo $?

apr-util

#安装前请确保有安装 expat-devel,不知道的情况下最好运行下面命令
yum install -y expat-devel

cd /usr/local/src/apr-utl-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

httpd

#安装前请确保有安装 pcre pcre-devel,不知道的情况下最好运行下面命令
yum install -y pcre pcre-devel

cd /usr/local/src/httpd-2.4.35
#下面的反斜杠是转义字符,加上它可以把一行命令写成多行
./configure \
--prefix=/usr/local/apache2.4 \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
#表示启动 DSO(把某些功能已模块;一个so文件;的形式展现出来)
--enable-so \
#以共享的方式安装大多数功能模块,安装后在modules目录下可以看到这些文件
--enable-mods-shared=most

make
make install
#可用下面命令查看安装是否成功
echo $?

如果安装出错,一定是哪里敲错了,那就删了再来,我敲了两遍才敲正确……

下面可以查看加载了哪些配置文件

/usr/local/apache2.4/bin/apachectl -M

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::d23:34b:8a80:ea3a. 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)
以下省略……

#AH0058开头的行是警告,不是错误。带有shared字样的,表示该模块为动态共享模块
#带有static字样的,表示以静态的形式存在。动态和静态的区别在于,静态模块直接
#和主程序(/usr/local/apache2.4/bin/httpd)绑定在一起,我们看不到,而动态
#的模块都是一个个独立的文件(modules目录下的.so文件)

 

003、安装PHP(5.6版本)

①下载软件包,官网地址http://php.net/downloads.php,选择需要的软件包后,会跳转到下载界面

这些都是镜像地址,随便选一个就是了

cd /usr/local/src
wget http://jp2.php.net/get/php-5.6.38.tar.gz/from/this/mirror
#下载下来的名字叫mirror,可以通过file查看其属性
file mirror 
mirror: gzip compressed data, was "php-5.6.38.tar", from Unix, last modified: Wed Sep 12 07:19:51 2018, max compression
#可以看到,这是一个tar文件,解包
tar -xvf mirror 

②配置编译参数,参数很多,一定要敲仔细,我又敲了两遍……

./configure  \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2.4/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif

③安装排错,什么都还没安装过的CentOS,在安装过程中讲道理会出很多错,一般仔细查看报错信息,安装缺少的库即可

错误1:

configure: error: xml2-config not found. Please check your libxml2 installation.

你可能发现你安装了libxml2还是报错了,这是因为我们是在编译,需要的是开发包

解决办法:yum install -y libxml2-devel

错误2:

configure: error: Cannot find OpenSSL's <evp.h>

解决办法:yum install -y openssl-devel

错误3:

checking for BZip2 in default path... not found.       configure: error: Please reinstall the BZip2 distribution

解决办法:yum insall -y bzip2-devel

错误4:

configure: error: jpeglib.h not found

解决办法:yum install -y libjpeg-devel

错误5:

configure: error: png.h not found

解决办法:yum install -y libpng-devel

错误6:

configure: error:  freetype.h not found

解决办法:yum install -y freetype-devel

错误7:

configure: error:  mcrypt.h not found. Please reinstall libmcrypt

解决办法:yum install -y epel-release    yum install -y libmcrypt-devel

CentOS默认的 yum 源没有 libmcrypt-devel 这个包,所以只能借助 epel yum 扩展源

④编译和安装

#make可能会好几分钟
make
make install
#同样,还是通过下面看安装成功没有
echo $?

⑤复制配置文件(此时我们仍在 /usr/local/src/php-5.6.38 中)

cp php.ini-production /usr/local/php/etc/php.ini

猜你喜欢

转载自blog.csdn.net/CHEndorid/article/details/82960795
今日推荐