歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 在linux上搭建javaweb服務器

在linux上搭建javaweb服務器

日期:2017/8/19 9:49:19   编辑:關於Linux

首先,要重裝系統,可憐的我一開始一無所知,在系統為windows server 2008的情況下,我把系統重裝成了win7,對於一個從沒重裝系統的人來說,簡直了,花了一天吧,終於裝上了win7,當看見win7開機界面的時候,我的內心是激動地,可惜還沒激動多久,就發現沒法上網,捯饬了好久,哈,終於也可以上網了,結果卻被告知要裝成linux系統,而且還是suse 的,又從網上各種查資料怎麼裝,這次用了半天就裝好了,結果開機後還是發現不能上網,崩潰--,還好遇見個大神,幫我各種捯饬網絡,最後終於網絡環境好了,可以上網了,可以開始搭建服務器之路了。。。。

以下是個人的裝mysql歷程 呵呵

1.首先下載mysql,

反正我是裝5.7裝不成功,只能選擇5.6的版本了

2.檢查是否已安裝,grep的-i選項表示匹配時忽略大小寫
rpm -qa|grep -i mysql
如果已經安裝了庫文件,應該先卸載。。。。

3.添加mysql用戶組和mysql用戶,命令如下:

groupadd mysql
useradd -r -g mysql mysql

4.將Mysql安裝包解壓到其所在目錄,命令如下:

tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

然後復制解壓得到的目錄到系統的本地軟件目錄“/usr/local/”,命令如下:

cp -rf mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql

5.進入安裝Mysql軟件的目錄,並修改當前目錄擁有者為剛才新建的mysql用戶 ,即更改所屬的組和用戶。

cd /usr/local/mysql

chown -R mysql:mysql ./

chgrp -R mysql:mysql ./

6.復制默認全局啟動參數配置文件到/etc目錄,命令如下:

cp ./support-files/my-default.cnf /etc/my.cnf

7. 執行安裝包中自帶腳本,安裝數據庫

./scripts/mysql_install_db --user=mysql

8.修改當前目錄擁有者為root用戶,即將mysql/目錄下除了data/目錄的所有文件,改回root用戶所有,mysql用戶只需作為mysql/data/目錄下所有文件的所有者。

chown -R root:root ./

chown -R mysql:mysql data

9.將mysqld服務加入開機自啟動項。

首先需要將scripts/mysql.server服務腳本復制到/etc/init.d/,並重命名為mysqld。

cp support-files/mysql.server /etc/init.d/mysqld

通過chkconfig命令將mysqld服務加入到自啟動服務項中。

chkconfig --add mysqld

查看是否添加成功
chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

10. 重啟系統,mysqld就會自動啟動了。

檢查是否啟動

netstat -anp|grep mysqld

tcp 0 00.0.0.0:3306 0.0.0.0:* LISTEN 2365/mysqld
unix 2 [ ACC ] STREAM LISTENING 14396 2365/mysqld /tmp/mysql.sock

如果不想重新啟動,那可以直接手動啟動。

service mysqld start

Starting MySQL..SUCCESS!

查看Mysql進程是否已啟動,ps -ef|grep mysqld

顯示如下圖所示結果,說明Mysql數據庫啟動成功:

root 1708 1 0 08:21 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/linux-c8tk.pid
mysql 1850 1708 0 08:21 ? 00:00:17 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/linux-c8tk.err --pid-file=/usr/local/mysql/data/linux-c8tk.pid
adminer 6231 6207 0 16:05 pts/0 00:00:00 grep --color=auto mysql

11.修改Mysql數據庫的root用戶的密碼,root的初始密碼默認為空的,在mysql系統外,使用mysqladmin

./bin/mysqladmin -u root password '(此處填寫密碼)root'

12.把mysql客戶端放到默認路徑,運行
#ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

13.進入mysql

mysql -uroot -proot

顯示結果如下:

Welcome to theMySQLmonitor. Commands end with ; or \g.
Your MySQLconnection idis 3
Serverversion:5.5.29-log MySQL Community Server (GPL)
Copyright (c)2000, 2012,Oracle and/or its affiliates. All rights reserved.
Oracle is aregisteredtrademark of Oracle Corporation and/or its
affiliates.Other namesmay be trademarks of their respective
owners.
Type 'help;' or'\h' forhelp. Type '\c' to clear the current input statement.
mysql>

flush privileges; //刷新MySQL的系統權限相關表-

flush hosts; //清空主機緩存表

14.打開MySQL數據庫遠程訪問的權限

鏈接mysql,運行
mysql -uroot -proot
切換數據庫
use mysql
查詢mysql用戶信息
SELECT User, Password ,Host From user;

開啟任何主機都能鏈接mysql服務器,遠程訪問授權:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'Administrator'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

修改生效
flush privileges;

15.導入數據庫

導入數據庫
1、首先建空數據庫
mysql>create database abc;

2、導入數據庫 //已操作
方法一:
(1)選擇數據庫
mysql>use abc;
(2)設置數據庫編碼
mysql>set names utf8;
(3)導入數據(注意sql文件的路徑)
mysql>source /home/abc/abc.sql;
方法二:
mysql -u用戶名 -p密碼 數據庫名 < 數據庫名.sql
#mysql -uabc_f -p abc < abc.sql
建議使用第二種方法導入。

Copyright © Linux教程網 All Rights Reserved