centos7上安装 apache-tomcat-mysql
------------------------------------------------------------
甲. 安装apache
------------------------------------------------------------
# yum install httpd
支持https
# yum install mod_ssl
查看状态,启动,停止,开机启动等
systemctl status httpd
systemctl start httpd
systemctl stop httpd
systemctl enable httpd
验证:
本地访问: firefox 地址栏中输入localhost, 应出现测试页面
远程访问:
如果出现"连接失败"
检查1: 可ping 通
检查2: 关闭防火墙
检查3: 关闭selinux
检查4: 是否安装了mod_ssl, 这样才能支持https: 协议
------------------------------------------------------------
当apache 根目录下没有index.html时, 测试页Testing 123..的位置在哪里?
------------------------------------------------------------
从/etc/httpd/conf.d/welcome.conf 中发现
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
原来它是如此映射的!!
------------------------------------------------------------
乙、安装tomcat
------------------------------------------------------------
安装jdk1.8 和tomcat 9
# yum install java-1.8.0-openjdk
tomcat 9以上版本需要手工安装
#wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.62/bin/apache-tomcat-9.0.62.tar.gz
解压源码包放在/usr/local目录下
# tar xvf apache-tomcat-9.0.62.tar.gz -C /usr/local/
创建链接文件
# ln -sv /usr/local/apache-tomcat-9.0.62 /usr/local/tomcat9
启动tomcat
/usr/local/tomcat9/bin/startup.sh
关闭tomcat
/usr/local/tomcat9/bin/shutdown.sh
把tomcat9按服务的形式来管理, 需要书写一个服务
vim /usr/lib/systemd/system/tomcat9.service
[Unit]
Description=Apache Tomcat 9
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/tomcat9/bin/catalina.sh start -DEFOREGRAND
ExecStop=/usr/local/tomcat9/bin/catalina.sh stop
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
可以用服务的形式开闭tomcat9
systemctl start tomcat9
systemctl stop tomcat9
设置开机自动启动
systemctl enable tomcat9
验证:
本机,localhost:8080
外网,IP:8080
------------------------------------------------------------
丙. centos 安装社区mysql8
------------------------------------------------------------
1. 首先获取rpm 包,安装更新repo 文件, 然后可以从yum 源中安装mysql
wget http://repo.mysql.com/mysql80-community-release-el7-6.noarch.rpm
rpm -ivh mysql80-community-release-el7-6.noarch.rpm
顺便看一下rpm 包的内容
# rpm -qpl mysql80-community-release-el7-6.noarch.rpm
警告:mysql80-community-release-el7-6.noarch.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
/etc/RPM-GPG-KEY-mysql
/etc/RPM-GPG-KEY-mysql-2022
/etc/yum.repos.d/mysql-community-debuginfo.repo
/etc/yum.repos.d/mysql-community-source.repo
/etc/yum.repos.d/mysql-community.repo
2. yum search mysql |grep community
yum install mysql-community-server-8.0.28-1.el7.x86_64
获取 GPG 密钥失败:[Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022"
解决办法:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
这句话的意思实际是把文件RPM-GPG-KEY-mysql-2022 下载到 /etc/目录下, 不过这样也可以通过了.
/etc/RPM-GPG-KEY-mysql-2022
然后再安装server可成功.
repo 安装的包含服务文件 (rpm -ql 查看)
/usr/lib/systemd/system/mysqld.service
3. 启动服务
这就很简单了
systemctl start mysqld
开机启动
systemctl enable mysqld
4. 第一次登录mysql 的 初始密码
获取 初始密码
grep 'password' /var/log/mysqld.log
你也可以
cat /var/log/mysqld.log
找到密码类似于: M.<HeauRT9ed
然后登录mysqld
mysql -uroot -p
------------------------------------------------------------
丁.应用:httpd 部署,转发给tomcat
------------------------------------------------------------
在/etc/httpd/conf.d/ 中添加一个配置文件,例如命名为multiview.conf
其中添加一个虚拟主机, 定义其DocumentRoot, 使指向自己的目录,转发规则. 可转发给tomcat9,
参考如下:
# cat multiview.conf
<VirtualHost *:80>
DocumentRoot "/data/web/www/public"
#ServerName mediaserver
#ServerAlias localhost
ErrorLog "|/usr/sbin/rotatelogs /data/log/web/http-error_%Y%m%d.log 86400"
CustomLog "|/usr/sbin/rotatelogs /data/log/web/http-access_%Y%m%d.log 86400" common
#DirectoryIndex index.php index.html
<Directory "/data/web/www/public">
CheckSpelling On
Options -Indexes +FollowSymLinks +ExecCGI
AllowOverride All
#Order allow,deny
#Allow from all
Require all granted
LimitRequestBody 1024000000
</Directory>
# 127.0.0.1是本机tomcat,如果不和apache httpd在一个服务器主机上,这里填对方ip,
# 8080是tomcat的服务端口,将对api的访问跳转到后端的8080服务端口上
ProxyPreserveHost On
ProxyRequests On
ProxyPass /api http://127.0.0.1:8080/api
ProxyPassReverse /api http://127.0.0.1:8080/api
ProxyPass /login http://127.0.0.1:8080/login
ProxyPassReverse /login http://127.0.0.1:8080/login
ProxyPass /logout http://127.0.0.1:8080/logout
ProxyPassReverse /logout http://127.0.0.1:8080/logout
# 前端映射路径 媒体目录为"/storage",如果修改媒体目录就把"/storage"改成修改的路径,需要改两处"/storage",一处alias /record "/storage",一处<Directory "/storage">
alias /record "/storage"
<Directory "/storage">
#CheckSpelling On
Options +Indexes +FollowSymLinks
AllowOverride All
#Order allow,deny
#Allow from all
Require all granted
</Directory>
</VirtualHost>
tomcat9 配置的更改。
仅需要修改/usr/local/tomcat9/conf/server.xml 文件
例如修改appBase, context path 等,使指向自己的应用.
修改:
appBase="/data/web/www/app/ts"
添加:
<Context path="/" docBase="/data/web/www/app/ts/ts-0.0.1-SNAPSHOT" debug="0" sessionCookieName="tsJSESSIONID" reloadable="true"></Context>