部署LAMT

LAMT

lamt部署

环境说明:

系统平台IP需要安装的服务
centos8192.168.10.22httpd-2.4 mysql-5.7 tomcat

lamp平台软件安装次序:

    httpd --> mysql --> tomcat

注意:php要求httpd使用prefork MPM

安装httpd

#先卸载系统默认安装的httpd
[root@localhost ~]# yum -y remove httpd

#下载好apr、apr-util和httpd的包
[root@localhost ~]# wget https://mirrors.bfsu.edu.cn/apache/apr/apr-1.7.0.tar.bz2
[root@localhost ~]# wget https://mirrors.bfsu.edu.cn/apache/apr/apr-util-1.6.1.tar.bz2
[root@localhost ~]# wget https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.46.tar.bz2

#安装包组等
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y groups  mark install 'Development Tools'

#创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache

#安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make bzip2

#安装apr以及apr-util
[root@localhost ~]# tar xf apr-1.7.0.tar.bz2 
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2 
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2 
[root@localhost ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    #$RM "$cfgfile"		#把这一行注释掉或者删掉

    cat <<_LT_EOF >> "$cfgfile"
#编译安装apr
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make & make install

#编译安装apr-util
[root@localhost apr-1.7.0]# 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 & make install

#编译安装httpd
[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.43/
[root@localhost httpd-2.4.43]# ./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--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 httpd-2.4.43]# make & make install

#配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/http.sh
[root@localhost ~]# source /etc/profile.d/http.sh 

#映射头文件
[root@localhost ~]# ln -s /usr/local/apache/include /usr/include/httpd

#帮助文档
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man		#添加这一条

#启动httpd
[root@localhost ~]# apachectl start

#关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
#永久关闭防火墙
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@localhost ~]# vim /etc/selinux/config 
#     disabled - No SELinux policy is loaded.
SELINUX=disabled			#把这里改成disabled

[root@localhost ~]# ss -antl
State           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                                  *:80                                *:*                            
LISTEN          0               128                               [::]:22                             [::]:*                            


安装mysql

#安装依赖包
[root@localhost ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

#创建mysql服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

#下载二进制格式的mysql软件包
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz

#解压到/usr/local/里
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql-5.7.33-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

#修改属主和属组
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ll mysql/
total 264
drwxr-xr-x.  2 mysql mysql   4096 May 12 10:13 bin
drwxr-xr-x.  2 mysql mysql     55 May 12 10:13 docs
drwxr-xr-x.  3 mysql mysql   4096 May 12 10:12 include
drwxr-xr-x.  5 mysql mysql    230 May 12 10:13 lib
-rw-r--r--.  1 mysql mysql 250129 Dec  9 22:01 LICENSE
drwxr-xr-x.  4 mysql mysql     30 May 12 10:12 man
-rw-r--r--.  1 mysql mysql    566 Dec  9 22:01 README
drwxr-xr-x. 28 mysql mysql   4096 May 12 10:13 share
drwxr-xr-x.  2 mysql mysql     90 May 12 10:13 support-files

#添加环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh 

#给头文件做软连接
[root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql

#库文件
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib		#添加这个
[root@localhost ~]# ldconfig 

#man文档
[root@localhost ~]# vim /etc/man_db.conf 
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
MANDATORY_MANPATH                       /usr/local/mysql/man		#添加这一行内容

#创建数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data

#初始化数据库
root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-12T14:25:38.875806Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-12T14:25:39.516844Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-12T14:25:39.602382Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-12T14:25:39.658834Z 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: ed087633-b32d-11eb-b3ef-000c29a3d1ed.
2021-05-12T14:25:39.666061Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-12T14:25:40.418925Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-12T14:25:40.521392Z 1 [Note] A temporary password is generated for root@localhost: D!;GR)Q%o8Cs		#记住这个密码后面会用到
[root@localhost ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF								#注意,这里如果这个文件里有实质性的内容,建议备份一下,再覆盖。

#配置启动脚本
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data

#启动脚本并修改密码
[root@localhost ~]# service mysqld start 
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# ss -antl
State           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                                  *:80                                *:*                            
LISTEN          0               128                               [::]:22                             [::]:*                            
[root@localhost ~]# dnf -y install ncurses-compat-libs
[root@localhost ~]# mysql -uroot -p'D!;GR)Q%o8Cs'
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 2
Server version: 5.7.33

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('asd123321');
Query OK, 0 rows affected, 1 warning (0.00 sec)

#设置开机自启
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

安装tomcat

#安装jdk环境
[root@localhost local]# yum -y install java-11-openjdk java-11-openjdk-devel
#下载tomcat
[root@localhost local]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.46/bin/apache-tomcat-9.0.46.tar.gz
[root@localhost local]# tar xf apache-tomcat-9.0.46.tar.gz
[root@localhost local]# mv apache-tomcat-9.0.46 tomcat
[root@localhost local]# rm -rf apache-tomcat-9.0.46.tar.gz

配置apache

#启用代理模块
[root@localhost ~]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_http_module modules/mod_proxy_http.so   #取消这三条的注释
#修改虚拟主机的配置文件
[root@localhost httpd24]# vim /etc/httpd24/httpd.conf
# Various default settings
#Include /etc/httpd24/extra/httpd-default.conf
Include /etc/httpd24/extra/vhosts.conf		#添加这一条
[root@localhost httpd24]# cd /etc/httpd24/extra/
[root@localhost extra]# vim vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ProxyPass / http://192.168.10.22:8080/
    ProxyPassReverse / http://192.168.10.22:8080/
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>
[root@localhost extra]# vim /etc/httpd24/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.jsp index.html
</IfModule>

image-20210615205711916

 Options none
    AllowOverride none
    Require all granted
</Directory>
[root@localhost extra]# vim /etc/httpd24/httpd.conf DirectoryIndex index.jsp index.html ```

[外链图片转存中…(img-wttpHr6x-1623761854505)]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值