centos7安裝jdk+tomcat+nginx+mysql
公司新專案要在linux下部署,搭建一下java執行環境,記錄一下。
一、安裝mysql
1去官網下載mysql,下載後並解壓,我把mysql安裝在/usr/local/mysql路徑下
tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql
2進入mysql目錄,建立data資料夾
[[email protected] local]# cd /usr/local/mysql [[email protected] mysql]# mkdir data
3新建不能登陸的mysql使用者
useradd -r -M -s /sbin/nologin mysql
4修改mysql目錄所有者為mysql使用者和mysql組
chown -R mysql.mysql /usr/local/mysql chgrp -R mysql /usr/local/mysql
5進入/usr/local/mysql目錄,初始化mysql,後面那個是初始密碼,要記住
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
6複製my.cnf檔案,並修改/etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# These are commonly set, remove the # and set as required. basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 character-set-server=utf8 collation-server=utf8_general_ci default-storage-engine=INNODB #server_id= ..... # socket = .....
7進行mysql.support-files目錄,複製mysql.server到/etc/init.d/mysqld,加入開機執行
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld
[[email protected] support-files]# chmod +x /etc/init.d/mysqld
[[email protected] support-files]# chkconfig --add mysqld
檢視是否成功
chkconfig --list mysqld
8mysql加入環境變數
vi /etc/profile #把mysql服務加入系統環境變數:在最後新增下面這一行 export PATH=$PATH:/usr/local/mysql/bin :wq! #儲存退出 source /etc/profile #使配置立刻生效
9登入後修改密碼
[[email protected] tmp]# service mysqld start Starting MySQL. SUCCESS! [[email protected] tmp]# mysql -uroot -p Enter password: mysql> SET PASSWORD = PASSWORD('123456'); mysql> flush privileges;
二jdk安裝
1下載jdk,解壓並移動到安裝路徑
tar -zxvfjdk-8u73-linux-x64.tar.gz -C /usr/local/jdk8
2加入環境變數
vi /etc/profile # 在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL下新增 export JAVA_HOME=/usr/local/jdk8 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#儲存後,執行source /etc/profile使其生效
3驗證是否成功java -vsersion
三安裝tomcat
1解壓並安裝到指定路徑
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# 建立使用者
groupadd tomcat
useradd
-s
/bin/bash
-g tomcat tomcat
# 下載:
wget http:
//apache
.opencas.org
/tomcat/tomcat-7/v7
.0.68
/bin/apache-tomcat-7
.0.68.
tar
.gz
# 解壓:
tar
-zxvf apache-tomcat-7.0.68.
tar
.gz
# 複製:
cp
-R .
/apache-tomcat-7
.0.68
/usr/local
cd
/usr/local/apache-tomcat-7
.0.68
# 修改許可權:
chown
-R tomcat:tomcat apache-tomcat-7.0.68
# 啟動:
sh .
/bin/startup
.sh
|
2將8080埠新增到防火牆例外並重啟
?1 2 |
firewall-cmd --zone=public --add-port=8080
/tcp
--permanent
firewall-cmd --reload
|
3訪問http://ip/8080
四安裝nginx
安裝nginx前,前提是安裝了gcc-c++,還要安裝一些依賴庫
1安裝perl
mkdir /usr/local/perl cd perl5.22 ./Configure -des -Dprefix=/usr/local/ perl -Dusethreads -Uversiononly make make test make install
2安裝pcre
mkdir /usr/local/pcre tar zxvf pcre-8.35.tar.gz cd pcre-8.35 ./configure --prefix=/usr/local/pcre make make install
3安裝openssl
mkdir /usr/local/openssl tar zxvf openssl-1.0.1h.tar.gz cd openssl-1.0.1h ./config --prefix=/usr/local/openssl make make install vi /etc/profile export PATH=$PATH:/usr/local/openssl/bin :wq! source /etc/profile
4安裝zlib
mkdir /usr/local/zlib tar zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure --prefix=/usr/local/lib/zlib make make install
5安裝nginx
#新增使用者和使用者級 groupadd nginx useradd -g nginx nginx -s /bin/false mkdir /usr/local/nginx tar zxvf nginx-1.6.0.tar.gz cd nginx-1.6.0 ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/root/tool/openssl-1.0.2g/ --with-zlib=/root/tool/zlib-1.2.8/ --with-pcre=/root/tool/pcre-8.37 #注意:--with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35指向的是原始碼包解壓的路徑,而不是安裝的路徑,否則會報錯 make make install
6
#新增80埠到防火牆 firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload #啟動nginx /usr/local/nginx/sbin/nginx
nginx -s reload :修改配置後重新載入生效
nginx -s reopen :重新開啟日誌檔案
nginx -t -c /path/to/nginx.conf 測試nginx配置檔案是否正確
關閉nginx:
nginx -s stop :快速停止nginx
quit :完整有序的停止nginx
其他的停止nginx 方式:
ps -ef | grep nginx
kill -QUIT 主程序號 :從容停止Nginx
kill -TERM 主程序號 :快速停止Nginx
pkill -9 nginx :強制停止Nginx
啟動nginx:
nginx -c /path/to/nginx.conf
平滑重啟nginx:
kill -HUP 主程序號
7設定nginx開機啟動
vi /etc/init.d/nginxd #編輯啟動檔案新增下面內容 #!/bin/bash # #chkconfig: - 85 15 #description: Nginx is a World Wide Web server. #processname: nginx nginx=/usr/local/nginx/sbin/nginx conf=/usr/local/nginx/conf/nginx.conf case $1 in start) echo -n "Starting Nginx" $nginx -c $conf echo " done" ;; stop) echo -n "Stopping Nginx" killall -9 nginx echo " done" ;; test) $nginx -t -c $conf ;; reload) echo -n "Reloading Nginx" ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP echo " done" ;; restart) $0 stop $0 start ;; show) ps -aux|grep nginx ;; *) echo -n "Usage: $0 {start|restart|reload|stop|test|show}" ;; esac :wq! #儲存退出 注意(centos7沒有killall命令,要先安裝,yum install psmisc) chmod +x /etc/init.d/nginxd #賦予檔案執行許可權 chkconfig --add nginxd#新增到服務 chkconfig nginxd on #設定開機啟動 /etc/init.d/nginxd restart #重啟
8nginx和tomcat整合,修改nginx配置檔案
server { listen 80; server_name localhost; index index.html index.htm index.jsp;#設定訪問的預設首頁地址 root /home/www/web/ROOT;#設定網站的資源存放路徑 #limit_conn crawler 20; location / { index index.html index.jsp; } location ~ .*.jsp$ #所有jsp的頁面均交由tomcat處理 { index index.jsp; proxy_pass http://192.168.222.128:8080;#轉向tomcat處理 } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #設定訪問靜態檔案直接讀取不經過tomcat { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } #定義訪問日誌的寫入格式 #log_format access '$remote_addr - $remote_user [$time_local] "$request" ' #'$status $body_bytes_sent "$http_referer" ' #'"$http_user_agent" $http_x_forwarded_for'; #access_log /usr/local/nginx/logs/localhost.log access;#設定訪問日誌的存放路徑 }
公司新專案要在linux下部署,搭建一下java執行環境,記錄一下。
一、安裝mysql
1去官網下載mysql,下載後並解壓,我把mysql安裝在/usr/local/mysql路徑下
tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql
2進入mysql目錄,建立data資料夾
[[email protected] local]# cd /usr/local/mysql [[email protected] mysql]# mkdir data
3新建不能登陸的mysql使用者
useradd -r -M -s /sbin/nologin mysql
4修改mysql目錄所有者為mysql使用者和mysql組
chown -R mysql.mysql /usr/local/mysql chgrp -R mysql /usr/local/mysql
5進入/usr/local/mysql目錄,初始化mysql,後面那個是初始密碼,要記住
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
6複製my.cnf檔案,並修改/etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# These are commonly set, remove the # and set as required. basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 character-set-server=utf8 collation-server=utf8_general_ci default-storage-engine=INNODB #server_id = ..... # socket = .....
7進行mysql.support-files目錄,複製mysql.server到/etc/init.d/mysqld,加入開機執行
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld
[[email protected] support-files]# chmod +x /etc/init.d/mysqld
[[email protected] support-files]# chkconfig --add mysqld
檢視是否成功
chkconfig --list mysqld
8mysql加入環境變數
vi /etc/profile #把mysql服務加入系統環境變數:在最後新增下面這一行 export PATH=$PATH:/usr/local/mysql/bin :wq! #儲存退出 source /etc/profile #使配置立刻生效
9登入後修改密碼
[[email protected] tmp]# service mysqld start Starting MySQL. SUCCESS! [[email protected] tmp]# mysql -uroot -p Enter password: mysql> SET PASSWORD = PASSWORD('123456'); mysql> flush privileges;
二jdk安裝
1下載jdk,解壓並移動到安裝路徑
tar -zxvfjdk-8u73-linux-x64.tar.gz -C /usr/local/jdk8
2加入環境變數
vi /etc/profile # 在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL下新增 export JAVA_HOME=/usr/local/jdk8 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#儲存後,執行source /etc/profile使其生效
3驗證是否成功java -vsersion
三安裝tomcat
1解壓並安裝到指定路徑
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# 建立使用者
groupadd tomcat
useradd
-s
/bin/bash
-g tomcat tomcat
# 下載:
wget http:
//apache
.opencas.org
/tomcat/tomcat-7/v7
.0.68
/bin/apache-tomcat-7
.0.68.
tar
.gz
# 解壓:
tar
-zxvf apache-tomcat-7.0.68.
tar
.gz
# 複製:
cp
-R .
/apache-tomcat-7
.0.68
/usr/local
cd
/usr/local/apache-tomcat-7
.0.68
# 修改許可權:
chown
-R tomcat:tomcat apache-tomcat-7.0.68
# 啟動:
sh .
/bin/startup
.sh
|
2將8080埠新增到防火牆例外並重啟
?1 2 |
firewall-cmd --zone=public --add-port=8080
/tcp
--permanent
firewall-cmd --reload
|
3訪問http://ip/8080
四安裝nginx
安裝nginx前,前提是安裝了gcc-c++,還要安裝一些依賴庫
1安裝perl
mkdir /usr/local/perl cd perl5.22 ./Configure -des -Dprefix=/usr/local/ perl -Dusethreads -Uversiononly make make test make install
2安裝pcre
mkdir /usr/local/pcre tar zxvf pcre-8.35.tar.gz cd pcre-8.35 ./configure --prefix=/usr/local/pcre make make install
3安裝openssl
mkdir /usr/local/openssl tar zxvf openssl-1.0.1h.tar.gz cd openssl-1.0.1h ./config --prefix=/usr/local/openssl make make install vi /etc/profile export PATH=$PATH:/usr/local/openssl/bin :wq! source /etc/profile
4安裝zlib
mkdir /usr/local/zlib tar zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure --prefix=/usr/local/lib/zlib make make install
5安裝nginx
#新增使用者和使用者級 groupadd nginx useradd -g nginx nginx -s /bin/false mkdir /usr/local/nginx tar zxvf nginx-1.6.0.tar.gz cd nginx-1.6.0 ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/root/tool/openssl-1.0.2g/ --with-zlib=/root/tool/zlib-1.2.8/ --with-pcre=/root/tool/pcre-8.37 #注意:--with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35指向的是原始碼包解壓的路徑,而不是安裝的路徑,否則會報錯 make make install
6
#新增80埠到防火牆 firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload #啟動nginx /usr/local/nginx/sbin/nginx
nginx -s reload :修改配置後重新載入生效
nginx -s reopen :重新開啟日誌檔案
nginx -t -c /path/to/nginx.conf 測試nginx配置檔案是否正確
關閉nginx:
nginx -s stop :快速停止nginx
quit :完整有序的停止nginx
其他的停止nginx 方式:
ps -ef | grep nginx
kill -QUIT 主程序號 :從容停止Nginx
kill -TERM 主程序號 :快速停止Nginx
pkill -9 nginx :強制停止Nginx
啟動nginx:
nginx -c /path/to/nginx.conf
平滑重啟nginx:
kill -HUP 主程序號
7設定nginx開機啟動
vi /etc/init.d/nginxd #編輯啟動檔案新增下面內容 #!/bin/bash # #chkconfig: - 85 15 #description: Nginx is a World Wide Web server. #processname: nginx nginx=/usr/local/nginx/sbin/nginx conf=/usr/local/nginx/conf/nginx.conf case $1 in start) echo -n "Starting Nginx" $nginx -c $conf echo " done" ;; stop) echo -n "Stopping Nginx" killall -9 nginx echo " done" ;; test) $nginx -t -c $conf ;; reload) echo -n "Reloading Nginx" ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP echo " done" ;; restart) $0 stop $0 start ;; show) ps -aux|grep nginx ;; *) echo -n "Usage: $0 {start|restart|reload|stop|test|show}" ;; esac :wq! #儲存退出 注意(centos7沒有killall命令,要先安裝,yum install psmisc) chmod +x /etc/init.d/nginxd #賦予檔案執行許可權 chkconfig --add nginxd#新增到服務 chkconfig nginxd on #設定開機啟動 /etc/init.d/nginxd restart #重啟
8nginx和tomcat整合,修改nginx配置檔案
server { listen 80; server_name localhost; index index.html index.htm index.jsp;#設定訪問的預設首頁地址 root /home/www/web/ROOT;#設定網站的資源存放路徑 #limit_conn crawler 20; location / { index index.html index.jsp; } location ~ .*.jsp$ #所有jsp的頁面均交由tomcat處理 { index index.jsp; proxy_pass http://192.168.222.128:8080;#轉向tomcat處理 } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #設定訪問靜態檔案直接讀取不經過tomcat { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } #定義訪問日誌的寫入格式 #log_format access '$remote_addr - $remote_user [$time_local] "$request" ' #'$status $body_bytes_sent "$http_referer" ' #'"$http_user_agent" $http_x_forwarded_for'; #access_log /usr/local/nginx/logs/localhost.log access;#設定訪問日誌的存放路徑 }