Centos6.5サーバのインストール

11023 ワード

セキュアサブシステムを閉じる

sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0

wgetのインストール

yum -y install wget

デフォルトのミラーをアリミラーに変更

cd /etc/yum.repos.d && mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum makecache
yum clean all

zipのインストール

yum install -y unzip zip

vimのインストール

yum install -y vim

scpのインストール

yum -y install openssh-clients

依存関係のインストール

yum -y install gcc-c++ tcl gettext-devel pcre-devel openssl openssl-devel bison flexcurl-devel expat-devel zlib-devel autoconf automake libtool python ncurses-devellibjpeg-devel e2fsprogs-devel sqlite-devel libcurl-devel speex-devel ldns-devel libeditdevelreadline-devel ncurses-devel pam-develnumactl

screenセッションのインストール

yum -y install screen

ntpdate時間同期ツールのインストール

yum -y install ntpdate
echo '0 1 * * * ntpdate cn.pool.ntp.org;hwclock -w' >> /var/spool/cron/root

Javaのインストール

mkdir -p /opt/java
cd ~ && wget http://oss.hongyangliao.com/jdk-8u151-linux-x64.tar.gz
mv jdk-8u151-linux-x64.tar.gz /opt/java/
cd /opt/java
tar -xzvf jdk-8u151-linux-x64.tar.gz
rm -rf jdk-8u151-linux-x64.tar.gz
echo 'export JAVA_HOME=/opt/java/jdk1.8.0_151' >> /etc/profile
echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/rt.jar' >> /etc/profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
cd /usr/bin
ln -s -f /opt/java/jdk1.8.0_151/jre/bin/java
ln -s -f /opt/java/jdk1.8.0_151/bin/javac

Tomcatのインストール

cd ~ && wget http://oss.hongyangliao.com/apache-tomcat-8.5.24.tar.gz
mv apache-tomcat-8.5.24.tar.gz /usr/local/
cd /usr/local
tar -xzvf apache-tomcat-8.5.24.tar.gz
mv apache-tomcat-8.5.24 tomcat8
mv apache-tomcat-8.5.24.tar.gz /usr/local/src
echo 'export CATALINA_HOME=/usr/local/tomcat8' >> /etc/profile
source /etc/profile

Tomcatの自動起動の設定

cd /etc/init.d
touch tomcat8 && chmod 755 tomcat8 && vim tomcat8

次のコマンドを追加します.JAVA_に注意してください.HOME,CATALANA_HOME
#!/bin/bash    
#    
# tomcat startup script for the Tomcat server    
#    
# chkconfig: 345 80 20    
# description: start the tomcat deamon    
#    
# Source function library    
. /etc/rc.d/init.d/functions

prog=tomcat8
JAVA_HOME=/opt/java/jdk1.8.0_151
export JAVA_HOME    
CATALANA_HOME=/usr/local/tomcat8
export CATALINA_HOME    

case "$1" in
start)
    echo "Starting Tomcat..."    
    $CATALANA_HOME/bin/startup.sh
    ;;

stop)
    echo "Stopping Tomcat..."    
    $CATALANA_HOME/bin/shutdown.sh
    ;;

restart)
    echo "Stopping Tomcat..."    
    $CATALANA_HOME/bin/shutdown.sh
    sleep 2
    echo    
    echo "Starting Tomcat..."    
    $CATALANA_HOME/bin/startup.sh
    ;;

*)
    echo "Usage: $prog {start|stop|restart}"    
    ;;
esac
exit 0

次のコマンドを実行します.
chkconfig --add tomcat8
chkconfig --level 345 tomcat8

nginxのインストール


nginxをダウンロードしてインストール
cd && wget http://oss.hongyangliao.com/nginx-1.8.1.tar.gz
mv nginx-1.8.1.tar.gz /usr/local/src
cd /usr/local/src && tar -xzvf nginx-1.8.1.tar.gz
cd nginx-1.8.1 && ./configure --prefix=/usr/local/nginx
make && make install

nginx自己起動の設定
cd /etc/init.d
touch nginx
vim nginx

次の内容を追加
#!/bin/bash  
# nginx Startup script for the Nginx HTTP Server  
#  
# chkconfig: - 85 15  
# description: Nginx is a high-performance web and proxy server.  
# It has a lot of features, but it's not for everyone.  
# processname: nginx  
# pidfile: /usr/local/nginx/logs/nginx.pid  
# config: /usr/local/nginx/conf/nginx.conf  
nginxd=/usr/local/nginx/sbin/nginx  
nginx_config=/usr/local/nginx/conf/nginx.conf  
nginx_pid=/usr/local/nginx/nginx.pid  

RETVAL=0  
prog="nginx"

# Source function library.  
. /etc/rc.d/init.d/functions  

