一、源码编译安装nginx
1.安装需要的软件包和编译工具
[root@raoling ~]# yum -y install gcc gcc-c++ make wget
2.官网下载最新nginx源码并解压
[root@raoling ~]# wget http://nginx.org/download/nginx-1.24.0.tar.gz
//解压
[root@raoling ~]# tar xf nginx-1.24.0.tar.gz
[root@raoling ~]# cd nginx-1.24.0/
[root@raoling nginx-1.24.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
3.编译组件,指定编译参数
//指定安装的路径
[root@raoling nginx-1.24.0]# ./configure --prefix=/usr/local/nginx
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
//以下是关于nginx软件的各种目录信息
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
4.编译并安装
[root@raoling nginx-1.24.0]# make && make install
5.启动nginx服务
//进入安装nginx的目录下的/sbin目录
[root@raoling nginx-1.24.0]# cd /usr/local/nginx/
[root@raoling nginx]# ls
conf html logs sbin
[root@raoling nginx]# cd sbin/
[root@raoling sbin]# ls
nginx
[root@raoling sbin]# ./nginx
[root@raoling sbin]#
//查看端口号
[root@raoling sbin]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:80 0.0.0.0:* //80端口已经起来了
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
6.配置环境变量 确保可以使用nginx命令
[root@raoling ~]# echo 'export PATH=$PATH:/usr/local/nginx/sbin' >>
/etc/profile.d/nginx.sh
[root@raoling ~]# bash
编译安装apache httpd##
1.关闭防火墙,将apache需要的软件包 传到/opt目录下
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
httpd-2.4.29.tar.gz
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
2.安装环境依赖包
yum -y install \
gcc \ #C语言的编译器
gcc-c++ \ #C++的编译器
make \ #源代码编译器(源代码转换成二进制文件)
pcre \ #pcre是一个Perl函数库,包括perl 兼容的正则表达式库
pcre-devel \ #perl的接口开发包
expat-devel \ #用于支持网站解析HTML、XML文件
perl #perl语言编译
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl
3.配置软件模块
cd /opt/
tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2
mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util
cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \ #指定将 httpd 服务程序的安装路径
--enable-so \ #启用动态加载模块支持,使 httpd 具备进一步扩展功能的能力
--enable-rewrite \ #启用网页地址重写功能,用于网站优化、防盗链及目录迁移维护
--enable-charset-lite \ #启动字符集支持,以便支持使用各种字符集编码的页面
--enable-cgi #启用CGI(通用网关接口)脚本程序支持,便于网站的外部扩展应用访问能力
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
4.编译并安装
make && make install
5.创建软连接
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
6.添加httpd服务
vim /lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server #描述
After=network.target #描述服务类别
[Service]
Type=forking #后台运行方式
PIDFile=/usr/local/httpd/logs/httpd.pid #PID文件位置
ExecStart=/usr/local/bin/apachectl $OPTIONS #启动服务
ExecReload=/bin/kill -HUP $MAINPID #根据PID重载配置
[Install]
WantedBy=multi-user.target
systemctl start httpd.service
systemctl enable httpd.service
7.修改httpd配置文件
vim /etc/httpd.conf
--52行--修改
Listen 192.198.184.10:80
--197行--取消注释,修改
ServerName www.lic.com:80
--221行--默认首页存放路径
DocumentRoot "/usr/local/httpd/htdocs"
--255行--默认首页文件名设置
DirectoryIndex index.html
httpd -t 或 apachectl -t #检查配置文件的配置项是否有误
cat /usr/local/httpd/htdocs/index.html
systemctl restart httpd.service
8.验证
编译安装MySQL
1.创建mysql用户和组
[root@raoling ~]# groupadd -r -g 306 mysql
[root@raoling ~]# useradd -r -//解压源码包到/usr/local/
[root@raoling ~]# tar -xf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz -C
/usr/local/M -s /sbin/nologin -g 306 -u 306 mysql
[root@raoling ~]# ls /usr/local/
apache bin include libexec share
apr etc lib mysql-5.7.39-linux-glibc2.12-x86_64 src
apr-util games lib64 sbin
2.创建链接
[root@raoling local]# ls
apache bin include libexec share
apr etc lib mysql-5.7.39-linux-glibc2.12-x86_64 src
apr-util games lib64 sbin
[root@raoling local]# ln -sv mysql-5.7.39-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.39-linux-glibc2.12-x86_64/'
[root@raoling local]# ll
total 0
drwxr-xr-x. 13 root root 152 Aug 28 15:50 apache
drwxr-xr-x. 6 root root 58 Aug 28 15:23 apr
drwxr-xr-x. 5 root root 43 Aug 28 15:28 apr-util
drwxr-xr-x. 2 root root 6 Jun 22 2021 bin
drwxr-xr-x. 2 root root 6 Jun 22 2021 etc
drwxr-xr-x. 2 root root 6 Jun 22 2021 games
drwxr-xr-x. 2 root root 6 Jun 22 2021 include
drwxr-xr-x. 2 root root 6 Jun 22 2021 lib
drwxr-xr-x. 3 root root 17 Aug 28 09:46 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
lrwxrwxrwx. 1 root root 36 Aug 28 16:31 mysql -> mysql-5.7.39-linux-glibc2.12-
x86_64/
drwxr-xr-x. 9 root root 129 Aug 28 16:28 mysql-5.7.39-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 Jun 22 2021 sbin
drwxr-xr-x. 5 root root 49 Aug 28 09:46 share
drwxr-xr-x. 2 root root 6 Jun 22 2021 src
//修改目录/usr/local/mysql的属主属组
[root@raoling local]# chown -R mysql:mysql /usr/local/mysql
[root@raoling local]# ll /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 36 Aug 28 16:31 /usr/local/mysql -> mysql-5.7.39-
linux-glibc2.12-x86_64/2w1a
修改目录/usr/local/mysql的属主属组
[root@raoling local]# chown -R mysql:mysql /usr/local/mysql
[root@raoling local]# ll /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 36 Aug 28 16:31 /usr/local/mysql -> mysql-5.7.39-
linux-glibc2.12-x86_64/2w1a