主に自分用メモ。
■とりあえずアプデ
yum update
■作業用ユーザー追加/パスワード設定
useradd ユーザー名 passwd ユーザー名 ※pass設定しないとロックされたままでsshのpemログインできない nginxの公開ディレクトリ置く場合 chmod 705 /home/ユーザー名
■SSH設定
まず自分のマシン(mac)でキーペア作る
ssh-keygen -t rsa ssh-add id_rsa scp id_rsa.pub サーバー:/home/ユーザー名/.ssh/authorized_keys
サーバー側
chmod 700 ./ssh chmod 600 ./ssh/authorized_keys
これで自分のマシンから
ssh ユーザー@サーバー -i id_rsa
でログイン可能になる
セキュリティ向上のため、サーバー側でポート変更と、公開鍵のみ受け付けるようにする
vi /etc/ssh/sshd_config ※同じ場所にある ssh_config ではないので注意 Port 10022 Protocol 2 PermitRootLogin no PasswordAuthentication no PermitEmptyPasswords no ChallengeResponseAuthentication no RhostsRSAAuthentication no PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys AllowUsers sshを許可するユーザー名 SyslogFacility AUTHPRIV
■ポートの設定
現在の設定確認 firewall-cmd --list-service --zone=public sshのポートを10022に変更する vi /usr/lib/firewalld/services/ssh.xml dhcpv6-clientを削除 firewall-cmd --remove-service=dhcpv6-client --zone=public --permanent httpdなどを追加 firewall-cmd --add-service=http --zone=public --permanent 反映 firewall-cmd --reload
■ホスト名を変更
hostnamectl set-hostname ホスト名
■必要なソフトウェアの追加
LANG=C yum groups list yum groups install "Compatibility Libraries" yum groups install "Development Tools"
■自動起動設定
一覧 systemctl list-unit-files -t service 自動起動on systemctl enable ***.service 自動起動off systemctl disable ***.service 起動や停止、再起動など systemctl restart ***.service
■nginx
vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
yum install nginx vi /etc/nginx/nginx.conf vi /etc/nginx/conf.d/default.conf configtest的な nginx -t -c /etc/nginx/nginx.conf 起動 systemctl start nginx.service systemctl enable nginx.service
■ssl化
Let’s Encrtptを利用
cd /usr/local/ git clone https://github.com/certbot/certbot cd certbot/ ./certbot-auto
更新テスト
/usr/local/certbot/certbot-auto renew --force-renew --dry-run
cronで定期的に更新
crontab -e 00 05 01 * * /usr/local/certbot/certbot-auto renew --force-renew && /sbin/service nginx restart
ssl_dhparamのためのpem生成
openssl dhparam 2048 -out dhparam.pem
■PHP
yum install epel-release yum localinstall http://rpms.famillecollet.com/enterprise/remi-release-7.rpm yum install --enablerepo=remi,remi-php70 \ php \ php-devel \ php-mysqli \ php-pdo \ php-openssl \ php-mbstring \ php-opcache \ php-fpm \ php-intl AWSのSDKなどで必要 php-xml Laravelとか入れるなら下記も php-pecl-zip
pear(pecl)
yum install libxslt yum install --enablerepo=remi,remi-php70 php-pear
php-fpm
vi /etc/php-fpm.d/www.conf user = nginx group = nginx ;listen = 127.0.0.1:9000 listen = /run/php-fpm/php7.sock listen.owner = nginx listen.group = nginx
systemctl start php-fpm.service systemctl enable php-fpm.service
■MySQL
yumのrepoをDL・localinstall
yum remove mariadb-libs wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm yum localinstall mysql57-community-release-el7-11.noarch.rpm yum install mysql-community-server 起動 systemctl start mysqld.service 初期パスワード表示 grep 'temporary password' /var/log/mysqld.log 初期パスワードでログイン後、パス変更 (デフォルトでは大文字、小文字、数字、記号が1つ以上、かつ8文字以上の必要がある) ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'; CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'password'; GRANT ALL ON *.* TO 'root'@'127.0.0.1';