今天,从新弄个人我的云主机的环境,准备运营本身用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,这种方式能够看到完整的启动信息。
Windows环境,也是这样。
这种启动方式很差的地方是,退出当前会话,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更短更容易输入和记忆
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日
湖北武汉