服务器安装教程.docx
《服务器安装教程.docx》由会员分享,可在线阅读,更多相关《服务器安装教程.docx(12页珍藏版)》请在冰豆网上搜索。
服务器安装教程
一、安装准备
解决yum命令无法使用问题
#vi/etc/resolv.conf
在此文件中最后加入nameserver8.8.8.8
1、关闭firewall:
systemctlstopfirewalld.service#停止firewall
systemctldisablefirewalld.service#禁止firewall开机启动
二、JDK
1.查看jdk的信息或直接执行
rpm-qa|grepjdk
2.卸载已有版本
yum-yremovejavajava-1.7.0-openjdk*
3.安装
cd/home/software
rpm-ivhjdk-7u67-linux-x64.rpm
4.环境变量
#vi/etc/profile
exportJAVA_HOME=/usr/java/jdk1.7.0_67
exportCLASSPATH=.:
$JAVA_HOME/jre/lib/rt.jar:
$JAVA_HOME/lib/dt.jar:
$JAVA_HOME/lib/tools.jar
exportPATH=$PATH:
$JAVA_HOME/bin
设置生效
#source/etc/profile
测试
#java-version
三、MySQL
1.安装cmake
wgethttp:
//www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
系统中已经安装了g++和ncurses-devel,如果没有安装使用下面的命令安装:
[root@admin/]#yuminstallgcc-c++
[root@admin/]#yuminstallncurses-devel
#yuminstall'perl(Data:
:
Dumper)'
2.安装mysql
#groupaddmysql
#useradd-r-gmysqlmysql
#cd/home/software
#cpmysql-5.6.20-linux-glibc2.5-x86_64.tar.gz/usr/local/
#cd/usr/local
#tar-zxvf mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz
shell>ln-smysql-5.6.20-linux-glibc2.5-x86_64mysql
shell>cdmysql
shell>chown-Rmysql.
shell>chgrp-Rmysql.
创建目录/home/data/mysql/data
shell>scripts/mysql_install_db--user=mysql--datadir=/home/data/mysql/data
shell>chown-Rroot.
shell>chown-Rmysqldata
#cd/usr/local/mysql/support-files/
#cpmysql.server/etc/rc.d/init.d/mysql
#cpmy-f/etc/f
#cp:
overwrite`/etc/f'?
y
[root@mysql5support-files]#chkconfig--addmysql
[root@mysql5support-files]#chkconfigmysqlon
#vi/etc/f
数据文件路径,缓存优化,字符集
[mysql]
default-character-set=utf8mb4
[mysqld]
#Thedefaultcharactersetthatwillbeusedwhenanewschemaortableis
#createdandnocharactersetisdefined
character-set-server=utf8mb4
innodb_buffer_pool_size=8G
datadir=/home/data/mysql/data
#ln-s/usr/local/mysql/bin/mysql/usr/bin
[root@mysql5support-files]#servicemysqlstart
#mysql–uroot–p
mysql>usemysql;
mysql>updateusersetpassword=password('Li721Zhong')whereuser='root';
mysql>FLUSHPRIVILEGES;
四、Nginx
./configure--prefix=/usr/local/nginx
make
makeinstall
安装gcc-c++
#yuminstall-ygcc-c++
安装purge
#wget
#tarzxvfngx_cache_purge-2.1.tar.gz
./configure
make&&makeinstall
安装zlib
tar-xvf
安装openssl-fips
tar-xvf
安装nginx
wgethttp:
//nginx.org/download/nginx-1.9.9.tar.gz
tarzxvfnginx-1.9.9.tar.gz
cdnginx-1.9.9
./configure--with-pcre=../pcre-8.38
location~.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)${
root/home/web/apache-tomcat-7.0.55/webapps/pss;
expires30d;
}
五、Tomcat
tar-zxvfapache-tomcat-7.0.55.tar.gz -C/home/web
Tomcat自动启动
#vi/etc/init.d/tomcat
#!
/bin/sh
#chkconfig:
3459910
#description:
Auto-startstomcat
#/etc/init.d/tomcatd
#Tomcatauto-start
#Sourcefunctionlibrary.
#./etc/init.d/functions
#sourcenetworkingconfiguration.
#./etc/sysconfig/network
RETVAL=0
exportJDK_HOME=/usr/java/jdk1.7.0_67
exportJAVA_HOME=/usr/java/jdk1.7.0_67
exportCLASSPATH=.:
$JAVA_HOME/lib/dt.jar:
$JAVA_HOME/lib/tools.jar:
$CLASSPATH
exportCATALINA_HOME=/home/web/apache-tomcat-7.0.55
exportCATALINA_BASE=/home/web/apache-tomcat-7.0.55
start()
{
if[-f$CATALINA_HOME/bin/startup.sh];
then
echo$"StartingTomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo"OK"
return$RETVAL
fi
}
stop()
{
if[-f$CATALINA_HOME/bin/shutdown.sh];
then
echo$"StoppingTomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep1
ps-ef|grepapache-tomcat|grep-vgrep|awk'{print$2}'|xargskill-9
echo"OK"
#[$RETVAL-eq0]&&rm-f/var/lock/...
return$RETVAL
fi
}
case"$1"in
start)
start
;;
stop)
stop
;;
restart)
echo$"RestaringTomcat"
$0stop
sleep1
$0start
;;
*)
echo$"Usage:
$0{start|stop|restart}"
exit1
;;
esac
exit$RETVAL
chmod+x/etc/init.d/tomcat
ln-s/etc/init.d/tomcat /etc/rc2.d/S65tomcat
chkconfig--addtomcat
chkconfigtomcaton
chmoda+x*.sh
安装APR
yum-yinstallgcc
cd/usr/local/src
tar-xzvfapr-1.5.2.tar.gz
cdapr-1.5.2
./configure
make
make install
cd/usr/local/src
tar-xzvfapr-util-1.5.4.tar.gz
cdapr-util-1.5.4
./configure--with-apr=/usr/local/apr
make
make install
cd/usr/local/src
tar-xzvftomcat-native.tar.gz
cdtomcat-native-1.1.31-src/jni/native
./configure--with-apr=/usr/local/apr--with-java-home=/usr/java/jdk1.7.0_67
make
make install
vi /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:
/usr/local/apr/lib
source /etc/profile
请关闭SSL侦听,除非你有使用SSL
六、数据库备份与还原
rpm-ivhlibev-4.15-1.el6.rf.x86_64.rpm
yum-yinstallperlperl-devellibaiolibaio-develperl-Time-HiResperl-DBD-MySQL
rpm-ivhpercona-xtrabackup
#完整备份
innobackupex--defaults-file=/etc/f--database=bessky_pss/home/backup/--user=root--password=Li721Zhong
tarzcvf文件名.tar.gz目标名
#完整还原
#mv/var/lib/mysql/var/lib/mysql_bak
servicemysqlstop
rm-rf/home/data/mysql/data
innobackupex--defaults-file=/etc/f--user=root--apply-log/home/backup/2015-12-03_00-33-10
innobackupex--defaults-file=/etc/f--user=root--copy-back/home/backup/2015-12-03_00-33-10
chown-Rmysql.mysql/home/data/mysql/data
chownmysql:
mysql/home/data/mysql/data/ib*
cd/usr/local/mysql
scripts/mysql_install_db--user=mysql--datadir=/home/data/mysql/data
其中,--user指定连接数据库的用户名,--password指定连接数据库的密码,--defaults-file指定数据库的配置文件,innobackupex要从其中获取datadir等信息;--database指定要备份的数据库,这里指定的数据库只对MyISAM表和InnoDB表的表结构有效,对于InnoDB数据来说都是全备(所有数据库中的InnoDB数据都进行了备份,不是只备份指定的数据库,恢复时也一样);/mysqlbackup是备份文件的存放位置。
七、其他命令
查看服务端口
netstat-anp|grep mysql
查看ip
Ifconfig
关闭防火墙
systemctlstopfirewalld.service
修改ip
#vi/etc/sysconfig/network-scripts/ifcfg-em1(eth0,第一块网卡,如果是第二块则为eth1)
按如下修改ip
DEVICE=eth0(如果是第二块刚为eth1)
BOOTPROTO=static
IPADDR=192.168.16.11(改成要设置的IP)
NETMASK=255.255.255.0(子网掩码)
GATEWAY=192.168.16.1
DNS1=61.235.70.98
DNS2=183.62.99.113
DNS3=202.96.128.86
ONBOO=yes
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="em1"
UUID="a972cfe5-7d14-4df9-98a9-e9f6b0013a04"
ONBOOT="yes"
IPADDR0="192.168.16.205"
PREFIX0="24"
GATEWAY0="192.168.16.1"
DNS1="192.168.16.1"
HWADDR="B8:
2A:
72:
D9:
F8:
F9"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
然后
#servicenetworkrestart
IP地址生效,重启系统后不变
如果是临时修改IP重启系统后恢复原始IP则用以下命令
#ifconfigem1192.168.16.202netmask255.255.255.0
修改DNS
#vi/etc/resolv.conf
nameserver202.96.128.86
nameserver8.8.8.8
vi/etc/hosts
178.236.5.114mws-
178.236.6.88mws-
178.236.4.102mws-
176.32.100.48
176.32.98.70
178.236.4.102mws.amazonservices.co.uk
176.32.100.48mws.amazonservices.ca
173.0.84.101api-
173.0.92.21api-
66.135.211.101
66.135.211.97
66.135.211.96
66.135.223.10.hk
修改映射
Vi/etc/hosts
修改时区
Tzselect
ASIS
TZ='Asia/Shanghai';exportTZ
ln-sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
写入bois
#hwclock-w
Vi/etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false
ARC=false
重启shutdown-rnow
复制文件