centos7配置笔记

时间:2024-06-03 22:05:56

原因:前两天服务器的硬盘出故障,报错:scsi 0:0:2:0: rejecting I/O to dead device,报这个错误的时候重启过一次,撑了一个月时间,现在直接导致整个文件系统崩溃。很明显是硬盘出问题了(一直在线用了4年多,而且I/O操作也非常频繁),原来有3块sas硬盘,其中两块500G的作了Raid1,另一块1T是备份并作了LVM,现在很难确定是哪一块有问题,估计寿命也都差不多了,打算直接都换掉算了。

准备:现在备了一块256G固态硬盘用于装centos和一块1T的sas硬盘用作存储数据,并让机房帮忙安装了最小版的centos7,内核: 3.10.0-229.el7.x86_64。

一、网络设置及服务

原来的网络有两块网卡,一个接外网,一个接内网,直接执行ifconfig竟然提示无此命令,原来centos7最小版默认就不用这个了,可以用ip addr 和 ip link代替。而且ifcfg的名字也改为emN这种形式了,直接编辑/etc/sysconfig/network-scripts/ifcfg-em2配置内网ip,配好后执行service network restart,然后ping一下看能否连通其它内网机器。

可以在/lib/systemd/system/目录下创建一些扩展名为.service的服务配置文件,如:nginx.service.

二、安全设置

三、磁盘设置

  • 利用LVM增加硬盘及扩容,参考:http://www.centoscn.com/CentOS/config/2015/0315/4891.html;另外,也可以借助系统存储管理器管理LVM卷,参考:http://os.51cto.com/art/201409/450584.htm。

