lamt环境搭建

环境

系统IP需要服务
CentOS7192.168.32.132http
mysql
tomcat

环境部署

httpd
#YUM源配置
[root@asuna ~]# rpm -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm

[root@asuna ~]# cd /etc/yum.repos.d/
[root@asuna yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@asuna yum.repos.d]# cd
[root@asuna ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@asuna ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo

[root@asuna ~]# yum -y install epel-release vim bzip2

#安装开发工具包
[root@asuna ~]# yum groups mark install 'Development Tools'

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

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


#下载和安装apr以及apr-util
[root@asuna ~]# cd /usr/src/
[root@asuna src]# wget https://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.bz2

[root@asuna src]# wget https://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.bz2

[root@asuna src]# ls
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  debug  kernels

[root@asuna src]# tar xf apr-1.7.0.tar.bz2 
[root@asuna src]# tar xf apr-util-1.6.1.tar.bz2 
[root@asuna src]# ls
apr-1.7.0          apr-util-1.6.1          debug
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  kernels

[root@asuna src]# cd apr-1.7.0
[root@asuna apr-1.7.0]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    #$RM "$cfgfile"		//将此行加上注释,或者删除此行
    
#编译并安装
[root@asuna apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@asuna apr-1.7.0]# make && make install

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

#编译安装httpd
[root@asuna ~]# cd /usr/src/
[root@asuna src]# wget https://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.bz2

[root@asuna src]# ls
apr-1.7.0          apr-util-1.6.1          debug                 kernels
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.43.tar.bz2
[root@asuna src]# tar xf httpd-2.4.43.tar.bz2 
[root@asuna src]# cd httpd-2.4.43
[root@asuna 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@asuna httpd-2.4.43]# make && make install

#安装后配置
[root@asuna ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@asuna ~]# source /etc/profile.d/httpd.sh
[root@asuna ~]# ln -s /usr/local/apache/include /usr/include/apache
[root@asuna ~]# echo 'MANDATORY_MANPATH /usr/local/apache/man' >> /etc/man_db.conf

#取消ServerName前面的注释
[root@asuna httpd24]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf

#启动apache
[root@asuna ~]# apachectl start
[root@asuna ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128      *:22                   *:*                  
LISTEN      0      128     :::80                  :::*                  
LISTEN      0      128     :::22                  :::*                  

#关闭防火墙
[root@asuna ~]# systemctl stop firewalld
mysql
#安装依赖包
[root@asuna ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

#创建用户和组
[root@asuna ~]# useradd -r -M -s /sbin/nologin -u 306 mysql

#下载二进制格式的mysql软件包
[root@asuna ~]# cd /usr/src/
[root@asuna src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

#解压软件至/usr/local/
[root@asuna src]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@asuna src]# ls /usr/local/
apache    bin    include  libexec                              share
apr       etc    lib      mysql-5.7.30-linux-glibc2.12-x86_64  src
apr-util  games  lib64    sbin

#创建软连接
[root@asuna local]# ln -sv mysql-5.7.30-linux-glibc2.12-x86_64/ mysql
[root@asuna local]# ll
...
lrwxrwxrwx.  1 root root  36 Jul  8 22:17 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/
...

#修改目录/usr/local/mysql的属主属组
[root@asuna ~]# chown -R mysql.mysql /usr/local/mysql*
[root@asuna ~]# ll /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 36 Jul  8 22:17 /usr/local/mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/

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

#建立数据存放目录
[root@asuna ~]# mkdir /opt/data
[root@asuna ~]# chown -R mysql.mysql /opt/data/
[root@asuna ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul  8 22:49 data

#初始化数据库
[root@asuna ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/

#配置mysql
[root@asuna mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@asuna ~]# echo 'MANDATORY_MANPATH /usr/local/mysql/man' >> /etc/man_db.conf
[root@asuna ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@asuna ~]# ldconfig

#生成配置文件
[root@asuna ~]# 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@asuna ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@asuna ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@asuna ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

#启动mysql
[root@asuna ~]# service mysqld start
[root@asuna ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128      *:22                   *:*                  
LISTEN      0      80      :::3306                :::*                  
LISTEN      0      128     :::80                  :::*                  
LISTEN      0      128     :::22                  :::*                  

#设置新密码
[root@asuna ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit
Bye
tomcat
# java环境安装
[root@asuna ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

#查看安装的版本
[root@asuna ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)


#下载tomcat
[root@asuna ~]# cd /usr/src/
[root@asuna src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz

#解压部署
[root@asuna src]# ls
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            kernels
apr-util-1.6.1               mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
apr-util-1.6.1.tar.bz2       php-7.2.8
debug                        php-7.2.8.tar.xz
[root@asuna src]# tar xf apache-tomcat-9.0.37.tar.gz -C /usr/local/
[root@asuna src]# cd /usr/local/
[root@asuna local]# ln -s apache-tomcat-9.0.37/ tomcat
[root@asuna local]# ll
total 0
drwxr-xr-x. 13 root  root  152 Jul 24 22:36 apache
drwxr-xr-x.  9 root  root  220 Aug  3 20:15 apache-tomcat-9.0.37
drwxr-xr-x.  6 root  root   58 Jul 24 22:24 apr
drwxr-xr-x.  5 root  root   43 Jul 24 22:29 apr-util
drwxr-xr-x.  2 root  root   62 Jul 27 05:29 bin
drwxr-xr-x.  4 root  root  223 Jul 27 05:49 etc
drwxr-xr-x.  2 root  root    6 Apr 11  2018 games
drwxr-xr-x.  2 root  root   19 Jul 25 01:33 include
drwxr-xr-x.  3 root  root   21 Jul 25 08:51 lib
drwxr-xr-x.  2 root  root    6 Apr 11  2018 lib64
drwxr-xr-x.  2 root  root    6 Apr 11  2018 libexec
lrwxrwxrwx.  1 mysql mysql  36 Jul 24 23:59 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 mysql mysql 172 Jul 27 02:02 mysql-5.7.30-linux-glibc2.12-x86_64
drwxr-xr-x.  9 root  root   88 Jul 25 03:44 php7
drwxr-xr-x.  2 root  root   48 Jul 27 05:29 sbin
drwxr-xr-x.  6 root  root   63 Jul 25 08:52 share
drwxr-xr-x.  2 root  root    6 Apr 11  2018 src
lrwxrwxrwx.  1 root  root   21 Aug  3 20:16 tomcat -> apache-tomcat-9.0.37/


# 写一个hello world的java页面
[root@asuna ~]# vim index.jsp
[root@asuna ~]# cat index.jsp
<html>
<head>
	<title>test page</title>
</head>
<body>
	<%
	    out.println("hello world");
	%>
	%</body>
	%</html>

[root@asuna ~]# mkdir /usr/local/tomcat/webapps/test
[root@asuna ~]# cp index.jsp /usr/local/tomcat/webapps/test/
[root@asuna ~]# ll /usr/local/tomcat/webapps/test/
total 4
-rw-r--r--. 1 root root 116 Aug  3 20:18 index.jsp

# 启动tomcat
[root@asuna ~]# /usr/local/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.
[root@asuna ~]# ps -ef|grep tomcat

[root@asuna ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128            *:10050                      *:*                  
LISTEN     0      128            *:10051                      *:*                  
LISTEN     0      128            *:22                         *:*                  
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                        :::*   

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值