クラウドサーバー環境構築

目次

JDKをインストールする 

MySQLをインストールする 

Tomcatサーバーをインストールする

Nginxリバースプロキシサーバーをインストールする


まず、クラウド サーバーが必要です。購入するだけです。

Centosイメージで説明、メモ、すべてのリソース

JDKをインストールする 

ここに jdk11 をインストールします(リソース 1) 

usr/localディレクトリにjdkフォルダを作成します。

jdk-11.0.14_linux-x64_bin.tar.gzをjdkディレクトリに転送し、カレントディレクトリに解凍します。

tar -zxvf jdk-11.0.14_linux-x64_bin.tar.gz

環境変数を構成する

[root@VM-12-8-centos jdk]# vim /etc/profile

。。。。。

if [ -n "${BASH_VERSION-}" ] ; then
        if [ -f /etc/bashrc ] ; then
                # Bash login shells run only /etc/profile
                # Bash non-login shells run only /etc/bashrc
                # Check for double sourcing is done in /etc/bashrc.
                . /etc/bashrc
       fi
fi

//末尾添加
export JAVA_HOME=/usr/local/jdk/jdk-11.0.14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
"/etc/profile" 89L, 2211C    
:wq保存退出后,让其生效
[root@VM-12-8-centos jdk]#  source /etc/profile
    

MySQLをインストールする 

ここに mysql8.0.29 をインストールします(リソース 2)

usr/local ディレクトリに mysql フォルダーを作成します。

mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz を mysql フォルダーに転送し、現在のディレクトリに解凍します。

tar xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz

 

 ディレクトリ名の変更

mv mysql-8.0.29-linux-glibc2.12-x86_64 mysql8.0.29

 ディレクトリ内にデータフォルダーを作成します

cd mysql8.0.29/
mkdir data

mysqlユーザーを作成して認可する

groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/mysql8.0.29

bin ディレクトリに入り、mysql を初期化します。

cd bin/
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0.29 --datadir=/usr/local/mysql/mysql8.0.29/data/ --initialize

実行結果は次のようになります。パスワードが含まれているので、パスワードを保存します。

[root@VM-12-8-centos bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0.29 --datadir=/usr/local/mysql/mysql8.0.29/data/ --initialize
2022-05-18T03:17:38.004698Z 0 [System] [MY-013169] [Server] /usr/local/mysql/mysql8.0.29/bin/mysqld (mysqld 8.0.29) initializing of server in progress as process 22024
2022-05-18T03:17:38.021352Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-18T03:17:39.300600Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-18T03:17:41.163199Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: szhdqpAKo1--

次に設定ファイルを編集します

vi /etc/my.cnf

[mysqld]
  basedir=/usr/local/mysql/mysql8.0.29
  datadir=/usr/local/mysql/mysql8.0.29/data/
  socket=/tmp/mysql.sock
  character-set-server=UTF8MB4

保存して終了したら、前のレベルのインストール ディレクトリに戻り、mysql をサービスに追加します。

cd ..
cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
service mysql start
service mysql status
ln -sf /usr/local/mysql/mysql8.0.29/bin/mysql /usr/bin

mysqlにログインする

mysql -u root -p

若出现错误
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
输入
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

パスワードを入力します。パスワードは初期化時のパスワードです。

入力後、パスワードをリセットし、希望のパスワードを設定して有効にします

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; 
flush privileges;

リモート接続をセットアップする

use mysql;
update user set host='%' where user='root';
flush privileges;

ポート 3306 を開き、接続できるようにします。

firewall-cmd --add-port=3306/tcp --permanent

FirewalID が実行されていない場合は、ファイアウォールを開きます

systemctl start firewalld.service
systemctl enable firewalld.service

有効にするためにポートを開いてください

firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload

 次に、セキュリティ グループまたはファイアウォールでこのポートを開きます。

 データベースツールを使用し、DBeaverを使用して接続をテストし、合格後は正常に使用できるようになりました。(リソース 3)

Tomcatサーバーをインストールする

ここに tomcat9.0.63 をインストールします(リソース 4)

usr/local ディレクトリに Tomcat フォルダーを作成します。

apache-tomcat-9.0.63.tar.gz を tomcat フォルダーに転送し、現在のディレクトリに解凍します。

tar -zxvf apache-tomcat-9.0.63.tar.gz

ディレクトリ名の変更

mv apache-tomcat-9.0.63 tomcat9.0.63

環境変数を構成する

vi /etc/profile

在末尾加上
export CATALINA_HOME=/usr/local/tomcat/tomcat9.0.63
export CATALINA_BASE=/usr/local/tomcat/tomcat9.0.63
export PATH=$PATH:$CATALINA_BASE/bin
export PATH CATALINA_BASE

:wq保存推出

それを有効にしましょう

source /etc/profile

Tomcat 構成ファイルに移動し、Tomcat の起動ポートを変更します。

cd /usr/loacl/tomcat/tomcat9.0.63/conf/
vi server.xml

ポート番号を一時的に 80 に変更します。

 ファイアウォールがポート 80 を開く

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

bin ディレクトリに戻り、Tomcat を起動します。

./startup.sh

この時点で Web ページを開き、「ip」と入力して Tomcat のようこそインターフェイスを表示します。

成功したら、ポートを 8080 に戻すことが最善です。 

Nginxリバースプロキシサーバーをインストールする

ここに nginx1.21.6 をインストールします(リソース 5)

usr/localディレクトリにnginx1.21.6フォルダを作成します。

nginx-1.21.6.tar.gzをnginx1.21.6フォルダに転送し、カレントディレクトリに解凍します。

tar zxvf nginx-1.21.6.tar.gz

  

ディレクトリを入力し、コンパイルしてインストールします。

cd nginx-1.21.6/
./configure --prefix=/usr/local/nginx

実行後、不足している依存関係を確認できます

 よくあるインストールの欠落

yum install -y gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel

インストール完了後、再度コンパイルとインストールを実行してください。

次に実行

make
make install

「usr/local」と入力すると、nginx が正常にインストールされたことがわかります。

nginx用のサービススクリプトを作成する

vi /usr/lib/systemd/system/nginx.service

スクリプトの内容、ディレクトリに注意してください

[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

スクリプトを使用して nginx を起動し、起動前にポート 80 を占有しているすべてのプロセスを強制終了します。

lsof -i :80
kill -9 PID

systemctl start nginx

この時点で Web ページを開き、IP を入力して nginx のようこそインターフェイスを表示します。

変更を加えるたびに、nginx をリロードする必要があります

systemctl reload nginx

nginx を使用して Tomcat をプロキシします。Tomcat ポートは 8080 に変更されています。一般的な構成は次のとおりです。


worker_processes  1;


#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    #upstream httpds {
        
    #    server 192.168.83.102:80 weight=8 ;
    #    server 192.168.83.103:80 weight=2 ;
    #    server 192.168.83.104:80 weight=1 backup;

    #}

    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://localhost:8080;
        }

          location /public {
            root  html;
            index  index.html index.htm;
         }

          location /static {
             root  html;
             index  index.html index.htm;
           }

          location /logo.ico {
             root  html;
             index  index.html index.htm;
           }

          location /pdf {
             root  html;
             index  index.html index.htm;
           }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
}

設定後、nginxをリロードします

systemctl reload nginx

この時点でページを開くと、Tomcat のウェルカム ページになります。 

おすすめ

転載: blog.csdn.net/weixin_42078172/article/details/124837184