7. 构建LNAMP高性能WEB服务器架构

时间:2021-10-23 18:36:11

Nginx 安装

[root@nginx2 ~]# yum install gcc-c++ -y

安装nginx的时候需要的依赖包,解压即可

[root@nginx2 software]# tar -xvf openssl-1.1.0g.tar.gz

[root@nginx2 software]# tar -xvf pcre-8.41.tar.gz

[root@nginx2 software]# tar -xvf zlib-1.2.11.tar.gz

[root@nginx2 software]# tar -xvf nginx-1.12.2.tar.gz

 

添加用户

[root@nginx2 software]# useradd nginx

 

[root@nginx2 software]# cd nginx-1.12.2/

 

配置:

[root@nginx2 nginx-1.12.2]#  ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/software/openssl-1.1.0g --with-pcre=/software/pcre-8.41 --with-zlib=/software/zlib-1.2.11 --with-http_stub_status_module --conf-path=/usr/local/nginx/nginx.conf

 

编译&安装

[root@nginx2 nginx-1.12.2]# make && make install

 

测试&启动

[root@nginx2 ~]# cd /usr/local/nginx/sbin/

 

[root@nginx2 sbin]# ./nginx -t

nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/nginx.conf test is successful

[root@nginx2 sbin]# ./nginx

[root@nginx2 sbin]# ps -ef | grep nginx

root      66606      1  0 22:05 ?        00:00:00 nginx: master process ./nginx

nginx     66607  66606  0 22:05 ?        00:00:00 nginx: worker process

root      66617  47667  0 22:05 pts/0    00:00:00 grep --color=auto nginx

 

安装Apache

安装依赖包:

[root@nginx2 software]# yum install libtool -y

 

 

其他三个包aprapr-utilpcre

Apr

[root@nginx2 software]# tar -xvf apr-1.6.3.tar.gz

[root@nginx2 software]# cd apr-1.6.3/
[root@nginx2 apr-1.6.3]# ./configure --prefix=/usr/local/apr/

安装的时候会报错:

rm: cannot remove 'libtoolT': No such file or directory

F1:我们需要把configure文件,查找 $RM "$cfgfile" 这个地方,用#注释掉

F2:configure里面 RM='$RM  -f'   这里的$RM后面一定有一个空格。 如果后面没有空格,直接连接减号,就依然会报错。把RM='$RM'改为RM='$RM  -f'

[root@nginx2 apr-1.6.3]# make && make install

 

Apr-util

[root@nginx2 software]# yum install expat-devel -y

[root@nginx2 software]# tar -xvf apr-util-1.6.1.tar.gz

[root@nginx2 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/ && make && make install

 

Pcre

[root@nginx2 software]# tar -xvf pcre-8.41.tar.gz

[root@nginx2 software]# cd pcre-8.41/

[root@nginx2 pcre-8.41]# ./configure --prefix=/usr/local/pcre/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/

[root@nginx2 pcre-8.41]# make && make install

 

安装apache

[root@nginx2 software]# tar -xvf httpd-2.4.29.tar.gz

[root@nginx2 software]# cd httpd-2.4.29/

[root@nginx2 httpd-2.4.29]# ./configure --help

[root@nginx2 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/

[root@nginx2 httpd-2.4.29]# make && make install

[root@nginx2 httpd-2.4.29]# cd /usr/local/apache2/

 

先停止nginx ,我们先测试apache是否安装成功

[root@nginx2 apache2]# /usr/local/nginx/sbin/nginx -s stop

[root@nginx2 apache2]# vi conf/httpd.conf

[...]

ServerName localhost:80

[...]

[root@nginx2 apache2]# ./bin/apachectl start

 

[root@nginx2 apache2]# ./bin/apachectl stop

 

apache服务脚本加入到initd目录

[root@nginx2 ~]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

接着我们安装数据库

安装mysql

或者安装mariadb

https://downloads.mariadb.org/mariadb/repositories/#mirror=neusoft&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.2

我们这里选择安装mysql数据库

 

安装cmakencurses-devel

[root@nginx2 software]# yum install cmake -y

[root@nginx2 software]# yum install ncurses-devel -y

 

创建用户

[root@nginx2 ~]# useradd -r -U mysql -M -d /usr/local/mysql/data

 

修改安装目录的所有者和所有组

[root@nginx2 ~]# mkdir /usr/local/mysql
[root@nginx2 ~]# chown -R mysql:mysql /usr/local/mysql

 

修改数据目录的所有者和所有组

[root@nginx2 ~]# mkdir -p /data/mysql

[root@nginx2 ~]# chown -R mysql:mysql /data/mysql/

 

解压

[root@nginx2 ~]# cd /software/
[root@nginx2 software]# tar -xvf mysql-5.6.24.tar.gz

 

配置编译参数

[root@nginx2 mysql-5.6.24]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306

 

安装

[root@nginx2 mysql-5.6.24]# make && make install

 

初始化数据库

[root@nginx2 mysql-5.6.24]# cd /usr/local/mysql/
[root@nginx2 mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql

 

复制mysql服务启动配置文件

[root@nginx2 mysql]# cp /etc/my.cnf /etc/my.cnf.bak
[root@nginx2 mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

 

复制mysql服务启动脚步及加入PATH路径

[root@nginx2 mysql]# vi /etc/profile
[...]

PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH

[root@nginx2 mysql]# source /etc/profile

 

修改配置文件

user=mysql
port=3306
socket=/data/mysql/mysql.sock
datadir=/data/mysql/
basedir=/usr/local/mysql/
explicit_defaults_for_timestamp=true