环境说明:
IP | 安装的服务 |
---|---|
192.168.209.12 | tomcat |
192.168.209.13 | nginx mysql |
********************************nginx安装**************************
1.//创建系统用户nginx
[[email protected] ~]# useradd -r -M -s /sbin/nologin nginx
//安装依赖环境
[[email protected] ~]# yum -y install pcre-devel openssl openssl-devel gd-devel
[[email protected] ~]# yum -y groups mark install ‘Development Tools‘
//创建日志存放目录
[[email protected] ~]# mkdir -p /var/log/nginx
[[email protected] ~]# chown -R nginx.nginx /var/log/nginx
//下载nginx
[[email protected] ~]# cd /usr/src/ [[email protected] src]# wgethttp://nginx.org/download/nginx-1.14.0.tar.gz
//编译安装
[[email protected] src]# tar xf nginx-1.14.0.tar.gz
[[email protected] src]# cd nginx-1.14.0
[[email protected] nginx-1.14.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
[[email protected] nginx-1.14.0]# make -j $(grep ‘processor‘ /proc/cpuinfo | wc -l) && make install
2.nginx安装后配置
//配置环境变量
[[email protected] ~]# echo ‘export PATH=/usr/local/nginx/sbin:$PATH‘ > /etc/profile.d/nginx.sh
[[email protected] ~]# source /etc/profile.d/nginx.sh
[[email protected] ~]# nginx
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 64 *:40154 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 64 :::2049 :::*
LISTEN 0 64 :::34409 :::*
********************************mysql安装****************************
//安装依赖 包
[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建用户和组
[[email protected] ~]# cd /usr/src/
[[email protected] src]# groupadd -r -g 306 mysql
[[email protected] src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
//下载二进制格式的mysql软件包
[[email protected] src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
//解压软件至/usr/local
[[email protected] src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[[email protected] src]# cd /usr/local/
//创建软连接
[[email protected] local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
//修改目录/usr/local/mysql的属主属组
[[email protected] local]# chown -R mysql.mysql /usr/local/mysql
[[email protected] local]# ll /usr/local/mysql
//添加环境变量
[[email protected] ~]# ls /usr/local/mysql
[[email protected] ~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[[email protected] ~]# source /etc/profile.d/mysql.sh
[[email protected] ~]# echo $PATH
//建立数据存放目录
[[email protected] ~]# mkdir /opt/data
[[email protected] ~]# chown -R mysql.mysql /opt/data/
[[email protected] ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 8月 19 13:20 data
//初始化数据库 注意这个命令后会生成临时密码 要记住 jd?ajfrKY4pQ
[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
//配置mysql
//软连接
[[email protected] ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
[[email protected] ~]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
[[email protected] ~]# ldconfig -v
//生成配置文件
[[email protected] ~]# 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
//配置服务启动脚本
[[email protected] ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld
//启动mysql
[[email protected] ~]# service mysqld start
[[email protected] ~]# ps -ef |grep mysql
[[email protected] ~]# ss -antl
LISTEN 0 80 :::3306 :::*
//修改密码 使用临时密码登入
[[email protected] ~]# mysql -uroot -p
说明:jd?ajfrKY4pQ 这是以上步骤的临时密码
mysql> set password = password(‘lanzhiyong‘);
******************************tomcat项目部署************************
//java环境安装,安装jdk环境
[[email protected] ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
[[email protected] ~]# java -version
//下载tomcat
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget https://archive.apache.org/dist/tomcat/tomcat-9/ v9.0.8/bin/apache-tomcat-9.0.8.tar.gz
//解压部署
[[email protected] src]# tar xf apache-tomcat-9.0.8.tar.gz -C /usr/local/
[[email protected] local]# tar xf apache-tomcat-9.0.8.tar.gz
[[email protected] local]# mv apache-tomcat-9.0.8 apache2
[[email protected] local]# mv apache2 /usr/local/
[[email protected] src]# cd /usr/local/
[[email protected] local]# ln -s apache2/ tomcat2
[[email protected] local]# ln -s apache-tomcat-9.0.8/ tomcat
[[email protected] local]# ll
//分别给tomcat,tomcat2写一个java页面
[[email protected] ~]# vim index.jsp
[[email protected] ~]# cat index.jsp
<html>
<head>
<title>test papg</title>
</head>
<body>
<%
out.println("Hellow World");
%>
</body>
</html>
[[email protected] ~]# mv index.jsp index
[[email protected] ~]# vim index.jsp
[[email protected] ~]# cat index.jsp
<html>
<head>
<title>test papg</title>
</head>
<body>
<%
out.println("I Love china");
%>
</body>
</html>
[[email protected] ~]# mkdir /usr/local/tomcat/webapps/test
[[email protected] ~]# mkdir /usr/local/tomcat2/webapps/test
[[email protected] ~]# cp /index/index.jsp /usr/local/tomcat/webapps/test/
[[email protected] ~]# cp index.jsp /usr/local/tomcat2/webapps/test/
[[email protected] ~]# ll /usr/local/tomcat/webapps/test/
总用量 4
-rw-r--r--. 1 root root 114 9月 5 11:27 index.jsp
[[email protected] ~]# ll /usr/local/tomcat2/webapps/test/
总用量 4
-rw-r--r--. 1 root root 114 9月 5 11:27 index.jsp
[[email protected] ~]# vim /usr/local/tomcat2/conf/server.xml
把所有的port=*端口号改下不同即可(例如port=8080->port=8081)
//启动tomcat
[[email protected] ~]# /usr/local/tomcat/bin/catalina.shstart
[[email protected] ~]# /usr/local/tomcat2/bin/catalina.shstart
[[email protected] ~]# ps -ef |grep tomcat
[[email protected] ~]# ss -antl
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 100 :::8080 :::*
LISTEN 0 100 :::8081 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8006 :::*
LISTEN 0 100 :::8009 :::*
LISTEN 0 100 :::8010 :::*
***************************nginx配置********************************
[[email protected] conf]# vim /usr/local/nginx/conf/nginx.conf
//添加以下模块
upstream web {
server 192.168.209.12:8080;
server 192.168.209.12:8081;
}
server{
location / {
proxy_pass http://web;
}
}
[[email protected] conf]# nginx -s reload
最后验证输入:192.168.209.13/test/ 刷新看效果
原文地址:http://blog.51cto.com/13833047/2170777
时间: 2024-10-04 00:08:09