今天,又一次弄個人我的雲主機的環境。準備運營本身用Java寫的我的官網等站點。
服務器環境:阿里雲CentOS 6.4位
包含如下腳本在內的絕大部分命令和腳本,都是我親自運行過,靠譜的。
1.mysql
1.1 安裝mysql
yum install mysql-server
1.2 啓動mysql,服務名字是「mysqld」而不是「mysql」
service mysqld start
service mysqld stop
1.3 設置密碼。刪除匿名用戶,是否贊成遠程登陸。刪除test數據庫。又一次載入權限表以確保剛剛的設置生效
/usr/bin/mysql_secure_installation
1.4贊成root用戶遠程鏈接數據庫
mysql -uroot -p;
use mysql;
select host,user,password from user;
update user set host = '%' where user = 'root';
#假設root用戶已經有了"%",會提示如下的錯誤
" Duplicate entry '%-root' for key 'PRIMARY'"
grant all privileges on *.* to root@'%' identified by "root";
flush privileges;
--運行上面的命令時,不知道到怎麼把密碼給改了,root沒法登陸。
#1.5 MySQL 忘記口令的解決的方法
假設 MySQL 正在運行,首先殺之: killall -TERM mysqld。
啓動 MySQL :/usr/bin/mysqld_safe --skip-grant-tables &
就可以不需要密碼就進入 MySQL 了。
而後就是
>use mysql
>update user set password=password("lw198962") where user="root";
>flush privileges;
又一次殺 MySQL 。用正常方法啓動 MySQL 。
---------------------------
1.6 安裝mysql時,給的提示,頗有幫助
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
#設置密碼
/usr/bin/mysqladmin -u root password 'lw198962'
/usr/bin/mysqladmin -u root -h AY1304131823374920ac password 'lw198962'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
2.java
2.1下載解壓版JDK7,上傳到服務器,而後解壓
untar -xvf jdk7.tar.gz
unzip jdk7.zip
2.2配置環境變量
export JAVA_HOME=/home/fans/Fans/jdk1.6.0_31
export CLASSPATH=$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
2.3又一次載入
source /etc/profile
3.tomcat
3.1下載解壓版Tomcat7,上傳到服務器。而後解壓
參考 解壓jdk7
3.2 添加可運行權限
chmod a+x *.sh
提示:不要給.bat文件添加x權限
運行tomcat命令的時候。僅僅有x權限的文件,linux才幹本身主動提示,比方輸入 ./start 按Tab 系統本身主動提示到startup.sh,
假設startup.bat也有權限,需要更具體的輸入。
3.3 JDK環境變量
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
多是尚未配置環境變量,也多是配置了。尚未生效。
記得運行 source /etc/profile
3.4 啓動Tomcat失敗怎麼辦
./startup.sh這樣的啓動方式,錯誤提示不夠明顯。
經過 ps -ef|grep tomcat 查看Tomcat是否已經啓動。
假設沒有,經過 ./catalina.sh run 啓動Tomcat,這樣的方式可以看到完整的啓動信息。
這樣的啓動方式很差的地方是。退出當前會話,Tomcat就中止了。
4.Nginx
安裝過程
yum install nginx-release...
yum install nginx
配置Nginx:核心部分
server {
listen 80;
server_name fansunion.cn www.fansunion.cn;
#將www.fansunon.cn永久重定向到fansunion.cn,在創業作ITFriend站點的過程當中發現,帶www和不帶www的Cookie可能不是同一個
#不要www是爲了簡化輸入,讓url更短更easy輸入和記憶
if ($host != 'fansunion.cn'){
}
charset utf-8;
access_log off;
ssi on;
ssi_silent_errors on;
location / {
}
}
後臺Tomcat監聽8080端口,把經過域名「fansunion.cn」過來的所有請求(html、js。靜態和動態的)都轉發到Tomcat解析。
假設靜態資源比較多的狀況下,也可以讓Nginx處理js、css、image。僅僅讓Tomcat處理動態的請求。
5.參考資料
Linux環境運維等不少其它相關資料,請參考個人CSDN博客
小雷FansUnion-博學的互聯網技術工做者
2014年11月1日
湖北武漢