环境说明:

系统平台IP需要安装的服务
Redhat8192.168.160.130

httpd-2.4

mysql

php

php-mysql

lamp平台软件安装次序:

httpd——MySQL——php

1、配置环境yum源

在阿里云里找

选择centos8的

再把云相关的干掉

先配置yum源

[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100  2495  100  2495    0     0  12053      0 --:--:-- --:--:-- --:--:-- 11995[root@localhost yum.repos.d]# lsCentOS-Base.repo[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo[root@localhost yum.repos.d]# cd[root@localhost ~]# yum clean all      //清理一下缓存正在更新 Subscription Management 软件仓库。无法读取客户身份本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。0 文件已删除[root@localhost ~]# 

再配置一下epel源

安装

设置一下

配置epel源

[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*[root@localhost ~]# yum clean all[root@localhost ~]# yum makecache     //重建缓存[root@localhost ~]# yum -y install wget vim   //下载一下wget和vim命令

2、编译安装httpd

Index of /apache 在里面找源码包(apr和httpd文件夹里)

[root@localhost ~]# yum groups mark install 'Development Tools'   //标记安装一下[root@localhost ~]# useradd -r -M -s /sbin/nologin apache   //-r系统用户,-M没有目录,-s不允许登录,创建用户的时候会自动创建跟用户名相同的组[root@localhost ~]#  yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make    //安装依赖包//下载源码包[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz//解压[root@localhost ~]# tar xf apr-1.7.0.tar.gz[root@localhost ~]# tar xf apr-util-1.6.1.tar.gz[root@localhost ~]# tar xf httpd-2.4.53.tar.gz//编译apr-1.7.0[root@localhost ~]# cd apr-1.7.0[root@localhost apr-1.7.0]# vim configure$RM "$cfgfile"   //把这个删掉[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr[root@localhost apr-1.7.0]# make[root@localhost apr-1.7.0]# make install //编译apr-util-1.6.1[root@localhost ~]# cd apr-util-1.6.1[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr[root@localhost apr-util-1.6.1]# make[root@localhost apr-util-1.6.1]# make install //编译httpd-2.4.53[root@localhost ~]# cd httpd-2.4.53[root@localhost httpd-2.4.53]# ./configure --prefix=/usr/local/apache \> --enable-so \> --enable-ssl \> --enable-cgi \> --enable-rewrite \> --with-zlib \> --with-pcre \> --with-apr=/usr/local/apr \> --with-apr-util=/usr/local/apr-util/ \> --enable-modules=most \> --enable-mpms-shared=all \> --with-mpm=prefork[root@localhost apr-1.7.0]# make[root@localhost apr-1.7.0]# make install //设置环境变量[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh[root@localhost ~]# source /etc/profile.d/apache.sh[root@localhost ~]# which httpd/usr/local/apache/bin/httpd//映射[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/apache//man文档[root@localhost ~]# vim /etc/man_db.conf MANDATORY_MANPATH                       /usr/manMANDATORY_MANPATH                       /usr/share/manMANDATORY_MANPATH                       /usr/local/share/manMANDATORY_MANPATH                       /usr/local/apache/man//怎么来启动使用这个服务//关闭防火墙[root@localhost ~]# systemctl disable --now firewalld[root@localhost ~]# setenforce 0[root@localhost ~]# getenforce Permissive[root@localhost ~]# vim /etc/selinux/config SELINUX=disabled   //把这个改为disabled//启动服务[root@localhost ~]# ss -antlState      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     LISTEN     0          128                  0.0.0.0:111               0.0.0.0:*                   LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   LISTEN     0          5                  127.0.0.1:631               0.0.0.0:*                   LISTEN     0          128                     [::]:111                  [::]:*                   LISTEN     0          128                     [::]:22                   [::]:*                   LISTEN     0          5                      [::1]:631                  [::]:*      //如果想设置成systemctl来控制启动,并且设置开机自启[root@localhost ~]# cd /usr/lib/systemd/system[root@localhost system]# ls sshd.service sshd.service[root@localhost system]# cp sshd.service httpd.servicecp:是否覆盖'httpd.service'? y[root@localhost system]# vim httpd.service     //配置修改 [Unit]Description=httpd server daemonAfter=network.target sshd-keygen.target [Service]Type=forkingExecStart=/usr/local/apache/bin/apachectl startExecStop=/usr/local/apache/bin/apachectl stopExecReload=/bin/kill -HUP $MAINPID [Install]WantedBy=multi-user.target[root@localhost system]# systemctl daemon-reload[root@localhost system]# cd[root@localhost ~]# systemctl status httpd    //查看一下这个服务,有了[root@localhost ~]# systemctl start httpd    //现在可以用systemctl来控制启动了[root@localhost ~]# systemctl enable httpd       //设置开机自启

3、MySQL安装(用二进制安装)

//用xftp传输到虚拟的/usr/src里[root@localhost ~]# ls /usr/srcdebug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

创建用户和组

//创建用户的时候会自动创建组[root@localhost ~]# cd /usr/src[root@localhost src]# useradd -r -M -s /sbin/nologin mysql   [root@localhost src]# id mysqluid=995(mysql) gid=992(mysql) groups=992(mysql)

解压软件至/usr/local

[root@localhost src]# ls /usr/localbin  games    lib    libexec  shareetc  include  lib64  sbin     src[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/[root@localhost src]# ls /usr/localbin    include  libexec                              shareetc    lib      mysql-5.7.37-linux-glibc2.12-x86_64  srcgames  lib64    sbin[root@localhost src]# cd /usr/local/[root@localhost local]#  //更改名字为mysql[root@localhost local]# mv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql[root@localhost local]# lsbin  games    lib    libexec  sbin   srcetc  include  lib64  mysql    share[root@localhost local]# lltotal 0drwxr-xr-x. 2 root root   6 Jun 21  2021 bindrwxr-xr-x. 2 root root   6 Jun 21  2021 etcdrwxr-xr-x. 2 root root   6 Jun 21  2021 gamesdrwxr-xr-x. 2 root root   6 Jun 21  2021 includedrwxr-xr-x. 2 root root   6 Jun 21  2021 libdrwxr-xr-x. 3 root root  17 Apr 27 16:32 lib64drwxr-xr-x. 2 root root   6 Jun 21  2021 libexecdrwxr-xr-x. 9 root root 129 Jun 28 17:04 mysqldrwxr-xr-x. 2 root root   6 Jun 21  2021 sbindrwxr-xr-x. 5 root root  49 Apr 27 16:32 sharedrwxr-xr-x. 2 root root   6 Jun 21  2021 src //修改目录/usr/local/mysql的属主属组[root@localhost local]# chown -R mysql.mysql mysql[root@localhost local]# lltotal 0drwxr-xr-x. 2 root  root    6 Jun 21  2021 bindrwxr-xr-x. 2 root  root    6 Jun 21  2021 etcdrwxr-xr-x. 2 root  root    6 Jun 21  2021 gamesdrwxr-xr-x. 2 root  root    6 Jun 21  2021 includedrwxr-xr-x. 2 root  root    6 Jun 21  2021 libdrwxr-xr-x. 3 root  root   17 Apr 27 16:32 lib64drwxr-xr-x. 2 root  root    6 Jun 21  2021 libexecdrwxr-xr-x. 9 mysql mysql 129 Jun 28 17:04 mysqldrwxr-xr-x. 2 root  root    6 Jun 21  2021 sbindrwxr-xr-x. 5 root  root   49 Apr 27 16:32 sharedrwxr-xr-x. 2 root  root    6 Jun 21  2021 src

添加环境变量

[root@localhost local]# ls mysql/bin   include  LICENSE  README  support-filesdocs  lib      man      share[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh[root@localhost local]# source /etc/profile.d/mysql.sh [root@localhost local]# which mysql/usr/local/mysql/bin/mysql //要告诉路径[root@localhost local]# cd mysql/[root@localhost mysql]# pwd/usr/local/mysql[root@localhost mysql]# lsbin   include  LICENSE  README  support-filesdocs  lib      man      share[root@localhost mysql]# ls /usr/bin    include  lib64    local  share  tmpgames  lib      libexec  sbin   src[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql[root@localhost mysql]# vi /etc/ld.so.conf.d/mysql.conf/usr/local/mysql/lib[root@localhost mysql]# ldconfig    //重新读取一下路径 

建立数据存放目录

[root@localhost mysql]# cd[root@localhost ~]# mkdir -p /opt/data[root@localhost ~]# chown -R mysql.mysql /opt/data[root@localhost ~]# ll /opt/total 0drwxr-xr-x. 2 mysql mysql 6 Jun 28 17:31 data

初始化数据库

[root@localhost ~]# which mysqld/usr/local/mysql/bin/mysqld[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data2022-06-28T09:35:52.428070Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2022-06-28T09:35:52.617289Z 0 [Warning] InnoDB: New log files created, LSN=457902022-06-28T09:35:52.652877Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2022-06-28T09:35:52.706287Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b3cb1102-f6c5-11ec-a88a-000c29d84a24.2022-06-28T09:35:52.706953Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2022-06-28T09:35:53.108617Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.2022-06-28T09:35:53.108629Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.2022-06-28T09:35:53.109012Z 0 [Warning] CA certificate ca.pem is self signed.2022-06-28T09:35:53.140487Z 1 [Note] A temporary password is generated for root@localhost: /cNErFpy9A#>      //临时密码只能用一次 //先将密码保存下来nerated for root@localhost: /cNErFpy9A#>[root@localhost ~]# echo '/cNErFpy9A#>' > pass[root@localhost ~]# lsanaconda-ks.cfg  pass

生成配置文件

[root@localhost ~]# cat /etc/my.cnfcat: /etc/my.cnf: No such file or directory[root@localhost ~]# vi /etc/my.cnf[root@localhost ~]# cat /etc/my.cnf[mysqld]basedir = /usr/local/mysqldatadir = /opt/datasocket = /tmp/mysql.sockport = 3306pid-file = /opt/data/mysql.piduser = mysqlskip-name-resolve#sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION[root@localhost ~]# 

配置服务

[root@localhost ~]# cd /usr/local/mysql/[root@localhost mysql]# lsbin   include  LICENSE  README  support-filesdocs  lib      man      share[root@localhost mysql]# cd support-files/[root@localhost support-files]# lsmagic  mysqld_multi.server  mysql-log-rotate  mysql.server[root@localhost support-files]# cp mysql.server mysqld[root@localhost support-files]# lltotal 36-rw-r--r--. 1 mysql mysql   773 Nov 30  2021 magic-rwxr-xr-x. 1 root  root  10576 Jun 28 17:47 mysqld-rwxr-xr-x. 1 mysql mysql  1061 Nov 30  2021 mysqld_multi.server-rwxr-xr-x. 1 mysql mysql   894 Nov 30  2021 mysql-log-rotate-rwxr-xr-x. 1 mysql mysql 10576 Nov 30  2021 mysql.server[root@localhost support-files]# chown -R mysql.mysql mysqld[root@localhost support-files]# lltotal 36-rw-r--r--. 1 mysql mysql   773 Nov 30  2021 magic-rwxr-xr-x. 1 mysql mysql 10576 Jun 28 17:47 mysqld-rwxr-xr-x. 1 mysql mysql  1061 Nov 30  2021 mysqld_multi.server-rwxr-xr-x. 1 mysql mysql   894 Nov 30  2021 mysql-log-rotate-rwxr-xr-x. 1 mysql mysql 10576 Nov 30  2021 mysql.server [root@localhost support-files]# vi mysqldbasedir=/usr/local/mysqldatadir=/opt/data       //找到里面这个为空的地方加上这些 比如:datadir=

启动mysql

[root@localhost ~]# /usr/local/mysql/support-files/mysqld startStarting MySQL.Logging to '/opt/data/localhost.localdomain.err'. SUCCESS! [root@localhost ~]# ss -antlState  Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                                        LISTEN 0       128            0.0.0.0:22          0.0.0.0:*                                                                   LISTEN 0       80                   *:3306              *:*                                                                   LISTEN 0       128               [::]:22             [::]:*    [root@localhost ~]# ps -ef|grep mysqldroot        1862       1  0 17:57 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pidmysql       2050    1862  0 17:57 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306root        2086    1668  0 18:00 pts/0    00:00:00 grep --color=auto mysqld

使用临时密码登录,修改密码

[root@localhost ~]# lsanaconda-ks.cfg  pass[root@localhost ~]# cat pass/cNErFpy9A#>[root@localhost ~]# mysql -uroot -p'/cNErFpy9A#>'mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory    //出现这个报错,没有这个包[root@localhost ~]# yum provides libncurses.so.5         //查看属于哪个包Updating Subscription Management repositories.Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:00:26 ago on Tue 28 Jun 2022 06:12:22 PM CST.ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses     ...: compatibility librariesRepo        : baseMatched from:Provide    : libncurses.so.5[root@localhost ~]# yum -y install ncurses-compat-libs  //登录//修改密码[root@localhost ~]# mysql -uroot -p'/cNErFpy9A#>'mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.37 Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set password = password('ltt429520.');Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> quitBye  //用新密码验证一下[root@localhost ~]# mysql -uroot -p'ltt429520.'mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> quitBye[root@localhost ~]#  

设置开机自启

[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service mysqld.service[root@localhost ~]# lsanaconda-ks.cfg  mysqld.service  pass[root@localhost ~]# vim mysqld.service [root@localhost ~]# cat mysqld.service [Unit]Description=mysql server daemonAfter=network.target sshd-keygen.target [Service]Type=forkingExecStart=/usr/local/mysql/support-files/mysqld startExecStop=/usr/local/mysql/support-files/mysqld stopExecReload=/bin/kill -HUP $MAINPID [Install]WantedBy=multi-user.target [root@localhost ~]# mv mysqld.service /usr/lib/systemd/system/[root@localhost ~]# lsanaconda-ks.cfg  pass[root@localhost ~]# systemctl disable --now firewalldRemoved /etc/systemd/system/multi-user.target.wants/firewalld.service.Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.[root@localhost ~]# setenforce 0[root@localhost ~]# vim /etc/selinux/config [root@localhost ~]# systemctl daemon-reload[root@localhost ~]# systemctl status mysqld● mysqld.service - mysql server daemon   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; dis>   Active: inactive (dead)[root@localhost ~]# ss -antlState  Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                                        LISTEN 0       128            0.0.0.0:22          0.0.0.0:*                                                                   LISTEN 0       80                   *:3306              *:*                                                                   LISTEN 0       128               [::]:22             [::]:*                                                                   [root@localhost ~]# pkill mysqld[root@localhost ~]# ss -antlState  Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                                        LISTEN 0       128            0.0.0.0:22          0.0.0.0:*                                                                   LISTEN 0       128               [::]:22             [::]:*   [root@localhost ~]# systemctl start mysqld   //启动[root@localhost ~]# ss -antlState  Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                                        LISTEN 0       128            0.0.0.0:22          0.0.0.0:*                                                                   LISTEN 0       80                   *:3306              *:*                                                                   LISTEN 0       128               [::]:22             [::]:*                                                                   [root@localhost ~]# mysql -uroot -p'ltt429520.'mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> quitBye[root@localhost ~]# systemctl enable mysqld[root@localhost ~]# systemctl status mysqld● mysqld.service - mysql server daemon   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; ena>   Active: active (running) since Tue 2022-06-28 18:48:13 CST;> Main PID: 10913 (mysqld_safe)    Tasks: 29 (limit: 11216)   Memory: 186.0M   CGroup: /system.slice/mysqld.service           ├─10913 /bin/sh /usr/local/mysql/bin/mysqld_safe -->           └─11103 /usr/local/mysql/bin/mysqld --basedir=/usr/> Jun 28 18:48:12 localhost.localdomain systemd[1]: Starting mys>Jun 28 18:48:13 localhost.localdomain mysqld[10900]: Starting >Jun 28 18:48:13 localhost.localdomain systemd[1]: Started mysq>[root@localhost ~]# reboot //看看开机自启设置成功没[root@localhost ~]# getenforceDisabled[root@localhost ~]# echo $" />

记事本内

//记事本里添加# Copyright (c) 1993-2009 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows.## This file contains the mappings of IP addresses to host names. Each# entry should be kept on an individual line. The IP address should# be placed in the first column followed by the corresponding host name.# The IP address and the host name should be separated by at least one# space.## Additionally, comments (such as these) may be inserted on individual# lines or following the machine name denoted by a '#' symbol.## For example:##      102.54.94.97     rhino.acme.com          # source server#       38.25.63.10     x.acme.com              # x client host# localhost name resolution is handled within DNS itself.#127.0.0.1       localhost#::1             localhost127.0.0.1         activate.navicat.com192.168.160.130 test.example.com

服务重启

[root@localhost ~]# systemctl stop httpd[root@localhost ~]# systemctl restart httpd[root@localhost ~]# ss -antlState  Recv-Q Send-Q Local Address:Port   Peer Address:Port Process LISTEN 0      128        127.0.0.1:9000        0.0.0.0:*            LISTEN 0      128          0.0.0.0:22          0.0.0.0:*            LISTEN 0      80                 *:3306              *:*            LISTEN 0      128                *:80                *:*            LISTEN 0      128             [::]:22             [::]:*      

浏览器

192.168.160.130访问

test.example.com访问