四、支撑环境

  • 安装rabbitmq,参考:http://my.oschina.net/jackwanger/blog/207898, 但在使用过程中发现没办法直接通过yum install erlang安装erlang,所以还得通过源码装。如果configure时指定了prefix,安装后还得在/etc/profile export指定path。在安装rabbitmq时提示
    rabbitmq /bin/sh: zip: command not found
    

    表示少了zip

    yum install zip unzip
    
    cd rabbitmq-server-3.5.3
    make
    make install TARGET_DIR=/usr/local/rabbitmq SBIN_DIR=/usr/local/rabbitmq/sbin MAN_DIR=/usr/local/rabbitmq/man

    后台启动

    ./rabbitmq-server -detached
    

    rabbitmq安装后默认端口为5672,而且不需要特定的配置,如果想指定一些特殊配置,可以参考:http://www.rabbitmq.com/configure.html  

      

  • 安装cmake:

    wget http://www.cmake.org/files/v3.3/cmake-3.3.0-rc3.tar.gz
    tar zxf cmake-3.3.0-rc3.tar.gz
    cd cmake-3.3.0-rc3
    ./configure
    make
    make install

      

  • 安装mysql

    wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz
    tar zxf mysql-5.6.27.tar.gz
    groupadd mysql
    useradd -g mysql mysql -s /bin/false
    mkdir -p /data/mysql
    chown -R mysql:mysql /data/mysql
    mkdir -p /usr/local/mysql
    cd mysql-5.6.27
    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
    make
    make install
    cd /usr/local/mysql
    cp ./support-files/my-huge.cnf /etc/my.cnf
    vi /etc/my.cnf
    datadir = /data/mysql #添加MySQL数据库路径
    ./scripts/mysql_install_db --user=mysql
    cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    chkconfig mysqld on
    vi /etc/rc.d/init.d/mysqld
    basedir = /usr/local/mysql
    datadir = /data/mysql
    service mysqld start
    vi /etc/profile
    export PATH=$PATH:/usr/local/mysql/bin
    ln -s /usr/local/mysql/lib /usr/lib/mysql
    ln -s /usr/local/mysql/include/mysql /usr/include/mysql
    mysql_secure_installation

    如果mysql命令行登录时提示:段错误(Segmentation fault),则需要按下面步骤处理:http://www.cnblogs.com/jenqz/p/4892570.html

  • 安装pcre

    tar zxvf pcre-8.37.tar.gz
    cd pcre-8.37
    ./configure --prefix=/usr/local/pcre
    make
    make install

      

  • 安装openssl
    wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz
    

      

  • 安装nginx    
    1. yum安装参考:http://www.linuxidc.com/Linux/2014-09/106192.htm2.

    yum -y install zlib-devel
    

      

  • 源码安装:

    wget http://nginx.org/download/nginx-1.9.5.tar.gz
    tar zxf nginx-1.9.5.tar.gz
    groupadd www
    useradd -g www www -s /bin/false cd nginx-1.9.5
    ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/root/tools/pcre-8.36
    make
    make install

      

    3.设置为服务

    cat >> /usr/lib/systemd/system/nginx.service << NGINX_SERVICE
    > [Unit]
    > Description=The nginx HTTP and reverse proxy server
    > After=syslog.target network.target remote-fs.target nss-lookup.target
    >
    > [Service]
    > Type=forking
    > PIDFile=/run/nginx.pid
    > ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    > ExecReload=/bin/kill -s HUP $MAINPID
    > ExecStop=/bin/kill -s QUIT $MAINPID
    > PrivateTmp=true
    >
    > [Install]
    > WantedBy=multi-user.target
    > NGINX_SERVICE systemctl enable nginx
    systemctl start nginx.service
  • 安装php

  • 1.安装php相关支持库
  • yum -y install libxml2 libxml2-devel libcurl-devel freetype freetype-devel libjpeg* libpng libpng-devel gd openssl openssl-devel libmcrypt

      

  • 2.安装php
  • ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-iconv  --with-zlib  --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex  --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir
    make
    make install

     

  • 安装redis

    wget http://download.redis.io/releases/redis-3.0.2.tar.gz
    tar zxvf redis-3.0.2.tar.gz
    cd redis-3.0.2
    mkdir /usr/local/redis
    make PREFIX=/usr/local/redis install
  • 安装ttserver,同时装一下httpsqs

    wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.48.tar.gz
    tar zxf tokyocabinet-1.4.48.tar.gz
    cd tokyocabinet-1.4.48
    ./configure --prefix=/usr/local/tokyocabinet-1.4.48/
    make
    make install wget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
    tar zxf tokyotyrant-1.1.41.tar.gz
    cd tokyotyrant-1.1.41
    ./configure --prefix=/usr/local/tokyotyrant-1.1.41 --with-tc=/usr/local/tokyocabinet-1.4.48/ wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gz
    tar xzf httpsqs-1.7.tar.gz
    cd httpsqs-1.7
    vi Makefile #将tokyocabinet由1.4.47改为1.4.48
    make
    make install

    ttserver的php扩展

    wget http://pecl.php.net/get/tokyo_tyrant-0.7.0.tgz
    tar zxvf tokyo_tyrant-0.7.0.tgz
    cd tokyo_tyrant-0.7.0
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config --with-tokyo-tyrant=/usr/local/tokyotyrant-1.1.41 --with-tokyo-cabinet-dir=/usr/local/tokyocabinet-1.4.48
    make && make install
  • 安装sphinx

    wget http://www.sphinx-search.com/downloads/sphinx-for-chinese-2.2.1-dev-r4311.tar.gz
    tar zxf sphinx-for-chinese-2.2.1-dev-r4311.tar.gz
    cd sphinx-for-chinese-2.2.1-dev-r4311
    ./configure --prefix=/usr/local/sphinx --with-mysql
    make
    make install

    安装sphinx的php扩展

    cd sphinx-for-chinese-2.2.1-dev-r4311/api/libsphinxclient
    ./configure –prefix=/usr/local/sphinxclient
    make && make install wget http://pecl.php.net/get/sphinx-1.3.0.tgz
    tar zxf sphinx-1.3.0.tgz
    cd sphinx-1.3.0
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinxclient/
    make
    make install

        

      

五、应用环境