lamt部署
Posted 卑微小胡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamt部署相关的知识,希望对你有一定的参考价值。
lamt部署
安装apache
安装依赖包和需要的软件
[root@localhost ~]# dnf -y install gcc gcc-c++ make pcre-devel openssl openssl-devel libtool expat-devel bzip2
#安装过程
依次解压源码包
[root@localhost ~]# ls
anaconda-ks.cfg httpd-2.4.43.tar.bz2
apr-1.7.0.tar.bz2 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
apr-util-1.6.1.tar.bz2
[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 ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.bz2
apr-1.7.0 httpd-2.4.43
apr-1.7.0.tar.bz2 httpd-2.4.43.tar.bz2
apr-util-1.6.1 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
httpd依赖apr和apr-util,apr-util又依赖apr所以得按照顺序先安装apr再安装apr-util最后安装httpd
安装apr
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# sed -i '/$RM "$cfgfile"/d' configure
[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
[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
#编译过程省略
[root@localhost apr-util-1.6.1]# 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
#编译过程省略
[root@localhost httpd-2.4.43]# make install
#编译安装过程省略
关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
启动apache服务
[root@localhost ~]# /usr/local/apache/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[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 [::]:*
打开浏览器输入ip地址
安装MySQL
#创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
#解压到指定文件
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ls /usr/local/
apache bin include libexec share
apr etc lib mysql-5.7.33-linux-glibc2.12-x86_64 src
apr-util games lib64 sbin
#创建软连接
[root@localhost ~]# ln -s /usr/local/mysql-5.7.33-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@localhost ~]# ll /usr/local/
total 0
......
lrwxrwxrwx. 1 root root 47 May 6 10:58 mysql -> /usr/local/mysql-5.7.33-linux-glibc2.12-x86_64/
......
#修改用户属主和属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql*
[root@localhost ~]# ll /usr/local/
......
lrwxrwxrwx. 1 mysql mysql 47 May 6 10:58 mysql -> /usr/local/mysql-5.7.33-linux-glibc2.12-x86_64/
......
#添加环境变量
[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 ~]# which mysql
/usr/local/mysql/bin/mysql
#创建存放数据的目录并修改属主属组
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 May 6 11:13 data
初始化数据库
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-06T03:16:40.204343Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-06T03:16:40.544276Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-06T03:16:40.583123Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-06T03:16:40.594012Z 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: 79cebdcb-ae19-11eb-ac91-000c29a69e07.
2021-05-06T03:16:40.595677Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-06T03:16:41.199204Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-06T03:16:41.336981Z 1 [Note] A temporary password is generated for root@localhost: ca2JkmmVua>d //这里是root用户的临时密码,此处密码是ca2JkmmVua>d
//注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到
[root@localhost ~]# ls /opt/data/ //初始化好了这里就有数据了
auto.cnf ibdata1 public_key.pem
ca-key.pem ib_logfile0 server-cert.pem
ca.pem ib_logfile1 server-key.pem
client-cert.pem mysql sys
client-key.pem performance_schema
ib_buffer_pool private_key.pem
写配置文件
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[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
配置服务启动脚本
root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# ll /etc/init.d/
total 36
-rw-r--r--. 1 root root 18434 Feb 15 23:09 functions
-rwxr-xr-x. 1 mysql mysql 10576 Dec 10 11:23 mysqld
-rw-r--r--. 1 root root 1161 Mar 17 03:42 README
[root@localhost ~]# vim /etc/init.d/mysqld
......
basedir=/usr/local/mysql //环境变量目录
datadir=/opt/data //数据存储目录
......
启动MySQL
[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 ~]# cat pass
ca2JkmmVua>d
[root@localhost ~]# mysql -uroot -p'ca2JkmmVua>d'
mysql> set password = password('填入你要修改的密码');
Query OK, 0 rows affected, 1 warning (0.00 sec)
安装tomcat
安装jdk
[root@localhost ~]# dnf -y install java-11-openjdk java-11-openjdk-devel
#安装过程省略
#查看安装的版本
[root@localhost ~]# java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)
安装tomcat
tomcat官网tomcat.apache.org
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.bz2
apache-tomcat-9.0.37.tar.gz httpd-2.4.43
apr-1.7.0 httpd-2.4.43.tar.bz2
apr-1.7.0.tar.bz2 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
apr-util-1.6.1 pass
[root@localhost ~]# tar xf apache-tomcat-9.0.37.tar.gz
[root@localhost ~]# mv apache-tomcat-9.0.37 /usr/local/tomcat
[root@localhost ~]# ls /usr/local/
apache bin include libexec sbin tomcat
apr etc lib mysql share
apr-util games lib64 mysql-5.7.33-linux-glibc2.12-x86_64 src
启动tomcat
[root@localhost ~]# cd /usr/local/tomcat/
[root@localhost tomcat]# bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
配置apache
取消以下注释
[root@localhost tomcat]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
Include /etc/httpd24/extra/httpd-vhosts.conf
配置虚拟主机
[root@localhost ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs"
ProxyPass / http://192.168.96.134:8080/
ProxyPassReverse / http://192.168.96.134:8080/
<Directory "/usr/local/apache/htdocs">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
重启apache
[root@localhost ~]# /usr/local/apache/bin/apachectl restart
[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 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
以上是关于lamt部署的主要内容,如果未能解决你的问题,请参考以下文章
lamt(Linux apache mysql tomcat)