# Source networking configuration.  
. /etc/sysconfig/network  

# Check that networking is up.  
[ ${NETWORKING} = "no" ] && exit 0  

[ -x $nginxd ] || exit 0  


# Start nginx daemons functions.  
start() {  

if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1  
fi  

   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}  
   RETVAL=$?  
   echo  
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx  
   return $RETVAL  

}  


# Stop nginx daemons functions.  
stop() {  
        echo -n $"Stopping $prog: "
        killproc $nginxd  
        RETVAL=$?  
        echo  
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid  
}  


# reload nginx service functions.  
reload() {  

    echo -n $"Reloading $prog: "
 $nginxd -s reload  
    #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"
    RETVAL=$?  
    echo  

}  

# See how we were called.  
case "$1" in
start)  
        start  
        ;;  

stop)  
        stop  
        ;;  

reload)  
        reload  
        ;;  

restart)  
        stop  
        start  
        ;;  

status)  
        status $prog  
        RETVAL=$?  
        ;;  
*)  
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1  
esac  

exit $RETVAL

保存して、次に自己起動を設定します.
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 345 nginx on
service nginx start

Redisのインストール

cd && wget http://oss.hongyangliao.com/redis-4.0.6.tar.gz
tar -zxvf redis-4.0.6.tar.gz
cd redis-4.0.6 && make PREFIX=/usr/local/redis install
cd /usr/local/redis && mkdir conf
cp ~/redis-4.0.6/redis.conf /usr/local/redis/conf


バックエンド起動Redisの設定
vim /usr/local/redis/conf/redis.conf

daemonize yes以降のモードを起動
################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes


redisサービスの自己起動の設定
cd /etc/init.d && touch redis && chmod +x redis
vim redis

redisファイルに次の内容を追加します.redis_に注意してください.pidの値
cd /etc/init.d
touch redis
vim redis
#!/bin/bash
#
# chkconfig: - 85 15
# script_name:redisd
# description:redis daemon
# config: /usr/local/redis/conf/redisd.conf
# pidfile: /var/run/redis-server.pid
#
### BEGIN INIT INFO
# Provides: redis
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

#variables
redis_port='6379'
redis_pid='/var/run/redis_'$redis_port'.pid'
redis_server="/usr/local/redis/bin/redis-server"
redis_conf="/usr/local/redis/conf/redis.conf"
redis_cli="/usr/local/redis/bin/redis-cli"

#function
function _start() {
    if [ ! -e "$redis_pid" ];then
        "$redis_server" "$redis_conf"
        echo "redis service start.......OK"
        return 0
    else
        echo "redis service is running !"
        return 1
    fi
}

function _stop() {

    if [ -e "$redis_pid" ];then
         "$redis_cli"  shutdown
         echo "redis service stop.......OK"
         sleep 1
         return 0
    else
         echo "redis service is not running !"
         return 1

    fi
}

function _status() {

    if [ -e "$redis_pid" ];then
         echo "redis service is running !"
         return 0
    else
         echo "redis service is not running !"
         return 1
    fi

}


#main
case "$1" in

        start)
               _start
                ;;
        stop)
               _stop
                ;;
        status)
               _status
               ;;
        *)
          echo  "Usage: $0 {start|stop|status}"
esac

に続く
chkconfig --add redis
chkconfig --level 345 redis on
service redis start

redisクライアントへのソフトリンクの設定
ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/redis-cli

mysqlのインストール

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum install mysql-server
/etc/init.d/mysqld start
mysql_secure_installation
mysql -uroot -p
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY 'admin' WITH GRANT OPTION;
FLUSH PRIVILEGES;

mysqlデータベースをUTF-8に符号化し、/etc/myを変更する.cnfまたは/etc/mysql/my.cnfファイル

[client]
default-character-set = utf8
[mysqld]
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci

mysqlサービスを再起動し、データベースのエンコードを表示

service mysqld restart
mysql -uroot -p
show variables like '%char%';

以下に符号化すればよい
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

Mavenのインストール

cd ~ && wget http://oss.hongyangliao.com/apache-maven-3.5.2-bin.tar.gz
mv apache-maven-3.5.2-bin.tar.gz /usr/local/
cd /usr/local && tar -xzvf apache-maven-3.5.2-bin.tar.gz
mv apache-maven-3.5.2 maven
echo 'M2_HOME=/usr/local/maven' >> /etc/profile
echo 'export PATH=$M2_HOME/bin:$PATH' >> /etc/profile
source /etc/profile
mvn help:system
cp /usr/local/maven/conf/settings.xml /root/.m2/
mv /usr/local/apache-maven-3.2.5-bin.tar.gz /usr/local/src/

インストールGit

yum -y install git

公開鍵の設定

ssh-keygen -t rsa