linux项目之lamt环境搭建

lamt环境搭建

环境说明:

系统IP需要安装的服务
CentOS7192.168.159.144httpd、mysql、tomcat

安装apache

//创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache 
[root@localhost ~]# id apache
uid=996(apache) gid=994(apache) groups=994(apache)

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

//下载和安装apr以及apr-util
[root@localhost ~]# wget http://mirrors.gigenet.com/apache//apr/apr-1.6.5.tar.gz http://mirrors.gigenet.com/apache//apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# tar xf apr-1.6.5.tar.gz 
[root@localhost ~]# tar xf apr-util-1.6.1.tar.gz
[root@localhost ~]# cd apr-1.6.5
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make && make install
......

[root@localhost apr-1.6.5]# 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
[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
[root@localhost ~]# tar xf httpd-2.4.43.tar.gz
[root@localhost ~]# 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/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man_db.conf

取消ServerName前面的注释
[root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf 
//启动apache
[root@localhost httpd-2.4.43]# apachectl start
[root@localhost ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port                           
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                               
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  

安装mysql

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


//创建用户和组
[root@localhost src]# useradd -r -M -s /sbin/nologin  mysql
[root@localhost ~]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)

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

//修改目录/usr/local/mysql的属主属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql -d
drwxr-xr-x 9 mysql mysql 129 Aug  1 00:11 /usr/local/mysql

//添加环境变量
[root@localhost ~]# ls /usr/local/mysql
bin  COPYING  docs  include  lib  man  README  share  support-files
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

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


//初始化数据库
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/
2020-08-01T04:15:55.095736Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-08-01T04:15:55.294922Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-08-01T04:15:55.321013Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-08-01T04:15:55.392545Z 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: b1cb74fe-d3ad-11ea-9e43-000c29f66cbc.
2020-08-01T04:15:55.402345Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-08-01T04:15:55.773892Z 0 [Warning] CA certificate ca.pem is self signed.
2020-08-01T04:15:55.992681Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

//配置mysql
[root@localhost ~]#  ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig 

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



//启动mysql
[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS! 
[root@localhost ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      50              *:3306                        *:*                  
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                              
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  

//修改密码
[root@localhost ~]#  mysql
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('longnian123.');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

安装tomcat

#安装JDK
[root@localhost ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

#安装tomcat
[root@localhost ~]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz
[root@localhost ~]# tar xf apache-tomcat-9.0.37.tar.gz 
[root@localhost ~]# mv apache-tomcat-9.0.37 /usr/local/tomcat

#启动tomcat
[root@localhost ~]# /usr/local/tomcat/bin/startup.sh 
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@localhost ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      50              *:3306                        *:*                  
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      100            :::8080                       :::*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
LISTEN      0      1        ::ffff:127.0.0.1:8005                       :::* 

修改配置文件

//启用httpd的相关模块,去掉以下两行注释
[root@localhost ~]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so


//配置虚拟主机
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#在最后添加
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ProxyPass / http://192.168.159.144:8080/
    ProxyPassReverse / http://192.158.159.144:8080/
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

#重启apache
[root@localhost ~]# apachectl restart
[root@localhost ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      50              *:3306                        *:*                  
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      100            :::8080                       :::*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
LISTEN      0      1        ::ffff:127.0.0.1:8005                       :::* 

浏览器访问验证

安装完apache后,访问的页面
在这里插入图片描述
安装完tomcat后,访问的页面
在这里插入图片描述
访问80端口时,跳转到了8080端口

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值