今天,又一次弄个人我的云主机的环境。准备运营本身用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日
湖北武汉